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();
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class AbstractSecurityWebSocketMessageBrokerConfigurerDocTests method setup.
@Before
public void setup() {
token = new DefaultCsrfToken("header", "param", "token");
sessionAttr = "sessionAttr";
messageUser = new TestingAuthenticationToken("user", "pass", "ROLE_USER");
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class AbstractSecurityWebSocketMessageBrokerConfigurerTests method setup.
@Before
public void setup() {
token = new DefaultCsrfToken("header", "param", "token");
sessionAttr = "sessionAttr";
messageUser = new TestingAuthenticationToken("user", "pass", "ROLE_USER");
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class SecurityContextChannelInterceptorTests method restoresOriginalContext.
// SEC-2829
@Test
public void restoresOriginalContext() throws Exception {
TestingAuthenticationToken original = new TestingAuthenticationToken("original", "original", "ROLE_USER");
SecurityContextHolder.getContext().setAuthentication(original);
messageBuilder.setHeader(SimpMessageHeaderAccessor.USER_HEADER, authentication);
interceptor.beforeHandle(messageBuilder.build(), channel, handler);
assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(authentication);
interceptor.afterMessageHandled(messageBuilder.build(), channel, handler, null);
assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(original);
}
Aggregations