Package org.springframework.security.core.userdetails

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


                "</user-service>");
        UserDetailsService userService = (UserDetailsService) appContext.getBean("service");
        UserDetails joe = userService.loadUserByUsername("joe");
        assertFalse(joe.isAccountNonLocked());
        // Check case-sensitive lookup SEC-1432
        UserDetails bob = userService.loadUserByUsername("Bob");
        assertFalse(bob.isEnabled());
    }

    @Test(expected=FatalBeanException.class)
    public void userWithBothPropertiesAndEmbeddedUsersThrowsException() {
View Full Code Here


        setContext(
                "<user-service id='service' properties='doesntmatter.props'>" +
                "    <user name='joe' password='joespassword' authorities='ROLE_A'/>" +
                "</user-service>");
        UserDetailsService userService = (UserDetailsService) appContext.getBean("service");
        userService.loadUserByUsername("Joe");
    }

    @Test(expected= FatalBeanException.class)
    public void multipleTopLevelUseWithoutIdThrowsException() {
        setContext(
View Full Code Here

        UserDetailsService service = (UserDetailsService) appContext.getBean("myUserService");
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("Test", "Password",
                AuthorityUtils.createAuthorityList("ROLE_SOMEOTHERROLE"));
        SecurityContextHolder.getContext().setAuthentication(token);

        service.loadUserByUsername("notused");
    }

    @Test
    public void supportsMethodArgumentsInPointcut() {
        setContext(
View Full Code Here

    @Test
    public void userServiceReturnsExpectedData() throws Exception {
        setContext("<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' 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_DEVELOPERS"));
    }
View Full Code Here

                "       user-search-base='ou=otherpeople' " +
                "       user-search-filter='(cn={0})' " +
                "       group-search-filter='member={0}' /><ldap-server ldif='classpath:test-server.ldif'/>");

        UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
        UserDetails joe = uds.loadUserByUsername("Joe Smeth");

        assertEquals("Joe Smeth", joe.getUsername());
    }

    @Test
View Full Code Here

                "<ldap-user-service id='ldapUDSNoPrefix' " +
                "     user-search-filter='(uid={0})' " +
                "     group-search-filter='member={0}' role-prefix='none'/><ldap-server ldif='classpath:test-server.ldif'/>");

        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

        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

    @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

    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

    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

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.