Search in sources :

Example 6 with SimpleKeycloakAccount

use of org.keycloak.adapters.springsecurity.account.SimpleKeycloakAccount in project keycloak by keycloak.

the class SpringSecurityCookieTokenStore method checkCurrentToken.

@Override
public void checkCurrentToken() {
    final KeycloakPrincipal<RefreshableKeycloakSecurityContext> principal = checkPrincipalFromCookie();
    if (principal != null) {
        final RefreshableKeycloakSecurityContext securityContext = principal.getKeycloakSecurityContext();
        KeycloakSecurityContext current = ((OIDCHttpFacade) facade).getSecurityContext();
        if (current != null) {
            securityContext.setAuthorizationContext(current.getAuthorizationContext());
        }
        final Set<String> roles = AdapterUtils.getRolesFromSecurityContext(securityContext);
        final OidcKeycloakAccount account = new SimpleKeycloakAccount(principal, roles, securityContext);
        SecurityContextHolder.getContext().setAuthentication(new KeycloakAuthenticationToken(account, false));
    } else {
        super.checkCurrentToken();
    }
    cookieChecked = true;
}
Also used : OidcKeycloakAccount(org.keycloak.adapters.OidcKeycloakAccount) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) KeycloakSecurityContext(org.keycloak.KeycloakSecurityContext) OIDCHttpFacade(org.keycloak.adapters.OIDCHttpFacade) SimpleKeycloakAccount(org.keycloak.adapters.springsecurity.account.SimpleKeycloakAccount)

Example 7 with SimpleKeycloakAccount

use of org.keycloak.adapters.springsecurity.account.SimpleKeycloakAccount in project keycloak by keycloak.

the class SpringSecurityTokenStoreTest method testSaveAccountInfo.

@Test
public void testSaveAccountInfo() throws Exception {
    OidcKeycloakAccount account = new SimpleKeycloakAccount(principal, Collections.singleton("FOO"), keycloakSecurityContext);
    Authentication authentication;
    store.saveAccountInfo(account);
    authentication = SecurityContextHolder.getContext().getAuthentication();
    assertNotNull(authentication);
    assertTrue(authentication instanceof KeycloakAuthenticationToken);
}
Also used : OidcKeycloakAccount(org.keycloak.adapters.OidcKeycloakAccount) Authentication(org.springframework.security.core.Authentication) SimpleKeycloakAccount(org.keycloak.adapters.springsecurity.account.SimpleKeycloakAccount) Test(org.junit.Test)

Aggregations

SimpleKeycloakAccount (org.keycloak.adapters.springsecurity.account.SimpleKeycloakAccount)7 OidcKeycloakAccount (org.keycloak.adapters.OidcKeycloakAccount)5 RefreshableKeycloakSecurityContext (org.keycloak.adapters.RefreshableKeycloakSecurityContext)5 KeycloakSecurityContext (org.keycloak.KeycloakSecurityContext)3 KeycloakAccount (org.keycloak.adapters.spi.KeycloakAccount)3 KeycloakAuthenticationToken (org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken)3 Principal (java.security.Principal)2 Before (org.junit.Before)2 Test (org.junit.Test)2 Authentication (org.springframework.security.core.Authentication)2 SecurityContext (org.springframework.security.core.context.SecurityContext)2 OIDCHttpFacade (org.keycloak.adapters.OIDCHttpFacade)1 KeycloakRole (org.keycloak.adapters.springsecurity.account.KeycloakRole)1 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)1