Search in sources :

Example 1 with Filter

use of io.jans.orm.search.filter.Filter 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 2 with Filter

use of io.jans.orm.search.filter.Filter 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 3 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class UserService method getUsersWithPersistentJwts.

public List<User> getUsersWithPersistentJwts() {
    String baseDN = getPeopleBaseDn();
    Filter filter = Filter.createPresenceFilter("jansPersistentJWT");
    return persistenceEntryManager.findEntries(baseDN, User.class, filter);
}
Also used : Filter(io.jans.orm.search.filter.Filter)

Example 4 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class UserService method getUser.

public User getUser(String userId, String... returnAttributes) {
    final String escapedUserId = escapeLog(userId);
    log.debug("Getting user information from LDAP: userId = {}", escapedUserId);
    if (StringHelper.isEmpty(userId)) {
        return null;
    }
    String peopleBaseDn = getPeopleBaseDn();
    Filter userUidFilter;
    if (dataSourceTypeService.isSpanner(peopleBaseDn)) {
        userUidFilter = Filter.createEqualityFilter("uid", StringHelper.toLowerCase(userId));
    } else {
        userUidFilter = Filter.createEqualityFilter(Filter.createLowercaseFilter("uid"), StringHelper.toLowerCase(userId));
    }
    List<User> entries = persistenceEntryManager.findEntries(peopleBaseDn, User.class, userUidFilter, returnAttributes);
    log.debug("Found {} entries for user id = {}", entries.size(), escapedUserId);
    return entries.isEmpty() ? null : entries.get(0);
}
Also used : User(io.jans.as.common.model.common.User) Filter(io.jans.orm.search.filter.Filter)

Example 5 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class UserService method countFidoRegisteredDevices.

public long countFidoRegisteredDevices(String username, String domain) {
    String userInum = getUserInum(username);
    if (userInum == null) {
        return 0;
    }
    String baseDn = getBaseDnForFidoDevices(userInum);
    if (persistenceEntryManager.hasBranchesSupport(baseDn)) {
        if (!persistenceEntryManager.contains(baseDn, SimpleBranch.class)) {
            return 0;
        }
    }
    Filter resultFilter = Filter.createEqualityFilter("jansStatus", DeviceRegistrationStatus.ACTIVE.getValue());
    List<DeviceRegistration> fidoRegistrations = persistenceEntryManager.findEntries(baseDn, DeviceRegistration.class, resultFilter);
    if (StringUtils.isEmpty(domain)) {
        return fidoRegistrations.size();
    }
    return fidoRegistrations.parallelStream().filter(f -> StringHelper.equals(domain, networkService.getHost(f.getApplication()))).count();
}
Also used : SimpleBranch(io.jans.orm.model.base.SimpleBranch) LdapEntryManagerFactory(io.jans.orm.ldap.impl.LdapEntryManagerFactory) StringUtils(org.apache.commons.lang.StringUtils) Filter(io.jans.orm.search.filter.Filter) Fido2RegistrationEntry(io.jans.fido2.model.entry.Fido2RegistrationEntry) AppConfiguration(io.jans.as.model.configuration.AppConfiguration) DeviceRegistrationStatus(io.jans.as.model.fido.u2f.DeviceRegistrationStatus) Inject(javax.inject.Inject) List(java.util.List) AttributeConstants(io.jans.as.common.util.AttributeConstants) StaticConfiguration(io.jans.as.model.config.StaticConfiguration) DeviceRegistration(io.jans.as.server.model.fido.u2f.DeviceRegistration) ApplicationScoped(javax.enterprise.context.ApplicationScoped) CustomEntry(io.jans.orm.model.base.CustomEntry) StringHelper(io.jans.util.StringHelper) NetworkService(io.jans.service.net.NetworkService) SimpleBranch(io.jans.orm.model.base.SimpleBranch) Filter(io.jans.orm.search.filter.Filter) DeviceRegistration(io.jans.as.server.model.fido.u2f.DeviceRegistration)

Aggregations

Filter (io.jans.orm.search.filter.Filter)188 Test (org.testng.annotations.Test)50 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)32 ConvertedExpression (io.jans.orm.couchbase.model.ConvertedExpression)28 SearchException (io.jans.orm.exception.operation.SearchException)25 ConvertedExpression (io.jans.orm.sql.model.ConvertedExpression)24 MappingException (io.jans.orm.exception.MappingException)22 ArrayList (java.util.ArrayList)21 AuthenticationException (io.jans.orm.exception.AuthenticationException)20 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)19 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)18 Date (java.util.Date)14 List (java.util.List)14 SqlEntryManager (io.jans.orm.sql.impl.SqlEntryManager)11 SqlEntryManagerSample (io.jans.orm.sql.persistence.SqlEntryManagerSample)11 CustomAttribute (io.jans.orm.model.base.CustomAttribute)9 CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)9 DateTimeParseException (java.time.format.DateTimeParseException)9 SpannerEntryManager (io.jans.orm.cloud.spanner.impl.SpannerEntryManager)8 SpannerEntryManagerSample (io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample)8