Search in sources :

Example 6 with OidcKeycloakAccount

use of org.keycloak.adapters.OidcKeycloakAccount in project keycloak by keycloak.

the class FilterRequestAuthenticator method completeOAuthAuthentication.

@Override
protected void completeOAuthAuthentication(final KeycloakPrincipal<RefreshableKeycloakSecurityContext> skp) {
    final RefreshableKeycloakSecurityContext securityContext = skp.getKeycloakSecurityContext();
    final Set<String> roles = AdapterUtils.getRolesFromSecurityContext(securityContext);
    OidcKeycloakAccount account = new OidcKeycloakAccount() {

        @Override
        public Principal getPrincipal() {
            return skp;
        }

        @Override
        public Set<String> getRoles() {
            return roles;
        }

        @Override
        public KeycloakSecurityContext getKeycloakSecurityContext() {
            return securityContext;
        }
    };
    request.setAttribute(KeycloakSecurityContext.class.getName(), securityContext);
    this.tokenStore.saveAccountInfo(account);
}
Also used : OidcKeycloakAccount(org.keycloak.adapters.OidcKeycloakAccount) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) KeycloakSecurityContext(org.keycloak.KeycloakSecurityContext)

Example 7 with OidcKeycloakAccount

use of org.keycloak.adapters.OidcKeycloakAccount in project keycloak by keycloak.

the class OIDCFilterSessionStore method saveAccountInfo.

@Override
public void saveAccountInfo(OidcKeycloakAccount account) {
    RefreshableKeycloakSecurityContext securityContext = (RefreshableKeycloakSecurityContext) account.getKeycloakSecurityContext();
    Set<String> roles = account.getRoles();
    SerializableKeycloakAccount sAccount = new SerializableKeycloakAccount(roles, account.getPrincipal(), securityContext);
    HttpSession httpSession = request.getSession();
    httpSession.setAttribute(KeycloakAccount.class.getName(), sAccount);
    httpSession.setAttribute(KeycloakSecurityContext.class.getName(), sAccount.getKeycloakSecurityContext());
    if (idMapper != null)
        idMapper.map(account.getKeycloakSecurityContext().getToken().getSessionState(), account.getPrincipal().getName(), httpSession.getId());
// String username = securityContext.getToken().getSubject();
// log.fine("userSessionManagement.login: " + username);
}
Also used : RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) KeycloakSecurityContext(org.keycloak.KeycloakSecurityContext) HttpSession(javax.servlet.http.HttpSession) KeycloakAccount(org.keycloak.adapters.spi.KeycloakAccount) OidcKeycloakAccount(org.keycloak.adapters.OidcKeycloakAccount)

Example 8 with OidcKeycloakAccount

use of org.keycloak.adapters.OidcKeycloakAccount in project keycloak by keycloak.

the class JettyRequestAuthenticator method completeOAuthAuthentication.

@Override
protected void completeOAuthAuthentication(final KeycloakPrincipal<RefreshableKeycloakSecurityContext> skp) {
    principal = skp;
    final RefreshableKeycloakSecurityContext securityContext = skp.getKeycloakSecurityContext();
    final Set<String> roles = AdapterUtils.getRolesFromSecurityContext(securityContext);
    OidcKeycloakAccount account = new OidcKeycloakAccount() {

        @Override
        public Principal getPrincipal() {
            return skp;
        }

        @Override
        public Set<String> getRoles() {
            return roles;
        }

        @Override
        public KeycloakSecurityContext getKeycloakSecurityContext() {
            return securityContext;
        }
    };
    request.setAttribute(KeycloakSecurityContext.class.getName(), securityContext);
    this.tokenStore.saveAccountInfo(account);
}
Also used : OidcKeycloakAccount(org.keycloak.adapters.OidcKeycloakAccount) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) KeycloakSecurityContext(org.keycloak.KeycloakSecurityContext)

Example 9 with OidcKeycloakAccount

use of org.keycloak.adapters.OidcKeycloakAccount 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

OidcKeycloakAccount (org.keycloak.adapters.OidcKeycloakAccount)9 KeycloakSecurityContext (org.keycloak.KeycloakSecurityContext)7 RefreshableKeycloakSecurityContext (org.keycloak.adapters.RefreshableKeycloakSecurityContext)7 SimpleKeycloakAccount (org.keycloak.adapters.springsecurity.account.SimpleKeycloakAccount)4 Test (org.junit.Test)2 KeycloakAccount (org.keycloak.adapters.spi.KeycloakAccount)2 Authentication (org.springframework.security.core.Authentication)2 HttpSession (javax.servlet.http.HttpSession)1 OIDCHttpFacade (org.keycloak.adapters.OIDCHttpFacade)1 KeycloakRole (org.keycloak.adapters.springsecurity.account.KeycloakRole)1 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)1