Package org.springframework.security.core.userdetails

Examples of org.springframework.security.core.userdetails.UserDetails


                    "SwitchUserFilter.noOriginalAuthentication",
                    "Could not find original Authentication object"));
        }

        // get the source user details
        UserDetails originalUser = null;
        Object obj = original.getPrincipal();

        if ((obj != null) && obj instanceof UserDetails) {
            originalUser = (UserDetails) obj;
        }
View Full Code Here


        // Determine username
        String username = (authentication.getPrincipal() == null) ? "NONE_PROVIDED" : authentication.getName();

        boolean cacheWasUsed = true;
        UserDetails user = this.userCache.getUserFromCache(username);

        if (user == null) {
            cacheWasUsed = false;

            try {
                user = retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication);
            } catch (UsernameNotFoundException notFound) {
                logger.debug("User '" + username + "' not found");

                if (hideUserNotFoundExceptions) {
                    throw new BadCredentialsException(messages.getMessage(
                            "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
                } else {
                    throw notFound;
                }
            }

            Assert.notNull(user, "retrieveUser returned null - a violation of the interface contract");
        }

        try {
            preAuthenticationChecks.check(user);
            additionalAuthenticationChecks(user, (UsernamePasswordAuthenticationToken) authentication);
        } catch (AuthenticationException exception) {
            if (cacheWasUsed) {
                // There was a problem, so try again after checking
                // we're using latest data (i.e. not from the cache)
                cacheWasUsed = false;
                user = retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication);
                preAuthenticationChecks.check(user);
                additionalAuthenticationChecks(user, (UsernamePasswordAuthenticationToken) authentication);
            } else {
                throw exception;
            }
        }

        postAuthenticationChecks.check(user);

        if (!cacheWasUsed) {
            this.userCache.putUserInCache(user);
        }

        Object principalToReturn = user;

        if (forcePrincipalAsString) {
            principalToReturn = user.getUsername();
        }

        return createSuccessAuthentication(principalToReturn, authentication, user);
    }
View Full Code Here

        Assert.notNull(this.userDetailsService, "A UserDetailsService must be set");
    }

    protected final UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
            throws AuthenticationException {
        UserDetails loadedUser;

        try {
            loadedUser = this.getUserDetailsService().loadUserByUsername(username);
        } catch (UsernameNotFoundException notFound) {
            if(authentication.getCredentials() != null) {
View Full Code Here

*/
@SuppressWarnings("deprecation")
public class UserMapTests {
    @Test
    public void testAddAndRetrieveUser() {
        UserDetails rod = new User("rod", "koala", true, true, true, true,
                AuthorityUtils.createAuthorityList("ROLE_ONE","ROLE_TWO"));
        UserDetails scott = new User("scott", "wombat", true, true, true, true,
                AuthorityUtils.createAuthorityList("ROLE_ONE","ROLE_THREE"));
        UserDetails peter = new User("peter", "opal", true, true, true, true,
                AuthorityUtils.createAuthorityList("ROLE_ONE","ROLE_FOUR"));
        UserMap map = new UserMap();
        map.addUser(rod);
        map.addUser(scott);
        map.addUser(peter);
View Full Code Here

        }
    }

    @Test
    public void unknownUserIsNotRetrieved() {
        UserDetails rod = new User("rod", "koala", true, true, true, true,
                AuthorityUtils.createAuthorityList("ROLE_ONE","ROLE_TWO"));
        UserMap map = new UserMap();
        assertEquals(0, map.getUserCount());
        map.addUser(rod);
        assertEquals(1, map.getUserCount());
View Full Code Here

        return dao;
    }

    public void testCheckDaoAccessUserSuccess() throws Exception {
        JdbcDaoImpl dao = makePopulatedJdbcDao();
        UserDetails user = dao.loadUserByUsername("rod");
        assertEquals("rod", user.getUsername());
        assertEquals("koala", user.getPassword());
        assertTrue(user.isEnabled());

        assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains("ROLE_TELLER"));
        assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains("ROLE_SUPERVISOR"));
    }
View Full Code Here

        assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains("ROLE_SUPERVISOR"));
    }

    public void testCheckDaoOnlyReturnsGrantedAuthoritiesGrantedToUser() throws Exception {
        JdbcDaoImpl dao = makePopulatedJdbcDao();
        UserDetails user = dao.loadUserByUsername("scott");
        assertEquals(1, user.getAuthorities().size());
        assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains("ROLE_TELLER"));
    }
View Full Code Here

        assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains("ROLE_TELLER"));
    }

    public void testCheckDaoReturnsCorrectDisabledProperty() throws Exception {
        JdbcDaoImpl dao = makePopulatedJdbcDao();
        UserDetails user = dao.loadUserByUsername("peter");
        assertTrue(!user.isEnabled());
    }
View Full Code Here

    public void testRolePrefixWorks() throws Exception {
        JdbcDaoImpl dao = makePopulatedJdbcDaoWithRolePrefix();
        assertEquals("ARBITRARY_PREFIX_", dao.getRolePrefix());

        UserDetails user = dao.loadUserByUsername("rod");
        assertEquals("rod", user.getUsername());
        assertEquals(2, user.getAuthorities().size());

        assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains("ARBITRARY_PREFIX_ROLE_TELLER"));
        assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains("ARBITRARY_PREFIX_ROLE_SUPERVISOR"));
    }
View Full Code Here

    public void testGroupAuthoritiesAreLoadedCorrectly() throws Exception {
        JdbcDaoImpl dao = makePopulatedJdbcDao();
        dao.setEnableAuthorities(false);
        dao.setEnableGroups(true);

        UserDetails jerry = dao.loadUserByUsername("jerry");
        assertEquals(3, jerry.getAuthorities().size());
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.core.userdetails.UserDetails

Copyright © 2018 www.massapicom. 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.