String sBaseDN = userProps.getUserSearchDIT();
String sFilter = userProps.returnUserLoginSearchFilter(unCredential.getUsername());
StringSet ssDNs = getQueryFunctions().searchDNs(
getConnectedContext(),sBaseDN,sFilter);
if (ssDNs.size() > 1) {
throw new IdentityException("Multiple LDAP usernames matched for:"+ unCredential.getUsername());
} else if (ssDNs.size() == 1) {
sAuthenticatedDN = ssDNs.iterator().next();
}
}
}
// Attempt to connect with the supplied credentials.
// An AuthenticationException will be thrown if the credentials are invalid
if (bUseDirectConnect) {
connectionClient = new LdapClient(getConfiguration(),upCredentials);
sAuthenticatedDN = connectionClient.connect();
bUseLoginPattern = false;
connectionClient.close();
connectionClient = null;
}
// Attempt to authenticate by first executing a search for all users
// matching the input username, then checking the supplied password against
// each matching DN.
// An AuthenticationException will be thrown if the credentials are invalid.
if (bUseLoginPattern) {
sAuthenticatedDN = searchForUser(upCredentials);
sTargetedGroupDN = upCredentials.getTargetedGroupDN();
}
// ensure an authenticated DN
if (sAuthenticatedDN.length() == 0) {
throw new AuthenticationException("Invalid credentials.");
}
// populate the authentication status and profile information
user.setDistinguishedName(sAuthenticatedDN);
populateUser(requestContext,user,sTargetedGroupDN);
RoleSet roles = user.getAuthenticationStatus().getAuthenticatedRoles();
if (roles.hasRole("gptForbiddenAccess")) {
User activeUser = requestContext.getUser();
if(activeUser.getAuthenticationStatus().getWasAuthenticated()){
String activeUserDn = requestContext.getUser().getDistinguishedName();
String managedUserDn = user.getDistinguishedName();
if(activeUserDn.equals(managedUserDn)){
throw new AuthenticationException("Forbidden");
}
}else{
throw new AuthenticationException("Forbidden");
}
}
} catch (AuthenticationException e) {
user.getAuthenticationStatus().reset();
throw new CredentialsDeniedException("Invalid credentials.");
} catch (com.esri.gpt.framework.context.ConfigurationException e) {
user.getAuthenticationStatus().reset();
throw new IdentityException(e.getMessage(),e);
} catch (NamingException e) {
user.getAuthenticationStatus().reset();
throw new IdentityException(e.getMessage(),e);
} catch (SQLException e) {
user.getAuthenticationStatus().reset();
throw e;
} catch (IdentityException e) {
user.getAuthenticationStatus().reset();