protected String escapeIllegalChars(String entityId) { if (!escapeOn()) { return entityId; } return entityId.replace(",", "\\,"); }
@Override public boolean existsGroup(String groupId) { String context = getConfigProperty(ROLE_CTX); String filter = getConfigProperty(ROLE_FILTER); String attributeId = getConfigProperty(ROLE_ATTR_ID, DEFAULT_ROLE_ATTR_ID); return existsEntity(groupId, context, filter, attributeId); }
@Override public List<String> getGroupsForUser(String userId) { String roleContext = getConfigProperty(USER_ROLES_CTX, getConfigProperty(ROLE_CTX)); String roleFilter = getConfigProperty(USER_ROLES_FILTER); String roleAttributeId = getConfigProperty(ROLE_ATTR_ID, DEFAULT_ROLE_ATTR_ID); String userDn = userId; if (!isUserIdDn()) { String userContext = getConfigProperty(USER_CTX); String userFilter = getConfigProperty(USER_FILTER); SearchResult searchResult = ldapSearcher.search(userContext, userFilter, userId).getSingleSearchResult(); userDn = searchResult.getNameInNamespace(); } List<String> result = ldapSearcher.search(roleContext, roleFilter, userDn).getAttributeResults(roleAttributeId); return result.stream().map(r-> unescapeIllegalChars(r)).collect(Collectors.toList()); }
private UserGroupCallback createLdapUserGroupCallback(Configuration config) { switch (config) { case CUSTOM: return new LDAPUserGroupCallbackImpl(createUserGroupCallbackProperties()); case SYSTEM: System.setProperty("jbpm.usergroup.callback.properties", "/jbpm.usergroup.callback.properties"); case DEFAULT: return new LDAPUserGroupCallbackImpl(true); default: throw new IllegalArgumentException("unknown config type"); } }
private boolean isUserIdDn() { return Boolean.parseBoolean(getConfigProperty(IS_USER_ID_DN, DEFAULT_USER_ID_DN)); }
private boolean existsEntity(String entityId, String context, String filter, String attributeId) { entityId = escapeIllegalChars(entityId); String ldapEntityId = ldapSearcher.search(context, filter, entityId).getSingleAttributeResult(attributeId); return entityId.equals(ldapEntityId); }
public static UserGroupCallback getUserGroupCallback() { UserGroupCallback callback = new MvelUserGroupCallbackImpl(true); if ("ldap".equalsIgnoreCase(USER_CALLBACK_IMPL)) { callback = new LDAPUserGroupCallbackImpl(true); } else if ("db".equalsIgnoreCase(USER_CALLBACK_IMPL)) { callback = new DBUserGroupCallbackImpl(true); } else if ("mvel".equalsIgnoreCase(USER_CALLBACK_IMPL)) { callback = new MvelUserGroupCallbackImpl(true); } else if ("props".equalsIgnoreCase(USER_CALLBACK_IMPL)) { callback = new JBossUserGroupCallbackImpl(true); } else if ("jaas".equalsIgnoreCase(USER_CALLBACK_IMPL)) { callback = new JAASUserGroupCallbackImpl(true); } else if ("custom".equalsIgnoreCase(USER_CALLBACK_IMPL)) { try { callback = (UserGroupCallback) Class.forName(CUSTOM_USER_CALLBACK_IMPL).newInstance(); } catch (Exception e) { throw new RuntimeException("Unable to create instance of custom user group callback impl", e); } } return callback; }
private boolean escapeOn() { return Boolean.parseBoolean(getConfigProperty(LDAP_NAME_ESCAPE, "true")); }
private UserGroupCallback createLdapUserGroupCallbackWithUserCtx(SearchScope searchScope, String userCtx) { Properties properties = createUserGroupCallbackProperties(searchScope); properties.setProperty(LDAPUserGroupCallbackImpl.USER_CTX, userCtx); return new LDAPUserGroupCallbackImpl(properties); }
@Override public boolean existsUser(String userId) { String context = getConfigProperty(USER_CTX); String filter = getConfigProperty(USER_FILTER); String attributeId = getConfigProperty(USER_ATTR_ID, DEFAULT_USER_ATTR_ID); return existsEntity(userId, context, filter, attributeId); }
protected String unescapeIllegalChars(String entityId) { if (!escapeOn()) { return entityId; } return entityId.replace("\\,", ","); }
private UserGroupCallback createLdapUserGroupCallbackWithRoleCtx(SearchScope searchScope, String roleCtx) { Properties properties = createUserGroupCallbackProperties(searchScope); properties.setProperty(LDAPUserGroupCallbackImpl.ROLE_CTX, roleCtx); return new LDAPUserGroupCallbackImpl(properties); }
@Test(expected = IllegalArgumentException.class) public void testCreateCallbackFromNullProperties() { UserGroupCallback ldapUserGroupCallback = new LDAPUserGroupCallbackImpl(null); }
@Test(expected = IllegalArgumentException.class) public void testCreateCallbackWithoutRequiredProperties() { UserGroupCallback ldapUserGroupCallback = new LDAPUserGroupCallbackImpl(new Properties()); }
@Test public void testInvalidScope() { Properties properties = createUserGroupCallbackProperties(); properties.setProperty(LDAPUserGroupCallbackImpl.SEARCH_SCOPE, "abc"); UserGroupCallback ldapUserGroupCallback = new LDAPUserGroupCallbackImpl(properties); assertUsers(ldapUserGroupCallback, true, true, false, false); assertGroups(ldapUserGroupCallback, true, true, false, false); }
@Test public void testDefaultScope() { Properties properties = createUserGroupCallbackProperties(); UserGroupCallback ldapUserGroupCallback = new LDAPUserGroupCallbackImpl(properties); assertUsers(ldapUserGroupCallback, true, true, false, false); assertGroups(ldapUserGroupCallback, true, true, false, false); }
public static UserGroupCallback getUserGroupCallback() { UserGroupCallback callback = new MvelUserGroupCallbackImpl(true); if ("ldap".equalsIgnoreCase(USER_CALLBACK_IMPL)) { callback = new LDAPUserGroupCallbackImpl(true); } else if ("db".equalsIgnoreCase(USER_CALLBACK_IMPL)) { callback = new DBUserGroupCallbackImpl(true); } else if ("mvel".equalsIgnoreCase(USER_CALLBACK_IMPL)) { callback = new MvelUserGroupCallbackImpl(true); } else if ("props".equalsIgnoreCase(USER_CALLBACK_IMPL)) { callback = new JBossUserGroupCallbackImpl(true); } else if ("jaas".equalsIgnoreCase(USER_CALLBACK_IMPL)) { callback = new JAASUserGroupCallbackImpl(true); } else if ("custom".equalsIgnoreCase(USER_CALLBACK_IMPL)) { try { callback = (UserGroupCallback) Class.forName(CUSTOM_USER_CALLBACK_IMPL).newInstance(); } catch (Exception e) { throw new RuntimeException("Unable to create instance of custom user group callback impl", e); } } return callback; }