Package org.springframework.security.core.context

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


    @Test
    public void userDetails() {
        authentication(authentication).postProcessRequest(request);

        verify(repository).saveContext(contextCaptor.capture(), eq(request), any(HttpServletResponse.class));
        SecurityContext context = contextCaptor.getValue();
        assertThat(context.getAuthentication()).isSameAs(authentication);
    }
View Full Code Here


        String username = "userabc";

        user(username).postProcessRequest(request);

        verify(repository).saveContext(contextCaptor.capture(), eq(request), any(HttpServletResponse.class));
        SecurityContext context = contextCaptor.getValue();
        assertThat(context.getAuthentication()).isInstanceOf(UsernamePasswordAuthenticationToken.class);
        assertThat(context.getAuthentication().getName()).isEqualTo(username);
        assertThat(context.getAuthentication().getCredentials()).isEqualTo("password");
        assertThat(context.getAuthentication().getAuthorities()).onProperty("authority").containsOnly("ROLE_USER");
    }
View Full Code Here

            .roles("CUSTOM","ADMIN")
            .password("newpass")
            .postProcessRequest(request);

        verify(repository).saveContext(contextCaptor.capture(), eq(request), any(HttpServletResponse.class));
        SecurityContext context = contextCaptor.getValue();
        assertThat(context.getAuthentication()).isInstanceOf(UsernamePasswordAuthenticationToken.class);
        assertThat(context.getAuthentication().getName()).isEqualTo(username);
        assertThat(context.getAuthentication().getCredentials()).isEqualTo("newpass");
        assertThat(context.getAuthentication().getAuthorities()).onProperty("authority").containsOnly("ROLE_CUSTOM","ROLE_ADMIN");
    }
View Full Code Here

        user(username)
            .authorities(authority1,authority2)
            .postProcessRequest(request);

        verify(repository).saveContext(contextCaptor.capture(), eq(request), any(HttpServletResponse.class));
        SecurityContext context = contextCaptor.getValue();
        assertThat(context.getAuthentication().getAuthorities()).containsOnly(authority1,authority2);
    }
View Full Code Here

        user(username)
            .authorities(Arrays.asList(authority1,authority2))
            .postProcessRequest(request);

        verify(repository).saveContext(contextCaptor.capture(), eq(request), any(HttpServletResponse.class));
        SecurityContext context = contextCaptor.getValue();
        assertThat(context.getAuthentication().getAuthorities()).containsOnly(authority1,authority2);
    }
View Full Code Here

                session.invalidate();
            }
        }

        if(clearAuthentication) {
            SecurityContext context = SecurityContextHolder.getContext();
            context.setAuthentication(null);
        }

        SecurityContextHolder.clearContext();
    }
View Full Code Here

         * @param authentication the {@link Authentication} to save
         * @param request the {@link HttpServletRequest} to use
         */
        final void save(Authentication authentication,
                HttpServletRequest request) {
            SecurityContext securityContext = SecurityContextHolder
                    .createEmptyContext();
            securityContext.setAuthentication(authentication);
            save(securityContext, request);
        }
View Full Code Here

            private TestSecurityContextRepository(SecurityContextRepository delegate) {
                this.delegate = delegate;
            }

            public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) {
                SecurityContext result = getContext(requestResponseHolder.getRequest());
                // always load from the delegate to ensure the request/response in the holder are updated
                // remember the SecurityContextRepository is used in many different locations
                SecurityContext delegateResult = delegate.loadContext(requestResponseHolder);
                return result == null ? delegateResult : result;
            }
View Full Code Here

            this.authentication = authentication;
        }

        public MockHttpServletRequest postProcessRequest(
                MockHttpServletRequest request) {
            SecurityContext context = SecurityContextHolder.getContext();
            context.setAuthentication(authentication);
            save(authentication, request);
            return request;
        }
View Full Code Here

    public void sessionIsntCreatedIfContextDoesntChange() throws Exception {
        HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response);
        SecurityContext context = repo.loadContext(holder);
        assertNull(request.getSession(false));
        repo.saveContext(context, holder.getRequest(), holder.getResponse());
        assertNull(request.getSession(false));
    }
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.