Search in sources :

Example 6 with KeycloakAccount

use of org.keycloak.adapters.spi.KeycloakAccount in project keycloak by keycloak.

the class SpringSecurityRequestAuthenticator method completeBearerAuthentication.

@Override
protected void completeBearerAuthentication(KeycloakPrincipal<RefreshableKeycloakSecurityContext> principal, String method) {
    RefreshableKeycloakSecurityContext securityContext = principal.getKeycloakSecurityContext();
    Set<String> roles = AdapterUtils.getRolesFromSecurityContext(securityContext);
    final KeycloakAccount account = new SimpleKeycloakAccount(principal, roles, securityContext);
    logger.debug("Completing bearer authentication. Bearer roles: {} ", roles);
    SecurityContext context = SecurityContextHolder.createEmptyContext();
    context.setAuthentication(new KeycloakAuthenticationToken(account, false));
    SecurityContextHolder.setContext(context);
    request.setAttribute(KeycloakSecurityContext.class.getName(), securityContext);
}
Also used : KeycloakAuthenticationToken(org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) KeycloakSecurityContext(org.keycloak.KeycloakSecurityContext) SimpleKeycloakAccount(org.keycloak.adapters.springsecurity.account.SimpleKeycloakAccount) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) KeycloakSecurityContext(org.keycloak.KeycloakSecurityContext) SecurityContext(org.springframework.security.core.context.SecurityContext) KeycloakAccount(org.keycloak.adapters.spi.KeycloakAccount) OidcKeycloakAccount(org.keycloak.adapters.OidcKeycloakAccount) SimpleKeycloakAccount(org.keycloak.adapters.springsecurity.account.SimpleKeycloakAccount)

Example 7 with KeycloakAccount

use of org.keycloak.adapters.spi.KeycloakAccount in project keycloak by keycloak.

the class FilterSamlSessionStore method getWrap.

public HttpServletRequestWrapper getWrap() {
    HttpSession session = request.getSession(true);
    final SamlSession samlSession = (SamlSession) session.getAttribute(SamlSession.class.getName());
    final KeycloakAccount account = samlSession;
    return buildWrapper(session, account);
}
Also used : HttpSession(javax.servlet.http.HttpSession) KeycloakAccount(org.keycloak.adapters.spi.KeycloakAccount) SamlSession(org.keycloak.adapters.saml.SamlSession)

Aggregations

KeycloakAccount (org.keycloak.adapters.spi.KeycloakAccount)7 Principal (java.security.Principal)3 RefreshableKeycloakSecurityContext (org.keycloak.adapters.RefreshableKeycloakSecurityContext)3 SimpleKeycloakAccount (org.keycloak.adapters.springsecurity.account.SimpleKeycloakAccount)3 KeycloakAuthenticationToken (org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken)3 HttpSession (javax.servlet.http.HttpSession)2 Before (org.junit.Before)2 OidcKeycloakAccount (org.keycloak.adapters.OidcKeycloakAccount)2 SecurityContext (org.springframework.security.core.context.SecurityContext)2 Group (java.security.acl.Group)1 ArrayList (java.util.ArrayList)1 Subject (javax.security.auth.Subject)1 GenericPrincipal (org.apache.catalina.realm.GenericPrincipal)1 JBossGenericPrincipal (org.jboss.as.web.security.JBossGenericPrincipal)1 NestableGroup (org.jboss.security.NestableGroup)1 SecurityContext (org.jboss.security.SecurityContext)1 SimpleGroup (org.jboss.security.SimpleGroup)1 SimplePrincipal (org.jboss.security.SimplePrincipal)1 KeycloakSecurityContext (org.keycloak.KeycloakSecurityContext)1 SamlSession (org.keycloak.adapters.saml.SamlSession)1