new FilterBasedLdapUserSearch(searchBase,
searchFilter,
initialDirContextFactory);
userSearch.setSearchSubtree(true);
BindAuthenticator authenticator = new BindAuthenticator(initialDirContextFactory);
authenticator.setUserSearch(userSearch);
authenticator.setUserDnPatterns(new String [] { "uid={0},ou=users"} );
String groupSearchBase = "ou=groups";
DefaultLdapAuthoritiesPopulator authoritiesPopulator =
new DefaultLdapAuthoritiesPopulator(initialDirContextFactory,
groupSearchBase);
String groupRoleAttribute = "ou";
authoritiesPopulator.setGroupRoleAttribute(groupRoleAttribute);
System.out.println("***********************************");
LdapAuthenticationProvider ldapAuthenticationProvider =
new LdapAuthenticationProvider(authenticator, authoritiesPopulator);
LdapUserInfo user = authenticator.authenticate(userDetails.getUsername(),
(String)authentication.getCredentials());
if (user != null) {
UserDetails u = ldapAuthenticationProvider.retrieveUser(userDetails.getUsername(),
authentication);
System.out.println("user " + u);