Search in sources :

Example 1 with PrincipalNameResolver

use of org.springframework.session.data.redis.RedisOperationsSessionRepository.PrincipalNameResolver in project spring-session by spring-projects.

the class RedisOperationsSessionRepositoryTests method resolvePrincipalIndex.

@Test
public void resolvePrincipalIndex() {
    PrincipalNameResolver resolver = RedisOperationsSessionRepository.PRINCIPAL_NAME_RESOLVER;
    String username = "username";
    RedisSession session = this.redisRepository.createSession();
    session.setAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username);
    assertThat(resolver.resolvePrincipal(session)).isEqualTo(username);
}
Also used : RedisSession(org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PrincipalNameResolver(org.springframework.session.data.redis.RedisOperationsSessionRepository.PrincipalNameResolver) Test(org.junit.Test)

Example 2 with PrincipalNameResolver

use of org.springframework.session.data.redis.RedisOperationsSessionRepository.PrincipalNameResolver in project spring-session by spring-projects.

the class RedisOperationsSessionRepositoryTests method resolveIndexOnSecurityContext.

@Test
public void resolveIndexOnSecurityContext() {
    String principal = "resolveIndexOnSecurityContext";
    Authentication authentication = new UsernamePasswordAuthenticationToken(principal, "notused", AuthorityUtils.createAuthorityList("ROLE_USER"));
    SecurityContext context = new SecurityContextImpl();
    context.setAuthentication(authentication);
    PrincipalNameResolver resolver = RedisOperationsSessionRepository.PRINCIPAL_NAME_RESOLVER;
    RedisSession session = this.redisRepository.createSession();
    session.setAttribute(SPRING_SECURITY_CONTEXT_KEY, context);
    assertThat(resolver.resolvePrincipal(session)).isEqualTo(principal);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) RedisSession(org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PrincipalNameResolver(org.springframework.session.data.redis.RedisOperationsSessionRepository.PrincipalNameResolver) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 PrincipalNameResolver (org.springframework.session.data.redis.RedisOperationsSessionRepository.PrincipalNameResolver)2 RedisSession (org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)1