Search in sources :

Example 1 with UserEntity

use of org.activiti.engine.impl.persistence.entity.UserEntity in project Activiti by Activiti.

the class LDAPUserManager method findUserByQueryCriteria.

@Override
public List<User> findUserByQueryCriteria(final UserQueryImpl query, final Page page) {
    if (query.getId() != null) {
        List<User> result = new ArrayList<User>();
        result.add(findUserById(query.getId()));
        return result;
    } else if (query.getFullNameLike() != null) {
        final String fullNameLike = query.getFullNameLike().replaceAll("%", "");
        LDAPTemplate ldapTemplate = new LDAPTemplate(ldapConfigurator);
        return ldapTemplate.execute(new LDAPCallBack<List<User>>() {

            public List<User> executeInContext(InitialDirContext initialDirContext) {
                List<User> result = new ArrayList<User>();
                try {
                    String searchExpression = ldapConfigurator.getLdapQueryBuilder().buildQueryByFullNameLike(ldapConfigurator, fullNameLike);
                    String baseDn = ldapConfigurator.getUserBaseDn() != null ? ldapConfigurator.getUserBaseDn() : ldapConfigurator.getBaseDn();
                    NamingEnumeration<?> namingEnum = initialDirContext.search(baseDn, searchExpression, createSearchControls());
                    while (namingEnum.hasMore()) {
                        SearchResult searchResult = (SearchResult) namingEnum.next();
                        UserEntity user = new UserEntity();
                        mapSearchResultToUser(searchResult, user);
                        result.add(user);
                    }
                    namingEnum.close();
                } catch (NamingException ne) {
                    logger.debug("Could not execute LDAP query: " + ne.getMessage(), ne);
                    return null;
                }
                return result;
            }
        });
    } else {
        throw new ActivitiIllegalArgumentException("Query is currently not supported by LDAPUserManager.");
    }
}
Also used : User(org.activiti.engine.identity.User) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ArrayList(java.util.ArrayList) SearchResult(javax.naming.directory.SearchResult) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) UserEntity(org.activiti.engine.impl.persistence.entity.UserEntity)

Aggregations

ArrayList (java.util.ArrayList)1 NamingException (javax.naming.NamingException)1 InitialDirContext (javax.naming.directory.InitialDirContext)1 SearchResult (javax.naming.directory.SearchResult)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 User (org.activiti.engine.identity.User)1 UserEntity (org.activiti.engine.impl.persistence.entity.UserEntity)1