@Override public GeoServerUserGroupService createUserGroupService(SecurityNamedServiceConfig config) throws IOException { return new LDAPUserGroupService(config); } }
@Override public SortedSet<GeoServerUser> getUsersHavingProperty(String propname) { final SortedSet<GeoServerUser> users = new TreeSet<GeoServerUser>(); authenticateIfNeeded( new AuthenticatedLdapEntryContextCallback() { @Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { LDAPUtils.getLdapTemplateInContext(ctx, template) .search(userSearchBase, propname + "=*", addToUsers(users)); } }); return users; }
protected ContextMapper addToUsers(SortedSet<GeoServerUser> users) { return ctx -> { users.add(createUser((DirContextAdapter) ctx)); return null; }; }
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { GeoServerUser user = null; try { user = getUserByUsername(username); if (user == null) { throw new UsernameNotFoundException(userNotFoundMessage(username)); } RoleCalculator calculator = new RoleCalculator(this, getSecurityManager().getActiveRoleService()); user.setAuthorities(calculator.calculateRoles(user)); } catch (IOException e) { throw new UsernameNotFoundException(userNotFoundMessage(username), e); } return user; }
@Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { try { DirContextOperations roleObj = LDAPUtils.getLdapTemplateInContext(ctx, template) .searchForSingleEntry( groupSearchBase, groupNameFilter, new String[] {group.getGroupname()}); if (roleObj != null) { Object[] usernames = roleObj.getObjectAttributes(groupMembershipAttribute); if (usernames != null) { for (Object username : usernames) { String user = username.toString(); Matcher m = userMembershipPattern.matcher(user); if (m.matches()) { user = m.group(1); } users.add( getUserByUsername(getUserNameFromMembership(user))); } } } } catch (IncorrectResultSizeDataAccessException e) { } } });
@Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { LDAPUtils.getLdapTemplateInContext(ctx, template) .search( userSearchBase, "(&(!(" + propname + "=*))(" + allUsersSearchFilter + "))", counter(size)); } });
@Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { LDAPUtils.getLdapTemplateInContext(ctx, template) .search(userSearchBase, propname + "=*", addToUsers(users)); } });
protected String userNotFoundMessage(String username) { return "User " + username + " not found in usergroupservice: " + getName(); }
public LDAPUserGroupService(SecurityNamedServiceConfig config) throws IOException { initializeFromConfig(config); }
@Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { LDAPUtils.getLdapTemplateInContext(ctx, template) .search(groupSearchBase, allGroupsSearchFilter, counter(size)); } });
@Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { LDAPUtils.getLdapTemplateInContext(ctx, template) .search( userSearchBase, "(&(!(" + propname + "=*))(" + allUsersSearchFilter + "))", addToUsers(users)); } });
@Override public SortedSet<GeoServerUser> getUsersNotHavingProperty(String propname) { final SortedSet<GeoServerUser> users = new TreeSet<GeoServerUser>(); authenticateIfNeeded( new AuthenticatedLdapEntryContextCallback() { @Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { LDAPUtils.getLdapTemplateInContext(ctx, template) .search( userSearchBase, "(&(!(" + propname + "=*))(" + allUsersSearchFilter + "))", addToUsers(users)); } }); return users; }
@Before public void createUserGroupService() throws Exception { config.setGroupNameAttribute("cn"); config.setUserSearchBase("ou=People"); config.setUserNameAttribute("uid"); config.setGroupSearchFilter("member={1},dc=example,dc=com"); ((LDAPUserGroupServiceConfig) config) .setPopulatedAttributes("sn, givenName, telephoneNumber, mail"); service = new LDAPUserGroupService(config); Assume.assumeTrue( LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath, "data4.ldif")); }
@Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { LDAPUtils.getLdapTemplateInContext(ctx, template) .search(userSearchBase, propname + "=" + propvalue, counter(size)); } });
@Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { LDAPUtils.getLdapTemplateInContext(ctx, template) .search( userSearchBase, propname + "=" + propvalue, addToUsers(users)); } });
@Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { try { DirContextOperations dco = LDAPUtils.getLdapTemplateInContext(ctx, template) .searchForSingleEntry( userSearchBase, userNameFilter, new String[] {username}); if (dco != null) { user.set(createUser(dco)); } } catch (IncorrectResultSizeDataAccessException e) { } } });
@Override public int getGroupCount() { AtomicInteger size = new AtomicInteger(0); authenticateIfNeeded( new AuthenticatedLdapEntryContextCallback() { @Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { LDAPUtils.getLdapTemplateInContext(ctx, template) .search(groupSearchBase, allGroupsSearchFilter, counter(size)); } }); return size.get(); }
@Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { LDAPUtils.getLdapTemplateInContext(ctx, template) .search(userSearchBase, propname + "=*", counter(size)); } });
@Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { LDAPUtils.getLdapTemplateInContext(ctx, template) .search(userSearchBase, allUsersSearchFilter, addToUsers(users)); } });
@Override public SortedSet<GeoServerUser> getUsersHavingPropertyValue(String propname, String propvalue) throws IOException { final SortedSet<GeoServerUser> users = new TreeSet<GeoServerUser>(); authenticateIfNeeded( new AuthenticatedLdapEntryContextCallback() { @Override public void executeWithContext( DirContext ctx, LdapEntryIdentification ldapEntryIdentification) { LDAPUtils.getLdapTemplateInContext(ctx, template) .search( userSearchBase, propname + "=" + propvalue, addToUsers(users)); } }); return users; }