Search in sources :

Example 76 with AnonymousAuthenticationToken

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();
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) Test(org.junit.jupiter.api.Test)

Example 77 with AnonymousAuthenticationToken

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("");
}
Also used : SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) AuthenticationSource(org.springframework.ldap.core.AuthenticationSource) Test(org.junit.jupiter.api.Test)

Example 78 with AnonymousAuthenticationToken

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"));
}
Also used : AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 79 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(this.expectedAnonymous.getName());
    assertThat(anonymous.getAuthorities()).containsOnlyElementsOf(this.expectedAnonymous.getAuthorities());
    assertThat(anonymous.getKeyHash()).isEqualTo(this.expectedAnonymous.getKeyHash());
}
Also used : Authentication(org.springframework.security.core.Authentication) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken)

Example 80 with AnonymousAuthenticationToken

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();
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)87 Authentication (org.springframework.security.core.Authentication)37 Test (org.junit.jupiter.api.Test)22 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)17 ArrayList (java.util.ArrayList)14 GrantedAuthority (org.springframework.security.core.GrantedAuthority)13 SecurityContext (org.springframework.security.core.context.SecurityContext)10 MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)7 ModuleAuthentication (com.evolveum.midpoint.authentication.api.config.ModuleAuthentication)6 Before (org.junit.Before)5 Test (org.junit.Test)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 FilterChain (jakarta.servlet.FilterChain)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3