Package org.springframework.security.core.userdetails

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


    }

    public SecurityContext createSecurityContext(WithUserDetails withUser) {
        String username = withUser.value();
        Assert.hasLength(username, "value() must be non empty String");
        UserDetails principal = userDetailsService.loadUserByUsername(username);
        Authentication authentication = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), principal.getAuthorities());
        SecurityContext context = SecurityContextHolder.createEmptyContext();
        context.setAuthentication(authentication);
        return context;
    }
View Full Code Here


    /**
     * Implementation of {@code UserDetailsService}. We only need this to satisfy the {@code RememberMeServices}
     * requirements.
     */
    public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException {
        UserDetails user = registeredUsers.get(id);

        if (user == null) {
            throw new UsernameNotFoundException(id);
        }

View Full Code Here

        interceptor.setAuthenticationDetailsSource(mock(AuthenticationDetailsSource.class));
        interceptor.invoke(mock(MethodInvocation.class));

        PreAuthenticatedAuthenticationProvider provider = new PreAuthenticatedAuthenticationProvider();
        AuthenticationUserDetailsService uds = mock(AuthenticationUserDetailsService.class);
        UserDetails user = mock(UserDetails.class);
        List authorities = AuthorityUtils.createAuthorityList("SOME_ROLE");
        when(user.getAuthorities()).thenReturn(authorities);
        when(uds.loadUserDetails(any(Authentication.class))).thenReturn(user);
        provider.setPreAuthenticatedUserDetailsService(uds);
        provider.setUserDetailsChecker(mock(UserDetailsChecker.class));

        assertNotNull(provider.authenticate(context.getAuthentication()));
View Full Code Here

        protected UserDetails processAutoLoginCookie(String[] cookieTokens, HttpServletRequest request, HttpServletResponse response) throws RememberMeAuthenticationException {
            if(cookieTokens.length != 3) {
                throw new InvalidCookieException("deliberate exception");
            }

            UserDetails user = getUserDetailsService().loadUserByUsername("joe");

            return user;
        }
View Full Code Here

        token.setDetails(new GrantedAuthoritiesContainer() {
            public Collection<? extends GrantedAuthority> getGrantedAuthorities() {
                return gas;
            }
        });
        UserDetails ud = svc.loadUserDetails(token);
        assertTrue(ud.isAccountNonExpired());
        assertTrue(ud.isAccountNonLocked());
        assertTrue(ud.isCredentialsNonExpired());
        assertTrue(ud.isEnabled());
        assertEquals(ud.getUsername(), userName);

        //Password is not saved by
        // PreAuthenticatedGrantedAuthoritiesUserDetailsService
        //assertEquals(ud.getPassword(),password);

        assertTrue("GrantedAuthority collections do not match; result: " + ud.getAuthorities() + ", expected: " + gas,
                gas.containsAll(ud.getAuthorities()) && ud.getAuthorities().containsAll(gas));
    }
View Full Code Here

        Object authDetails = new Object();
        authRequest.setDetails(authDetails);
        Authentication authResult = ldapProvider.authenticate(authRequest);
        assertEquals("benspassword", authResult.getCredentials());
        assertSame(authDetails, authResult.getDetails());
        UserDetails user = (UserDetails) authResult.getPrincipal();
        assertEquals(2, user.getAuthorities().size());
        assertEquals("{SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ=", user.getPassword());
        assertEquals("ben", user.getUsername());
        assertEquals("ben", populator.getRequestedUsername());

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

        LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator());
        LdapUserDetailsMapper userMapper = new LdapUserDetailsMapper();
        userMapper.setRoleAttributes(new String[] {"ou"});
        ldapProvider.setUserDetailsContextMapper(userMapper);
        UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken("ben", "benspassword");
        UserDetails user = (UserDetails) ldapProvider.authenticate(authRequest).getPrincipal();
        assertEquals(1, user.getAuthorities().size());
        assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains("ROLE_FROM_ENTRY"));
    }
View Full Code Here

            OpenIDAuthenticationStatus status = response.getStatus();

            // handle the various possibilities
            if (status == OpenIDAuthenticationStatus.SUCCESS) {
                // Lookup user details
                UserDetails userDetails = userDetailsService.loadUserDetails(response);

                return createSuccessfulAuthentication(userDetails, response);

            } else if (status == OpenIDAuthenticationStatus.CANCELLED) {
                throw new AuthenticationCancelledException("Log in cancelled");
View Full Code Here

    public void setUserCache(UserCache userCache) {
        this.userCache = userCache;
    }

    public UserDetails loadUserByUsername(String username) {
        UserDetails user = userCache.getUserFromCache(username);

        if (user == null) {
            user = delegate.loadUserByUsername(username);
        }
View Full Code Here

        attributes.put("someother", "unused");
        when(assertion.getPrincipal()).thenReturn(principal);
        when(principal.getAttributes()).thenReturn(attributes);
        when(principal.getName()).thenReturn("somebody");
        CasAssertionAuthenticationToken token = new CasAssertionAuthenticationToken(assertion, "ticket");
        UserDetails user = uds.loadUserDetails(token);
        Set<String> roles = AuthorityUtils.authorityListToSet(user.getAuthorities());
        assertTrue(roles.size() == 4);
        assertTrue(roles.contains("role_a1"));
        assertTrue(roles.contains("role_a2"));
        assertTrue(roles.contains("role_b"));
        assertTrue(roles.contains("role_c"));
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.