Package org.springframework.security.core.context

Examples of org.springframework.security.core.context.SecurityContext


    }

    @Test
    public void disableClearsAuthentication() {
        handler.setClearAuthentication(false);
        SecurityContext beforeContext = SecurityContextHolder.getContext();
        Authentication beforeAuthentication = beforeContext.getAuthentication();
        handler.logout(request, response, SecurityContextHolder.getContext().getAuthentication());

        assertNotNull(beforeContext.getAuthentication());
        assertSame(beforeAuthentication, beforeContext.getAuthentication());
    }
View Full Code Here


    }

    @Test
    public void getAsyncContextStart() throws Exception {
        ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        SecurityContext context = SecurityContextHolder.createEmptyContext();
        TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password","ROLE_USER");
        context.setAuthentication(expectedAuth);
        SecurityContextHolder.setContext(context);
        AsyncContext asyncContext = mock(AsyncContext.class);
        when(request.getAsyncContext()).thenReturn(asyncContext);
        Runnable runnable = new Runnable() {
            public void run() {}
View Full Code Here

    }

    @Test
    public void startAsyncStart() throws Exception {
        ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        SecurityContext context = SecurityContextHolder.createEmptyContext();
        TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password","ROLE_USER");
        context.setAuthentication(expectedAuth);
        SecurityContextHolder.setContext(context);
        AsyncContext asyncContext = mock(AsyncContext.class);
        when(request.startAsync()).thenReturn(asyncContext);
        Runnable runnable = new Runnable() {
            public void run() {}
View Full Code Here

    }

    @Test
    public void startAsyncWithRequestResponseStart() throws Exception {
        ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        SecurityContext context = SecurityContextHolder.createEmptyContext();
        TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password","ROLE_USER");
        context.setAuthentication(expectedAuth);
        SecurityContextHolder.setContext(context);
        AsyncContext asyncContext = mock(AsyncContext.class);
        when(request.startAsync(request,response)).thenReturn(asyncContext);
        Runnable runnable = new Runnable() {
            public void run() {}
View Full Code Here

    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

    public void loadedContextContextIsCopiedToSecurityContextHolderAndUpdatedContextIsStored() throws Exception {
        final MockHttpServletRequest request = new MockHttpServletRequest();
        final MockHttpServletResponse response = new MockHttpServletResponse();
        SecurityContextPersistenceFilter filter = new SecurityContextPersistenceFilter();
        final TestingAuthenticationToken beforeAuth = new TestingAuthenticationToken("someoneelse", "passwd", "ROLE_B");
        final SecurityContext scBefore = new SecurityContextImpl();
        final SecurityContext scExpectedAfter = new SecurityContextImpl();
        scExpectedAfter.setAuthentication(testToken);
        scBefore.setAuthentication(beforeAuth);
        final SecurityContextRepository repo = mock(SecurityContextRepository.class);
        filter.setSecurityContextRepository(repo);

        when(repo.loadContext(any(HttpRequestResponseHolder.class))).thenReturn(scBefore);
View Full Code Here

            }
            authorities.add(new SimpleGrantedAuthority("ROLE_"+role));
        }
        User principal = new User(username, withUser.password(), true, true, true, true, authorities);
        Authentication authentication = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), principal.getAuthorities());
        SecurityContext context = SecurityContextHolder.createEmptyContext();
        context.setAuthentication(authentication);
        return context;
    }
View Full Code Here

        private String expectedAuthenticationName;
        private Collection<GrantedAuthority> expectedGrantedAuthorities;


        public void match(MvcResult result) throws Exception {
            SecurityContext context = load(result);

            Authentication auth = context.getAuthentication();

            assertTrue("Authentication should not be null", auth != null);

            if(this.expectedContext != null) {
                assertEquals(this.expectedContext + " does not equal " + context, this.expectedContext, context);
            }

            if(this.expectedAuthentication != null) {
                assertEquals(this.expectedAuthentication + " does not equal " + context.getAuthentication(), this.expectedAuthentication, context.getAuthentication());
            }

            if(this.expectedAuthenticationPrincipal != null) {
                assertTrue("Authentication cannot be null", context.getAuthentication() != null);
                assertEquals(this.expectedAuthenticationPrincipal + " does not equal " + context.getAuthentication().getPrincipal(), this.expectedAuthenticationPrincipal, context.getAuthentication().getPrincipal());
            }

            if(this.expectedAuthenticationName != null) {
                assertTrue("Authentication cannot be null", auth != null);
                String name = auth.getName();
View Full Code Here

        WASUsernameAndGroupsExtractor helper = mock(WASUsernameAndGroupsExtractor.class);
        when(helper.getCurrentUserName()).thenReturn("joe");
        WebSphere2SpringSecurityPropagationInterceptor interceptor =
            new WebSphere2SpringSecurityPropagationInterceptor(helper);

        final SecurityContext context = new SecurityContextImpl();

        interceptor.setAuthenticationManager(new AuthenticationManager() {
            public Authentication authenticate(Authentication authentication) {
                // Store the auth object
                context.setAuthentication(authentication);
                return null;
            }
        });
        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

     * @since 4.0
     */
    private static final class UnAuthenticatedMatcher extends AuthenticationMatcher<UnAuthenticatedMatcher>{

        public void match(MvcResult result) throws Exception {
            SecurityContext context = load(result);

            assertEquals("",null,context.getAuthentication());
        }
View Full Code Here

TOP

Related Classes of org.springframework.security.core.context.SecurityContext

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.