use of org.keycloak.admin.client.resource.ClientScopesResource in project keycloak by keycloak.
the class ClientScopePolicyTest method testRemovePolicyWhenRemovingScope.
@Test
public void testRemovePolicyWhenRemovingScope() {
createClientScopePolicy("Client Scope To Remove Policy", "to-remove-a", "to-remove-b");
ClientScopesResource clientScopes = getRealm().clientScopes();
ClientScopeRepresentation scopeRep = clientScopes.findAll().stream().filter(r -> r.getName().equals("to-remove-a")).findAny().get();
getClient().removeDefaultClientScope(scopeRep.getId());
getRealm().clientScopes().get(scopeRep.getId()).remove();
ClientScopePolicyRepresentation policyRep = getClient().authorization().policies().clientScope().findByName("Client Scope To Remove Policy");
final String id = scopeRep.getId();
assertFalse(policyRep.getClientScopes().stream().anyMatch(def -> def.getId().equals(id)));
scopeRep = clientScopes.findAll().stream().filter(r -> r.getName().equals("to-remove-b")).findAny().get();
getClient().removeDefaultClientScope(scopeRep.getId());
getRealm().clientScopes().get(scopeRep.getId()).remove();
assertNull(getClient().authorization().policies().clientScope().findByName("Client Scope To Remove Policy"));
}
use of org.keycloak.admin.client.resource.ClientScopesResource in project keycloak by keycloak.
the class AbstractBasePhotozExampleAdapterTest method setManageAlbumScopeRequired.
protected void setManageAlbumScopeRequired() {
ClientScopeRepresentation clientScope = new ClientScopeRepresentation();
clientScope.setName("manage-albums");
clientScope.setProtocol("openid-connect");
ProtocolMapperRepresentation mapper = new ProtocolMapperRepresentation();
mapper.setName("manage-albums");
mapper.setProtocol("openid-connect");
mapper.setProtocolMapper(UserClientRoleMappingMapper.PROVIDER_ID);
Map<String, String> config = new HashMap<>();
config.put("access.token.claim", "true");
config.put("id.token.claim", "true");
config.put("userinfo.token.claim", "true");
config.put(ProtocolMapperUtils.USER_MODEL_CLIENT_ROLE_MAPPING_CLIENT_ID, "photoz-restful-api");
mapper.setConfig(config);
clientScope.setProtocolMappers(Arrays.asList(mapper));
RealmResource realmResource = realmsResouce().realm(REALM_NAME);
ClientScopesResource clientScopes = realmResource.clientScopes();
Response resp = clientScopes.create(clientScope);
Assert.assertEquals(201, resp.getStatus());
resp.close();
String clientScopeId = ApiUtil.getCreatedId(resp);
ClientResource resourceServer = getClientResource(RESOURCE_SERVER_ID);
clientScopes.get(clientScopeId).getScopeMappings().clientLevel(resourceServer.toRepresentation().getId()).add(Arrays.asList(resourceServer.roles().get("manage-albums").toRepresentation()));
ClientResource html5ClientApp = getClientResource("photoz-html5-client");
html5ClientApp.addOptionalClientScope(clientScopeId);
html5ClientApp.getScopeMappings().realmLevel().add(Arrays.asList(realmResource.roles().get("user").toRepresentation(), realmResource.roles().get("admin").toRepresentation()));
ClientRepresentation clientRep = html5ClientApp.toRepresentation();
clientRep.setFullScopeAllowed(false);
html5ClientApp.update(clientRep);
}
use of org.keycloak.admin.client.resource.ClientScopesResource in project keycloak by keycloak.
the class TokenIntrospectionTest method afterAbstractKeycloakTestRealmImport.
@Override
protected void afterAbstractKeycloakTestRealmImport() {
ClientScopesResource clientScopesResource = testRealm().clientScopes();
List<ClientScopeRepresentation> clientScopeRepresentations = clientScopesResource.findAll();
for (ClientScopeRepresentation scope : clientScopeRepresentations) {
List<ProtocolMapperRepresentation> mappers = scope.getProtocolMappers();
if (mappers != null) {
for (ProtocolMapperRepresentation mapper : mappers) {
if ("username".equals(mapper.getName())) {
Map<String, String> config = mapper.getConfig();
config.put("user.attribute", "username");
config.put("claim.name", "preferred_username12");
clientScopesResource.get(scope.getId()).getProtocolMappers().update(mapper.getId(), mapper);
}
}
}
}
}
use of org.keycloak.admin.client.resource.ClientScopesResource in project keycloak by keycloak.
the class UserInfoTest method switchIncludeRolesInUserInfoEndpoint.
private void switchIncludeRolesInUserInfoEndpoint(boolean includeRoles) {
ClientScopesResource clientScopesResource = adminClient.realm("test").clientScopes();
ClientScopeRepresentation rolesClientScope = clientScopesResource.findAll().stream().filter(clientScope -> "roles".equals(clientScope.getName())).findAny().get();
ProtocolMappersResource protocolMappersResource = clientScopesResource.get(rolesClientScope.getId()).getProtocolMappers();
ProtocolMapperRepresentation realmRolesMapper = protocolMappersResource.getMappers().stream().filter(mapper -> "realm roles".equals(mapper.getName())).findAny().get();
realmRolesMapper.getConfig().put(INCLUDE_IN_USERINFO, String.valueOf(includeRoles));
ProtocolMapperRepresentation clientRolesMapper = protocolMappersResource.getMappers().stream().filter(mapper -> "client roles".equals(mapper.getName())).findAny().get();
clientRolesMapper.getConfig().put(INCLUDE_IN_USERINFO, String.valueOf(includeRoles));
protocolMappersResource.update(realmRolesMapper.getId(), realmRolesMapper);
protocolMappersResource.update(clientRolesMapper.getId(), clientRolesMapper);
}
Aggregations