Search in sources :

Example 26 with AnonymousAuthenticationToken

use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.

the class SecurityContextChannelInterceptorTests method assertAnonymous.

private void assertAnonymous() {
    Authentication currentAuthentication = SecurityContextHolder.getContext().getAuthentication();
    assertThat(currentAuthentication).isInstanceOf(AnonymousAuthenticationToken.class);
    AnonymousAuthenticationToken anonymous = (AnonymousAuthenticationToken) currentAuthentication;
    assertThat(anonymous.getName()).isEqualTo(expectedAnonymous.getName());
    assertThat(anonymous.getAuthorities()).containsOnlyElementsOf(expectedAnonymous.getAuthorities());
    assertThat(anonymous.getKeyHash()).isEqualTo(expectedAnonymous.getKeyHash());
}
Also used : Authentication(org.springframework.security.core.Authentication) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken)

Example 27 with AnonymousAuthenticationToken

use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.

the class DefaultMessageSecurityExpressionHandlerTests method setup.

@Before
public void setup() {
    handler = new DefaultMessageSecurityExpressionHandler<Object>();
    message = new GenericMessage<Object>("");
    authentication = new AnonymousAuthenticationToken("key", "anonymous", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
}
Also used : AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) Before(org.junit.Before)

Example 28 with AnonymousAuthenticationToken

use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.

the class SecurityContextChannelInterceptorTests method setup.

@Before
public void setup() {
    authentication = new TestingAuthenticationToken("user", "pass", "ROLE_USER");
    messageBuilder = MessageBuilder.withPayload("payload");
    expectedAnonymous = new AnonymousAuthenticationToken("key", "anonymous", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
    interceptor = new SecurityContextChannelInterceptor();
}
Also used : SecurityContextChannelInterceptor(org.springframework.security.messaging.context.SecurityContextChannelInterceptor) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) Before(org.junit.Before)

Example 29 with AnonymousAuthenticationToken

use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.

the class SecurityContextChannelInterceptorTests method preSendUsesCustomAnonymous.

@Test
public void preSendUsesCustomAnonymous() throws Exception {
    expectedAnonymous = new AnonymousAuthenticationToken("customKey", "customAnonymous", AuthorityUtils.createAuthorityList("ROLE_CUSTOM"));
    interceptor.setAnonymousAuthentication(expectedAnonymous);
    interceptor.preSend(messageBuilder.build(), channel);
    assertAnonymous();
}
Also used : AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) Test(org.junit.Test)

Example 30 with AnonymousAuthenticationToken

use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.

the class WithAnonymousUserSecurityContextFactory method createSecurityContext.

public SecurityContext createSecurityContext(WithAnonymousUser withUser) {
    List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS");
    Authentication authentication = new AnonymousAuthenticationToken("key", "anonymous", authorities);
    SecurityContext context = SecurityContextHolder.createEmptyContext();
    context.setAuthentication(authentication);
    return context;
}
Also used : Authentication(org.springframework.security.core.Authentication) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SecurityContext(org.springframework.security.core.context.SecurityContext) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken)

Aggregations

AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)40 Test (org.junit.Test)20 Authentication (org.springframework.security.core.Authentication)13 GrantedAuthority (org.springframework.security.core.GrantedAuthority)7 ArrayList (java.util.ArrayList)6 Before (org.junit.Before)6 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)3 SecurityContext (org.springframework.security.core.context.SecurityContext)3 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2 AnonymousAuthenticationProvider (org.springframework.security.authentication.AnonymousAuthenticationProvider)2 User (org.springframework.security.core.userdetails.User)2 UserDetails (org.springframework.security.core.userdetails.UserDetails)2 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)2 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)2 SecurityQuestionsAuthenticationContext (com.evolveum.midpoint.model.api.context.SecurityQuestionsAuthenticationContext)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1