use of org.keycloak.adapters.springsecurity.account.KeycloakRole in project keycloak by keycloak.
the class SpringSecurityTokenStoreTest method testIsCached.
@Test
public void testIsCached() throws Exception {
Authentication authentication = new PreAuthenticatedAuthenticationToken("foo", "bar", Collections.singleton(new KeycloakRole("ROLE_FOO")));
SecurityContextHolder.getContext().setAuthentication(authentication);
assertFalse(store.isCached(requestAuthenticator));
}
use of org.keycloak.adapters.springsecurity.account.KeycloakRole in project keycloak by keycloak.
the class SpringSecurityTokenStoreTest method testSaveAccountInfoInvalidAuthenticationType.
@Test(expected = IllegalStateException.class)
public void testSaveAccountInfoInvalidAuthenticationType() throws Exception {
OidcKeycloakAccount account = new SimpleKeycloakAccount(principal, Collections.singleton("FOO"), keycloakSecurityContext);
Authentication authentication = new PreAuthenticatedAuthenticationToken("foo", "bar", Collections.singleton(new KeycloakRole("ROLE_FOO")));
SecurityContextHolder.getContext().setAuthentication(authentication);
store.saveAccountInfo(account);
}
use of org.keycloak.adapters.springsecurity.account.KeycloakRole in project keycloak by keycloak.
the class KeycloakClientRequestFactoryTest method testGetKeycloakSecurityContextInvalidAuthentication.
@Test(expected = IllegalStateException.class)
public void testGetKeycloakSecurityContextInvalidAuthentication() throws Exception {
SecurityContextHolder.getContext().setAuthentication(new PreAuthenticatedAuthenticationToken("foo", "bar", Collections.singleton(new KeycloakRole("baz"))));
factory.getKeycloakSecurityContext();
}
use of org.keycloak.adapters.springsecurity.account.KeycloakRole in project keycloak by keycloak.
the class KeycloakAuthenticationProvider method authenticate.
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
KeycloakAuthenticationToken token = (KeycloakAuthenticationToken) authentication;
List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
for (String role : token.getAccount().getRoles()) {
grantedAuthorities.add(new KeycloakRole(role));
}
return new KeycloakAuthenticationToken(token.getAccount(), token.isInteractive(), mapAuthorities(grantedAuthorities));
}
use of org.keycloak.adapters.springsecurity.account.KeycloakRole in project shinyproxy by openanalytics.
the class KeycloakAuthenticationBackend method keycloakAuthenticationProvider.
protected KeycloakAuthenticationProvider keycloakAuthenticationProvider() {
return new KeycloakAuthenticationProvider() {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
KeycloakAuthenticationToken token = (KeycloakAuthenticationToken) super.authenticate(authentication);
List<GrantedAuthority> auth = token.getAuthorities().stream().map(t -> t.getAuthority().toUpperCase()).map(a -> a.startsWith("ROLE_") ? a : "ROLE_" + a).map(a -> new KeycloakRole(a)).collect(Collectors.toList());
return new KeycloakAuthenticationToken2(token.getAccount(), auth);
}
};
}
Aggregations