Search in sources :

Example 1 with SimpleUser

use of org.xdi.oxauth.model.common.SimpleUser in project oxAuth by GluuFederation.

the class AuthenticationService method getUserByAttribute.

private User getUserByAttribute(LdapEntryManager ldapAuthEntryManager, String baseDn, String attributeName, String attributeValue) {
    log.debug("Getting user information from LDAP: attributeName = '{}', attributeValue = '{}'", attributeName, attributeValue);
    if (StringHelper.isEmpty(attributeValue)) {
        return null;
    }
    SimpleUser sampleUser = new SimpleUser();
    sampleUser.setDn(baseDn);
    List<CustomAttribute> customAttributes = new ArrayList<CustomAttribute>();
    customAttributes.add(new CustomAttribute(attributeName, attributeValue));
    sampleUser.setCustomAttributes(customAttributes);
    log.debug("Searching user by attributes: '{}', baseDn: '{}'", customAttributes, baseDn);
    List<User> entries = ldapAuthEntryManager.findEntries(sampleUser, 1);
    log.debug("Found '{}' entries", entries.size());
    if (entries.size() > 0) {
        SimpleUser foundUser = entries.get(0);
        return ldapAuthEntryManager.find(User.class, foundUser.getDn());
    } else {
        return null;
    }
}
Also used : SimpleUser(org.xdi.oxauth.model.common.SimpleUser) User(org.xdi.oxauth.model.common.User) SimpleUser(org.xdi.oxauth.model.common.SimpleUser) CustomAttribute(org.xdi.ldap.model.CustomAttribute)

Aggregations

CustomAttribute (org.xdi.ldap.model.CustomAttribute)1 SimpleUser (org.xdi.oxauth.model.common.SimpleUser)1 User (org.xdi.oxauth.model.common.User)1