Search in sources :

Example 1 with IdentityProviderException

use of org.camunda.bpm.engine.impl.identity.IdentityProviderException in project camunda-bpm-platform by camunda.

the class LdapIdentityProviderSession method findUsersByGroupId.

protected List<User> findUsersByGroupId(LdapUserQueryImpl query) {
    String baseDn = getDnForGroup(query.getGroupId());
    // compose group search filter
    String groupSearchFilter = "(& " + ldapConfiguration.getGroupSearchFilter() + ")";
    NamingEnumeration<SearchResult> enumeration = null;
    try {
        enumeration = initialContext.search(baseDn, groupSearchFilter, ldapConfiguration.getSearchControls());
        List<String> groupMemberList = new ArrayList<String>();
        // first find group
        while (enumeration.hasMoreElements()) {
            SearchResult result = enumeration.nextElement();
            Attribute memberAttribute = result.getAttributes().get(ldapConfiguration.getGroupMemberAttribute());
            if (null != memberAttribute) {
                NamingEnumeration<?> allMembers = memberAttribute.getAll();
                // iterate group members
                while (allMembers.hasMoreElements()) {
                    groupMemberList.add((String) allMembers.nextElement());
                }
            }
        }
        List<User> userList = new ArrayList<User>();
        String userBaseDn = composeDn(ldapConfiguration.getUserSearchBase(), ldapConfiguration.getBaseDn());
        int memberCount = 0;
        for (String memberId : groupMemberList) {
            if (userList.size() < query.getMaxResults() && memberCount >= query.getFirstResult()) {
                if (ldapConfiguration.isUsePosixGroups()) {
                    query.userId(memberId);
                }
                List<User> users = ldapConfiguration.isUsePosixGroups() ? findUsersWithoutGroupId(query, userBaseDn, true) : findUsersWithoutGroupId(query, memberId, true);
                if (users.size() > 0) {
                    userList.add(users.get(0));
                }
            }
            memberCount++;
        }
        return userList;
    } catch (NamingException e) {
        throw new IdentityProviderException("Could not query for users", e);
    } finally {
        try {
            if (enumeration != null) {
                enumeration.close();
            }
        } catch (Exception e) {
        // ignore silently
        }
    }
}
Also used : User(org.camunda.bpm.engine.identity.User) Attribute(javax.naming.directory.Attribute) ArrayList(java.util.ArrayList) SearchResult(javax.naming.directory.SearchResult) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) IdentityProviderException(org.camunda.bpm.engine.impl.identity.IdentityProviderException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) NamingException(javax.naming.NamingException) IdentityProviderException(org.camunda.bpm.engine.impl.identity.IdentityProviderException)

Example 2 with IdentityProviderException

use of org.camunda.bpm.engine.impl.identity.IdentityProviderException in project camunda-bpm-platform by camunda.

the class LdapIdentityProviderSession method findGroupByQueryCriteria.

public List<Group> findGroupByQueryCriteria(LdapGroupQuery query) {
    ensureContextInitialized();
    String groupBaseDn = composeDn(ldapConfiguration.getGroupSearchBase(), ldapConfiguration.getBaseDn());
    if (ldapConfiguration.isSortControlSupported()) {
        applyRequestControls(query);
    }
    NamingEnumeration<SearchResult> enumeration = null;
    try {
        String filter = getGroupSearchFilter(query);
        enumeration = initialContext.search(groupBaseDn, filter, ldapConfiguration.getSearchControls());
        // perform client-side paging
        int resultCount = 0;
        List<Group> groupList = new ArrayList<Group>();
        while (enumeration.hasMoreElements() && groupList.size() < query.getMaxResults()) {
            SearchResult result = enumeration.nextElement();
            GroupEntity group = transformGroup(result);
            if (isAuthorized(READ, GROUP, group.getId())) {
                if (resultCount >= query.getFirstResult()) {
                    groupList.add(group);
                }
                resultCount++;
            }
        }
        return groupList;
    } catch (NamingException e) {
        throw new IdentityProviderException("Could not query for users", e);
    } finally {
        try {
            if (enumeration != null) {
                enumeration.close();
            }
        } catch (Exception e) {
        // ignore silently
        }
    }
}
Also used : Group(org.camunda.bpm.engine.identity.Group) GroupEntity(org.camunda.bpm.engine.impl.persistence.entity.GroupEntity) ArrayList(java.util.ArrayList) SearchResult(javax.naming.directory.SearchResult) NamingException(javax.naming.NamingException) IdentityProviderException(org.camunda.bpm.engine.impl.identity.IdentityProviderException) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) IdentityProviderException(org.camunda.bpm.engine.impl.identity.IdentityProviderException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException)

Example 3 with IdentityProviderException

use of org.camunda.bpm.engine.impl.identity.IdentityProviderException in project camunda-bpm-platform by camunda.

the class LdapIdentityProviderSession method findUsersWithoutGroupId.

public List<User> findUsersWithoutGroupId(LdapUserQueryImpl query, String userBaseDn, boolean ignorePagination) {
    if (ldapConfiguration.isSortControlSupported()) {
        applyRequestControls(query);
    }
    NamingEnumeration<SearchResult> enumeration = null;
    try {
        String filter = getUserSearchFilter(query);
        enumeration = initialContext.search(userBaseDn, filter, ldapConfiguration.getSearchControls());
        // perform client-side paging
        int resultCount = 0;
        List<User> userList = new ArrayList<User>();
        while (enumeration.hasMoreElements() && (userList.size() < query.getMaxResults() || ignorePagination)) {
            SearchResult result = enumeration.nextElement();
            UserEntity user = transformUser(result);
            if (isAuthenticatedUser(user) || isAuthorized(READ, USER, user.getId())) {
                if (resultCount >= query.getFirstResult() || ignorePagination) {
                    userList.add(user);
                }
                resultCount++;
            }
        }
        return userList;
    } catch (NamingException e) {
        throw new IdentityProviderException("Could not query for users", e);
    } finally {
        try {
            if (enumeration != null) {
                enumeration.close();
            }
        } catch (Exception e) {
        // ignore silently
        }
    }
}
Also used : User(org.camunda.bpm.engine.identity.User) ArrayList(java.util.ArrayList) SearchResult(javax.naming.directory.SearchResult) NamingException(javax.naming.NamingException) IdentityProviderException(org.camunda.bpm.engine.impl.identity.IdentityProviderException) UserEntity(org.camunda.bpm.engine.impl.persistence.entity.UserEntity) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) IdentityProviderException(org.camunda.bpm.engine.impl.identity.IdentityProviderException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException)

Example 4 with IdentityProviderException

use of org.camunda.bpm.engine.impl.identity.IdentityProviderException in project camunda-bpm-platform by camunda.

the class LdapIdentityProviderSession method openContext.

protected InitialLdapContext openContext(String userDn, String password) {
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, ldapConfiguration.getInitialContextFactory());
    env.put(Context.SECURITY_AUTHENTICATION, ldapConfiguration.getSecurityAuthentication());
    env.put(Context.PROVIDER_URL, ldapConfiguration.getServerUrl());
    env.put(Context.SECURITY_PRINCIPAL, userDn);
    env.put(Context.SECURITY_CREDENTIALS, password);
    // for anonymous login
    if (ldapConfiguration.isAllowAnonymousLogin() && password.isEmpty()) {
        env.put(Context.SECURITY_AUTHENTICATION, "none");
    }
    if (ldapConfiguration.isUseSsl()) {
        env.put(Context.SECURITY_PROTOCOL, "ssl");
    }
    // add additional properties
    Map<String, String> contextProperties = ldapConfiguration.getContextProperties();
    if (contextProperties != null) {
        env.putAll(contextProperties);
    }
    try {
        return new InitialLdapContext(env, null);
    } catch (AuthenticationException e) {
        throw new LdapAuthenticationException("Could not authenticate with LDAP server", e);
    } catch (NamingException e) {
        throw new IdentityProviderException("Could not connect to LDAP server", e);
    }
}
Also used : AuthenticationException(javax.naming.AuthenticationException) Hashtable(java.util.Hashtable) InitialLdapContext(javax.naming.ldap.InitialLdapContext) NamingException(javax.naming.NamingException) IdentityProviderException(org.camunda.bpm.engine.impl.identity.IdentityProviderException)

Example 5 with IdentityProviderException

use of org.camunda.bpm.engine.impl.identity.IdentityProviderException in project camunda-bpm-platform by camunda.

the class LdapIdentityProviderSession method applyRequestControls.

protected void applyRequestControls(AbstractQuery<?, ?> query) {
    try {
        List<Control> controls = new ArrayList<Control>();
        List<QueryOrderingProperty> orderBy = query.getOrderingProperties();
        if (orderBy != null) {
            for (QueryOrderingProperty orderingProperty : orderBy) {
                String propertyName = orderingProperty.getQueryProperty().getName();
                if (UserQueryProperty.USER_ID.getName().equals(propertyName)) {
                    controls.add(new SortControl(ldapConfiguration.getUserIdAttribute(), Control.CRITICAL));
                } else if (UserQueryProperty.EMAIL.getName().equals(propertyName)) {
                    controls.add(new SortControl(ldapConfiguration.getUserEmailAttribute(), Control.CRITICAL));
                } else if (UserQueryProperty.FIRST_NAME.getName().equals(propertyName)) {
                    controls.add(new SortControl(ldapConfiguration.getUserFirstnameAttribute(), Control.CRITICAL));
                } else if (UserQueryProperty.LAST_NAME.getName().equals(propertyName)) {
                    controls.add(new SortControl(ldapConfiguration.getUserLastnameAttribute(), Control.CRITICAL));
                }
            }
        }
        initialContext.setRequestControls(controls.toArray(new Control[0]));
    } catch (Exception e) {
        throw new IdentityProviderException("Exception while setting paging settings", e);
    }
}
Also used : SortControl(javax.naming.ldap.SortControl) Control(javax.naming.ldap.Control) SortControl(javax.naming.ldap.SortControl) ArrayList(java.util.ArrayList) QueryOrderingProperty(org.camunda.bpm.engine.impl.QueryOrderingProperty) IdentityProviderException(org.camunda.bpm.engine.impl.identity.IdentityProviderException) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) IdentityProviderException(org.camunda.bpm.engine.impl.identity.IdentityProviderException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException)

Aggregations

AuthenticationException (javax.naming.AuthenticationException)5 NamingException (javax.naming.NamingException)5 IdentityProviderException (org.camunda.bpm.engine.impl.identity.IdentityProviderException)5 ArrayList (java.util.ArrayList)4 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)4 SearchResult (javax.naming.directory.SearchResult)3 User (org.camunda.bpm.engine.identity.User)2 Hashtable (java.util.Hashtable)1 Attribute (javax.naming.directory.Attribute)1 Control (javax.naming.ldap.Control)1 InitialLdapContext (javax.naming.ldap.InitialLdapContext)1 SortControl (javax.naming.ldap.SortControl)1 Group (org.camunda.bpm.engine.identity.Group)1 QueryOrderingProperty (org.camunda.bpm.engine.impl.QueryOrderingProperty)1 GroupEntity (org.camunda.bpm.engine.impl.persistence.entity.GroupEntity)1 UserEntity (org.camunda.bpm.engine.impl.persistence.entity.UserEntity)1