use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method testCreateDynamicScopeWithFeatureDisabledAndNonEmptyDynamicScopeRegexp.
@Test
@DisableFeature(value = Profile.Feature.DYNAMIC_SCOPES, skipRestart = true)
public void testCreateDynamicScopeWithFeatureDisabledAndNonEmptyDynamicScopeRegexp() {
ClientScopeRepresentation scopeRep = new ClientScopeRepresentation();
scopeRep.setName("non-dynamic-scope-def3");
scopeRep.setProtocol("openid-connect");
scopeRep.setAttributes(new HashMap<String, String>() {
{
put(ClientScopeModel.IS_DYNAMIC_SCOPE, "false");
put(ClientScopeModel.DYNAMIC_SCOPE_REGEXP, "not-empty");
}
});
handleExpectedCreateFailure(scopeRep, 400, "Unexpected value \"not-empty\" for attribute dynamic.scope.regexp in ClientScope");
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method testUpdateScopeScope.
@Test
public void testUpdateScopeScope() {
// Test creating
ClientScopeRepresentation scopeRep = new ClientScopeRepresentation();
scopeRep.setName("scope1");
scopeRep.setDescription("scope1-desc");
scopeRep.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL);
Map<String, String> attrs = new HashMap<>();
attrs.put("someAttr", "someAttrValue");
attrs.put("emptyAttr", "");
scopeRep.setAttributes(attrs);
String scope1Id = createClientScope(scopeRep);
// Assert created attributes
scopeRep = clientScopes().get(scope1Id).toRepresentation();
Assert.assertEquals("scope1", scopeRep.getName());
Assert.assertEquals("scope1-desc", scopeRep.getDescription());
Assert.assertEquals("someAttrValue", scopeRep.getAttributes().get("someAttr"));
assertTrue(ObjectUtil.isBlank(scopeRep.getAttributes().get("emptyAttr")));
Assert.assertEquals(OIDCLoginProtocol.LOGIN_PROTOCOL, scopeRep.getProtocol());
// Test updating
scopeRep.setName("scope1-updated");
scopeRep.setDescription("scope1-desc-updated");
scopeRep.setProtocol(SamlProtocol.LOGIN_PROTOCOL);
// Test update attribute to some non-blank value
scopeRep.getAttributes().put("emptyAttr", "someValue");
clientScopes().get(scope1Id).update(scopeRep);
assertAdminEvents.assertEvent(getRealmId(), OperationType.UPDATE, AdminEventPaths.clientScopeResourcePath(scope1Id), scopeRep, ResourceType.CLIENT_SCOPE);
// Assert updated attributes
scopeRep = clientScopes().get(scope1Id).toRepresentation();
Assert.assertEquals("scope1-updated", scopeRep.getName());
Assert.assertEquals("scope1-desc-updated", scopeRep.getDescription());
Assert.assertEquals(SamlProtocol.LOGIN_PROTOCOL, scopeRep.getProtocol());
Assert.assertEquals("someAttrValue", scopeRep.getAttributes().get("someAttr"));
Assert.assertEquals("someValue", scopeRep.getAttributes().get("emptyAttr"));
// Remove scope1
clientScopes().get(scope1Id).remove();
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method testUpdateProtocolMappers.
// KEYCLOAK-5863
@Test
public void testUpdateProtocolMappers() {
ClientScopeRepresentation scopeRep = new ClientScopeRepresentation();
scopeRep.setName("testUpdateProtocolMappers");
scopeRep.setProtocol("openid-connect");
String scopeId = createClientScope(scopeRep);
ProtocolMapperRepresentation mapper = new ProtocolMapperRepresentation();
mapper.setName("test");
mapper.setProtocol("openid-connect");
mapper.setProtocolMapper("oidc-usermodel-attribute-mapper");
Map<String, String> m = new HashMap<>();
m.put("user.attribute", "test");
m.put("claim.name", "");
m.put("jsonType.label", "");
mapper.setConfig(m);
ProtocolMappersResource protocolMappers = clientScopes().get(scopeId).getProtocolMappers();
Response response = protocolMappers.createMapper(mapper);
String mapperId = ApiUtil.getCreatedId(response);
mapper = protocolMappers.getMapperById(mapperId);
mapper.getConfig().put("claim.name", "claim");
protocolMappers.update(mapperId, mapper);
List<ProtocolMapperRepresentation> mappers = protocolMappers.getMappers();
assertEquals(1, mappers.size());
assertEquals(2, mappers.get(0).getConfig().size());
assertEquals("test", mappers.get(0).getConfig().get("user.attribute"));
assertEquals("claim", mappers.get(0).getConfig().get("claim.name"));
clientScopes().get(scopeId).remove();
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method testScopes.
@Test
public void testScopes() {
RoleRepresentation realmCompositeRole = createRealmRole("realm-composite");
RoleRepresentation realmChildRole = createRealmRole("realm-child");
testRealmResource().roles().get("realm-composite").addComposites(Collections.singletonList(realmChildRole));
assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, AdminEventPaths.roleResourceCompositesPath("realm-composite"), Collections.singletonList(realmChildRole), ResourceType.REALM_ROLE);
// create client scope
ClientScopeRepresentation scopeRep = new ClientScopeRepresentation();
scopeRep.setName("bar-scope");
String scopeId = createClientScope(scopeRep);
// update with some scopes
String accountMgmtId = testRealmResource().clients().findByClientId(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID).get(0).getId();
RoleRepresentation viewAccountRoleRep = testRealmResource().clients().get(accountMgmtId).roles().get(AccountRoles.VIEW_PROFILE).toRepresentation();
RoleMappingResource scopesResource = clientScopes().get(scopeId).getScopeMappings();
scopesResource.realmLevel().add(Collections.singletonList(realmCompositeRole));
assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, AdminEventPaths.clientScopeRoleMappingsRealmLevelPath(scopeId), Collections.singletonList(realmCompositeRole), ResourceType.REALM_SCOPE_MAPPING);
scopesResource.clientLevel(accountMgmtId).add(Collections.singletonList(viewAccountRoleRep));
assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, AdminEventPaths.clientScopeRoleMappingsClientLevelPath(scopeId, accountMgmtId), Collections.singletonList(viewAccountRoleRep), ResourceType.CLIENT_SCOPE_MAPPING);
// test that scopes are available (also through composite role)
List<RoleRepresentation> allRealm = scopesResource.realmLevel().listAll();
List<RoleRepresentation> availableRealm = scopesResource.realmLevel().listAvailable();
List<RoleRepresentation> effectiveRealm = scopesResource.realmLevel().listEffective();
List<RoleRepresentation> accountRoles = scopesResource.clientLevel(accountMgmtId).listAll();
assertNames(allRealm, "realm-composite");
assertNames(availableRealm, "realm-child", Constants.OFFLINE_ACCESS_ROLE, Constants.AUTHZ_UMA_AUTHORIZATION, Constants.DEFAULT_ROLES_ROLE_PREFIX + "-test");
assertNames(effectiveRealm, "realm-composite", "realm-child");
assertNames(accountRoles, AccountRoles.VIEW_PROFILE);
MappingsRepresentation mappingsRep = clientScopes().get(scopeId).getScopeMappings().getAll();
assertNames(mappingsRep.getRealmMappings(), "realm-composite");
assertNames(mappingsRep.getClientMappings().get(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID).getMappings(), AccountRoles.VIEW_PROFILE);
// remove scopes
scopesResource.realmLevel().remove(Collections.singletonList(realmCompositeRole));
assertAdminEvents.assertEvent(getRealmId(), OperationType.DELETE, AdminEventPaths.clientScopeRoleMappingsRealmLevelPath(scopeId), Collections.singletonList(realmCompositeRole), ResourceType.REALM_SCOPE_MAPPING);
scopesResource.clientLevel(accountMgmtId).remove(Collections.singletonList(viewAccountRoleRep));
assertAdminEvents.assertEvent(getRealmId(), OperationType.DELETE, AdminEventPaths.clientScopeRoleMappingsClientLevelPath(scopeId, accountMgmtId), Collections.singletonList(viewAccountRoleRep), ResourceType.CLIENT_SCOPE_MAPPING);
// assert scopes are removed
allRealm = scopesResource.realmLevel().listAll();
availableRealm = scopesResource.realmLevel().listAvailable();
effectiveRealm = scopesResource.realmLevel().listEffective();
accountRoles = scopesResource.clientLevel(accountMgmtId).listAll();
assertNames(allRealm);
assertNames(availableRealm, "realm-composite", "realm-child", Constants.OFFLINE_ACCESS_ROLE, Constants.AUTHZ_UMA_AUTHORIZATION, Constants.DEFAULT_ROLES_ROLE_PREFIX + "-test");
assertNames(effectiveRealm);
assertNames(accountRoles);
// remove scope
removeClientScope(scopeId);
}
use of org.keycloak.representations.idm.ClientScopeRepresentation 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);
}
Aggregations