Examples of loadUserByUsername()


Examples of org.springframework.security.core.userdetails.UserDetailsService.loadUserByUsername()

        UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
        UserDetails ben = uds.loadUserByUsername("ben");
        assertTrue(AuthorityUtils.authorityListToSet(ben.getAuthorities()).contains("PREFIX_DEVELOPERS"));

        uds = (UserDetailsService) appCtx.getBean("ldapUDSNoPrefix");
        ben = uds.loadUserByUsername("ben");
        assertTrue(AuthorityUtils.authorityListToSet(ben.getAuthorities()).contains("DEVELOPERS"));
    }


View Full Code Here

Examples of org.springframework.security.core.userdetails.UserDetailsService.loadUserByUsername()

    @Test
    public void differentGroupRoleAttributeWorksAsExpected() throws Exception {
        setContext("<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' group-role-attribute='ou' group-search-filter='member={0}' /><ldap-server ldif='classpath:test-server.ldif'/>");

        UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
        UserDetails ben = uds.loadUserByUsername("ben");

        Set<String> authorities = AuthorityUtils.authorityListToSet(ben.getAuthorities());
        assertEquals(3, authorities.size());
        assertTrue(authorities.contains("ROLE_DEVELOPER"));
View Full Code Here

Examples of org.springframework.security.core.userdetails.UserDetailsService.loadUserByUsername()

    public void personContextMapperIsSupported() {
        setContext(
                "<ldap-server ldif='classpath:test-server.ldif'/>" +
                "<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' user-details-class='person'/>");
        UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
        UserDetails ben = uds.loadUserByUsername("ben");
        assertTrue(ben instanceof Person);
    }

    @Test
    public void inetOrgContextMapperIsSupported() {
View Full Code Here

Examples of org.springframework.security.core.userdetails.UserDetailsService.loadUserByUsername()

    public void inetOrgContextMapperIsSupported() {
        setContext(
                "<ldap-server id='someServer' ldif='classpath:test-server.ldif'/>" +
                "<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' user-details-class='inetOrgPerson'/>");
        UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
        UserDetails ben = uds.loadUserByUsername("ben");
        assertTrue(ben instanceof InetOrgPerson);
    }

    @Test
    public void externalContextMapperIsSupported() {
View Full Code Here

Examples of org.springframework.security.core.userdetails.UserDetailsService.loadUserByUsername()

                "<ldap-server id='someServer' ldif='classpath:test-server.ldif'/>" +
                "<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' user-context-mapper-ref='mapper'/>" +
                "<b:bean id='mapper' class='"+ InetOrgPersonContextMapper.class.getName() +"'/>");

        UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
        UserDetails ben = uds.loadUserByUsername("ben");
        assertTrue(ben instanceof InetOrgPerson);
    }


    private void setContext(String context) {
View Full Code Here

Examples of org.springframework.security.core.userdetails.UserDetailsService.loadUserByUsername()

    @Test
    public void delegationToUserDetailsServiceReturnsCorrectRoles() throws Exception {
        UserDetailsService uds = mock(UserDetailsService.class);
        UserDetails user = mock(UserDetails.class);
        when(uds.loadUserByUsername("joe")).thenReturn(user);
        List authorities = AuthorityUtils.createAuthorityList("ROLE_USER");
        when(user.getAuthorities()).thenReturn(authorities);

        UserDetailsServiceLdapAuthoritiesPopulator populator = new UserDetailsServiceLdapAuthoritiesPopulator(uds);
        Collection<? extends GrantedAuthority> auths =  populator.getGrantedAuthorities(new DirContextAdapter(), "joe");
View Full Code Here

Examples of org.springframework.security.core.userdetails.UserDetailsService.loadUserByUsername()

        RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
        roleHierarchy.setHierarchy("ROLE_A > ROLE_B");
        final UserDetails user = new User("EXISTING_USER", "PASSWORD", true, true, true, true,
                AuthorityUtils.createAuthorityList("ROLE_A"));
        final UserDetailsService wrappedUserDetailsService = mock(UserDetailsService.class);
        when(wrappedUserDetailsService.loadUserByUsername("EXISTING_USER")).thenReturn(user);
        when(wrappedUserDetailsService.loadUserByUsername("USERNAME_NOT_FOUND_EXCEPTION")).thenThrow(new UsernameNotFoundException("USERNAME_NOT_FOUND_EXCEPTION"));

        this.wrappedUserDetailsService = wrappedUserDetailsService;
        userDetailsServiceWrapper = new UserDetailsServiceWrapper();
        userDetailsServiceWrapper.setRoleHierarchy(roleHierarchy);
View Full Code Here

Examples of org.springframework.security.core.userdetails.UserDetailsService.loadUserByUsername()

        roleHierarchy.setHierarchy("ROLE_A > ROLE_B");
        final UserDetails user = new User("EXISTING_USER", "PASSWORD", true, true, true, true,
                AuthorityUtils.createAuthorityList("ROLE_A"));
        final UserDetailsService wrappedUserDetailsService = mock(UserDetailsService.class);
        when(wrappedUserDetailsService.loadUserByUsername("EXISTING_USER")).thenReturn(user);
        when(wrappedUserDetailsService.loadUserByUsername("USERNAME_NOT_FOUND_EXCEPTION")).thenThrow(new UsernameNotFoundException("USERNAME_NOT_FOUND_EXCEPTION"));

        this.wrappedUserDetailsService = wrappedUserDetailsService;
        userDetailsServiceWrapper = new UserDetailsServiceWrapper();
        userDetailsServiceWrapper.setRoleHierarchy(roleHierarchy);
        userDetailsServiceWrapper.setUserDetailsService(wrappedUserDetailsService);
View Full Code Here

Examples of org.springframework.security.core.userdetails.UserDetailsService.loadUserByUsername()

    @Test
    public void testHandleUsernameTokenPrincipal() throws Exception {
        UserDetailsService userDetailsService = createMock(UserDetailsService.class);
        callbackHandler.setUserDetailsService(userDetailsService);

        expect(userDetailsService.loadUserByUsername("Ernie")).andReturn(user).anyTimes();

        replay(userDetailsService);

        callbackHandler.handleUsernameTokenPrincipal(callback);
        SecurityContext context = SecurityContextHolder.getContext();
View Full Code Here

Examples of org.springframework.security.core.userdetails.UserDetailsService.loadUserByUsername()

    }

    private UsernamePasswordAuthenticationToken authentication(ServletContext servletContext) {
      ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
      UserDetailsService  userDetailsService = userDetailsService(context);
      UserDetails userDetails = userDetailsService.loadUserByUsername(this.username);
      return new UsernamePasswordAuthenticationToken(
          userDetails, userDetails.getPassword(), userDetails.getAuthorities());
    }

    private UserDetailsService userDetailsService(ApplicationContext context) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.