List of usage examples for org.springframework.security.ldap.userdetails LdapUserDetailsService LdapUserDetailsService
public LdapUserDetailsService(LdapUserSearch userSearch, LdapAuthoritiesPopulator authoritiesPopulator)
From source file:net.oneandone.stool.overview.config.SecurityConfiguration.java
@Override public UserDetailsService userDetailsService() { FilterBasedLdapUserSearch userSearch; DefaultLdapAuthoritiesPopulator authoritiesPopulator; LdapUserDetailsService result;// w w w . ja v a2 s . co m userSearch = new FilterBasedLdapUserSearch("ou=cisostages", "(uid={0})", contextSource()); authoritiesPopulator = new DefaultLdapAuthoritiesPopulator(contextSource(), "ou=roles,ou=cisostages"); authoritiesPopulator.setGroupSearchFilter("(member=uid={1})"); authoritiesPopulator.setGroupRoleAttribute("ou"); authoritiesPopulator.setSearchSubtree(false); authoritiesPopulator.setIgnorePartialResultException(true); result = new LdapUserDetailsService(userSearch, authoritiesPopulator); result.setUserDetailsMapper(new InetOrgPersonContextMapper()); return result; }
From source file:org.pentaho.test.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListServiceTest.java
/** * Get the roles of user <code>suzy</code> by extracting the <code>cn</code> token from the <code>uniqueMember</code> * attribute of the object that matches base of <code>ou=users</code> and filter of <code>(uid={0})</code>. * //w ww .ja va2 s. c o m * <p> * Note that the UserDetailsService used by Spring Security is re-used here. * </p> * * @throws Exception */ @Test public void testGetAuthoritiesForUser1() throws Exception { LdapUserSearch userSearch = getUserSearch("ou=users", "(uid={0})"); //$NON-NLS-1$//$NON-NLS-2$ LdapUserDetailsService service = new LdapUserDetailsService(userSearch, new NoOpLdapAuthoritiesPopulator()); RolePreprocessingMapper mapper = new RolePreprocessingMapper(); mapper.setRoleAttributes(new String[] { "uniqueMember" }); //$NON-NLS-1$ mapper.setTokenName("cn"); //$NON-NLS-1$ service.setUserDetailsMapper(mapper); DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService(); userRoleListService.setUserDetailsService(service); List res = userRoleListService.getRolesForUser(null, "suzy"); //$NON-NLS-1$ assertTrue(res.contains("ROLE_A")); //$NON-NLS-1$ if (logger.isDebugEnabled()) { logger.debug("results of getAuthoritiesForUser1(): " + res); //$NON-NLS-1$ } }
From source file:org.pentaho.test.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListServiceTest.java
@Test public void testGetAuthoritiesForUser1ForTenant() throws Exception { ITenant defaultTenant = new Tenant("/pentaho/tenant0", true); login("suzy", defaultTenant); LdapUserSearch userSearch = getUserSearch("ou=users", "(uid={0})"); //$NON-NLS-1$//$NON-NLS-2$ LdapUserDetailsService service = new LdapUserDetailsService(userSearch, new NoOpLdapAuthoritiesPopulator()); RolePreprocessingMapper mapper = new RolePreprocessingMapper(); mapper.setRoleAttributes(new String[] { "uniqueMember" }); //$NON-NLS-1$ mapper.setTokenName("cn"); //$NON-NLS-1$ service.setUserDetailsMapper(mapper); DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService(); userRoleListService.setUserDetailsService(service); List res = userRoleListService.getRolesForUser(defaultTenant, "suzy"); //$NON-NLS-1$ assertTrue(res.contains("ROLE_A")); //$NON-NLS-1$ if (logger.isDebugEnabled()) { logger.debug("results of getAuthoritiesForUser1(): " + res); //$NON-NLS-1$ }/*from w w w . j a v a2 s.c o m*/ try { userRoleListService.getRolesForUser(new Tenant("/pentaho", true), "suzy"); } catch (UnsupportedOperationException uoe) { assertNotNull(uoe); } }
From source file:org.pentaho.test.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListServiceTest.java
/** * Get the roles of user <code>suzy</code> by returning the <code>cn</code> attribute of each object that matches base * of <code>ou=roles</code> and filter of <code>(roleOccupant={0})</code>. * /* www .ja v a2 s .co m*/ * <p> * Note that the UserDetailsService used by Spring Security is re-used here. * </p> */ @Test public void testGetAuthoritiesForUser2() { DefaultLdapAuthoritiesPopulator populator = new DefaultLdapAuthoritiesPopulator(getContextSource(), "ou=roles"); //$NON-NLS-1$ populator.setGroupRoleAttribute("cn"); //$NON-NLS-1$ populator.setGroupSearchFilter("(roleOccupant={0})"); //$NON-NLS-1$ LdapUserSearch userSearch = getUserSearch("ou=users", "(uid={0})"); //$NON-NLS-1$//$NON-NLS-2$ LdapUserDetailsService service = new LdapUserDetailsService(userSearch, populator); DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService(); userRoleListService.setUserDetailsService(service); List res = userRoleListService.getRolesForUser(null, "suzy"); //$NON-NLS-1$ assertTrue(res.contains("ROLE_IS")); //$NON-NLS-1$ if (logger.isDebugEnabled()) { logger.debug("results of getAuthoritiesForUser2(): " + res); //$NON-NLS-1$ } }
From source file:org.pentaho.test.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListServiceTest.java
/** * Same as above except sorted.//from ww w.j a va 2 s .co m */ @Test public void testGetAuthoritiesForUser2Sorted() { DefaultLdapAuthoritiesPopulator populator = new DefaultLdapAuthoritiesPopulator(getContextSource(), "ou=roles"); //$NON-NLS-1$ populator.setGroupRoleAttribute("cn"); //$NON-NLS-1$ populator.setGroupSearchFilter("(roleOccupant={0})"); //$NON-NLS-1$ LdapUserSearch userSearch = getUserSearch("ou=users", "(uid={0})"); //$NON-NLS-1$//$NON-NLS-2$ LdapUserDetailsService service = new LdapUserDetailsService(userSearch, populator); DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService(); userRoleListService.setUserDetailsService(service); userRoleListService.setRoleComparator(new DefaultRoleComparator()); List res = userRoleListService.getRolesForUser(null, "suzy"); //$NON-NLS-1$ assertTrue(res.contains("ROLE_POWER_USER")); //$NON-NLS-1$ if (logger.isDebugEnabled()) { logger.debug("results of getAuthoritiesForUser2Sorted(): " + res); //$NON-NLS-1$ } }