Search in sources :

Example 1 with User

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

the class UserService method addUserAttributeByUserInum.

public User addUserAttributeByUserInum(String userInum, String attributeName, Object attributeValue) {
    log.debug("Add user attribute by user inum  to LDAP: attributeName = '{}', attributeValue = '{}'", attributeName, attributeValue);
    User user = getUserByInum(userInum);
    if (user == null) {
        return null;
    }
    boolean result = addUserAttribute(user, attributeName, attributeValue);
    if (!result) {
        // We uses this result in Person Authentication Scripts
        addUserAttribute(user, attributeName, attributeValue);
    }
    return updateUser(user);
}
Also used : User(io.jans.as.common.model.common.User)

Example 2 with User

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

the class UserService method getUserByAttributes.

public User getUserByAttributes(Object attributeValue, String[] attributeNames, Boolean multiValued, String... returnAttributes) {
    if (ArrayHelper.isEmpty(attributeNames)) {
        return null;
    }
    if (log.isDebugEnabled())
        log.debug("Getting user information from DB: {} = {}", ArrayHelper.toString(attributeNames), attributeValue);
    String peopleBaseDn = getPeopleBaseDn();
    List<Filter> filters = new ArrayList<>();
    for (String attributeName : attributeNames) {
        Filter filter;
        if (dataSourceTypeService.isSpanner(peopleBaseDn)) {
            filter = Filter.createEqualityFilter(attributeName, attributeValue);
        } else {
            filter = Filter.createEqualityFilter(Filter.createLowercaseFilter(attributeName), attributeValue);
        }
        if (multiValued != null) {
            filter.multiValued(multiValued);
        }
        filters.add(filter);
    }
    Filter searchFiler;
    if (filters.size() == 1) {
        searchFiler = filters.get(0);
    } else {
        searchFiler = Filter.createORFilter(filters);
    }
    List<User> entries = persistenceEntryManager.findEntries(getPeopleBaseDn(), User.class, searchFiler, returnAttributes, 1);
    if (log.isDebugEnabled())
        log.debug("Found {} entries for user {} = {}", entries.size(), ArrayHelper.toString(attributeNames), attributeValue);
    return entries.isEmpty() ? null : entries.get(0);
}
Also used : User(io.jans.as.common.model.common.User) Filter(io.jans.orm.search.filter.Filter) ArrayList(java.util.ArrayList)

Example 3 with User

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

the class UserService method getUniqueUserByAttributes.

public User getUniqueUserByAttributes(List<String> attributeNames, String attributeValue) {
    log.debug("Getting user information from LDAP: attributeNames = '{}', attributeValue = '{}'", attributeNames, attributeValue);
    if (attributeNames != null) {
        for (String attributeName : attributeNames) {
            User searchUser = new User();
            searchUser.setDn(getPeopleBaseDn());
            List<CustomObjectAttribute> customAttributes = new ArrayList<>();
            customAttributes.add(new CustomObjectAttribute(attributeName, attributeValue));
            searchUser.setCustomAttributes(customAttributes);
            try {
                List<User> entries = persistenceEntryManager.findEntries(searchUser);
                log.debug(Constants.LOG_FOUND, entries.size());
                if (entries.size() == 1) {
                    return entries.get(0);
                } else if (entries.size() > 1) {
                    break;
                }
            } catch (Exception e) {
                log.debug(e.getMessage(), e);
            }
        }
    }
    return null;
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) User(io.jans.as.common.model.common.User) ArrayList(java.util.ArrayList)

Example 4 with User

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

the class UserService method getUsersByAttribute.

public List<User> getUsersByAttribute(String attributeName, Object attributeValue, Boolean multiValued, int limit) {
    if (log.isDebugEnabled())
        log.debug("Getting user information from LDAP: attributeName = '{}', attributeValue = '{}'", escapeLog(attributeName), escapeLog(attributeValue));
    if (StringHelper.isEmpty(attributeName) || (attributeValue == null)) {
        return Collections.emptyList();
    }
    Filter filter = Filter.createEqualityFilter(attributeName, attributeValue);
    if (multiValued != null) {
        filter.multiValued(multiValued);
    }
    List<User> entries = persistenceEntryManager.findEntries(getPeopleBaseDn(), User.class, filter, limit);
    log.debug("Found '{}' entries", entries.size());
    return entries;
}
Also used : User(io.jans.as.common.model.common.User) Filter(io.jans.orm.search.filter.Filter)

Example 5 with User

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

the class UserService method addUserAttribute.

public User addUserAttribute(String userId, String attributeName, Object attributeValue, Boolean multiValued) {
    log.debug("Add user attribute to LDAP: attributeName = '{}', attributeValue = '{}'", attributeName, attributeValue);
    User user = getUser(userId);
    if (user == null) {
        // We uses this result in Person Authentication Scripts
        return null;
    }
    boolean result = addUserAttribute(user, attributeName, attributeValue, multiValued);
    if (!result) {
        // We uses this result in Person Authentication Scripts
        return null;
    }
    return updateUser(user);
}
Also used : User(io.jans.as.common.model.common.User)

Aggregations

User (io.jans.as.common.model.common.User)95 Test (org.testng.annotations.Test)54 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)35 CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)12 Client (io.jans.as.common.model.registration.Client)11 Date (java.util.Date)11 SessionId (io.jans.as.server.model.common.SessionId)9 Scope (io.jans.as.persistence.model.Scope)8 ArrayList (java.util.ArrayList)8 SimpleUser (io.jans.as.common.model.common.SimpleUser)7 WebApplicationException (javax.ws.rs.WebApplicationException)6 OAuth2AuditLog (io.jans.as.server.model.audit.OAuth2AuditLog)5 Response (javax.ws.rs.core.Response)5 JsonWebResponse (io.jans.as.model.token.JsonWebResponse)4 AuthorizationGrant (io.jans.as.server.model.common.AuthorizationGrant)4 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 InvalidJwtException (io.jans.as.model.exception.InvalidJwtException)3 CibaRequestCacheControl (io.jans.as.server.model.common.CibaRequestCacheControl)3 CustomAttribute (io.jans.orm.model.base.CustomAttribute)3