LDAP authentication using scala or java -


i've created ldap server on machine , created 1 user admin inside ldap server , can access url http://192.158.2.136/phpldapadmin, i've login page in application , want when enters username , password want application validate user ldap server i.e should check whatever username , password entered same exists in ldap server or not.so far tried apacheds-all couldn't find proper way send username , password server, can please tell me how in java or scala, should able validate user credentials ldap server using java or scala client code.thanks in advance!!

i got solution :

object ldapvalidations {   def validateforldap(username: string, passcode: string): boolean = {  val result = try {   var props = new properties   props.put(context.initial_context_factory, "com.sun.jndi.ldap.ldapctxfactory")   props.put(context.provider_url, "ldap://192.168.1.121:389")   props.put(context.security_principal, s"cn=$username,cn=staff,dc=myreutore,dc=local")   props.put(context.security_credentials, "administrator")    var context: initialdircontext = new initialdircontext(props)    val controls: searchcontrols = new searchcontrols   controls.setreturningattributes(array[string]("givenname", "sn", "memberof", "cn"))   controls.setsearchscope(searchcontrols.subtree_scope)    val answers: namingenumeration[searchresult] = context.search("dc=myrtor,dc=local", s"cn=$username", controls)   val result: searchresult = answers.nextelement    val user: string = result.getnameinnamespace   props = new properties   props.put(context.initial_context_factory, "com.sun.jndi.ldap.ldapctxfactory")   props.put(context.provider_url, "ldap://192.168.1.121:389")   props.put(context.security_principal, user)   props.put(context.security_credentials, passcode)   context = new initialdircontext(props) } result match {   case success(v) => true   case failure(v) => false } 

}

}


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo