-1
I am trying to log on to the ad, but soon on the Admim user already error 502e. But user and password are correct, which may be wrong here
@PostMapping("loginJndi")
public logonModel authenticateJndi(@RequestBody logonModel modelAuth) throws Exception{
logonModel model = new logonModel();
try {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.put(Context.PROVIDER_URL, "ldap://10.xx.254.5:xxx");
props.put(Context.SECURITY_PRINCIPAL, "[email protected],dc=br,dc=empresa,dc=com");//adminuser - User with special priviledge, dn user
props.put(Context.SECURITY_CREDENTIALS, "Y,I,5g5l");//dn user password
InitialDirContext context = new InitialDirContext(props);
SearchControls ctrls = new SearchControls();
ctrls.setReturningAttributes(new String[] { "givenName", "sn","memberOf" });
ctrls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<javax.naming.directory.SearchResult> answers = context.search("[email protected]", "(uid=" + modelAuth.username + ")", ctrls);
javax.naming.directory.SearchResult result = answers.nextElement();
String user = result.getNameInNamespace();
try {
props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.put(Context.PROVIDER_URL, "ldap://10.xx.254.5:xxx");
props.put(Context.SECURITY_PRINCIPAL, user);
props.put(Context.SECURITY_CREDENTIALS, modelAuth.password);
context = new InitialDirContext(props);
model.status = true;
model.mensagem = context.toString();
} catch (Exception e) {
model.status = false;
model.mensagem = e.getMessage();
}
}catch (Exception e)
{
model.mensagem = e.getMessage();
}
return model;
}
Hello! Post error log if possible.
– leandro.dev