Search in sources :

Example 1 with SimpleUser

use of io.jans.as.common.model.common.SimpleUser in project jans by JanssenProject.

the class AuthenticationService method getUserByAttribute.

private User getUserByAttribute(PersistenceEntryManager 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<CustomObjectAttribute> customAttributes = new ArrayList<CustomObjectAttribute>();
    customAttributes.add(new CustomObjectAttribute(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 : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) SimpleUser(io.jans.as.common.model.common.SimpleUser) SimpleUser(io.jans.as.common.model.common.SimpleUser) User(io.jans.as.common.model.common.User) ArrayList(java.util.ArrayList)

Aggregations

SimpleUser (io.jans.as.common.model.common.SimpleUser)1 User (io.jans.as.common.model.common.User)1 CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)1 ArrayList (java.util.ArrayList)1