use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.
the class AnonymousAuthenticationTokenTests method testNotEqualsDueToDifferentAuthenticationClass.
@Test
public void testNotEqualsDueToDifferentAuthenticationClass() {
AnonymousAuthenticationToken token1 = new AnonymousAuthenticationToken("key", "Test", ROLES_12);
UsernamePasswordAuthenticationToken token2 = new UsernamePasswordAuthenticationToken("Test", "Password", ROLES_12);
assertThat(token1.equals(token2)).isFalse();
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.
the class SpringSecurityAuthenticationSourceTests method principalIsEmptyForAnonymousUser.
@Test
public void principalIsEmptyForAnonymousUser() {
AuthenticationSource source = new SpringSecurityAuthenticationSource();
SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken("key", "anonUser", AuthorityUtils.createAuthorityList("ignored")));
assertThat(source.getPrincipal()).isEqualTo("");
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.
the class DefaultMessageSecurityExpressionHandlerTests method setup.
@BeforeEach
public void setup() {
this.handler = new DefaultMessageSecurityExpressionHandler<>();
this.message = new GenericMessage<>("");
this.authentication = new AnonymousAuthenticationToken("key", "anonymous", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
}
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(this.expectedAnonymous.getName());
assertThat(anonymous.getAuthorities()).containsOnlyElementsOf(this.expectedAnonymous.getAuthorities());
assertThat(anonymous.getKeyHash()).isEqualTo(this.expectedAnonymous.getKeyHash());
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.
the class SecurityContextChannelInterceptorTests method setup.
@BeforeEach
public void setup() {
this.authentication = new TestingAuthenticationToken("user", "pass", "ROLE_USER");
this.messageBuilder = MessageBuilder.withPayload("payload");
this.expectedAnonymous = new AnonymousAuthenticationToken("key", "anonymous", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
this.interceptor = new SecurityContextChannelInterceptor();
}
Aggregations