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
}
}
}
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
}
}
}
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
}
}
}
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);
}
}
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);
}
}
Aggregations