use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class HttpSecurityLogoutTests method clearAuthenticationFalse.
// SEC-2848
@Test
public void clearAuthenticationFalse() throws Exception {
loadConfig(ClearAuthenticationFalseConfig.class);
SecurityContext currentContext = SecurityContextHolder.createEmptyContext();
currentContext.setAuthentication(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
request.getSession().setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, currentContext);
request.setMethod("POST");
request.setServletPath("/logout");
springSecurityFilterChain.doFilter(request, response, chain);
assertThat(currentContext.getAuthentication()).isNotNull();
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class PreAuthorizeTests method preAuthorizeAdminRoleGranted.
@Test
public void preAuthorizeAdminRoleGranted() {
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "pass", "ROLE_ADMIN"));
service.preAuthorizeAdminRole();
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class Sec2196Tests method genericMethodsProtected.
@Test(expected = AccessDeniedException.class)
public void genericMethodsProtected() {
loadContext("<global-method-security secured-annotations=\"enabled\" pre-post-annotations=\"enabled\"/>" + "<b:bean class='" + Service.class.getName() + "'/>");
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("test", "pass", "ROLE_USER"));
Service service = context.getBean(Service.class);
service.save(new User());
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class SecuredAnnotationDrivenBeanDefinitionParserTests method targetIsSerializableAfterUse.
@Test(expected = AccessDeniedException.class)
public void targetIsSerializableAfterUse() throws Exception {
try {
target.someAdminMethod();
} catch (AuthenticationCredentialsNotFoundException expected) {
}
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("u", "p", "ROLE_A"));
BusinessService chompedTarget = (BusinessService) serializeAndDeserialize(target);
chompedTarget.someAdminMethod();
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class SecuredTests method securedAdminRoleDenied.
@Test(expected = AccessDeniedException.class)
public void securedAdminRoleDenied() {
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "pass", "ROLE_USER"));
service.securedAdminRole();
}
Aggregations