use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method updateClientWithDefaultScopeAssignedAsOptionalAndOpposite.
@Test
public void updateClientWithDefaultScopeAssignedAsOptionalAndOpposite() {
// create client
ClientRepresentation clientRep = new ClientRepresentation();
clientRep.setClientId("bar-client");
clientRep.setProtocol("openid-connect");
String clientUuid = createClient(clientRep);
getCleanup().addClientUuid(clientUuid);
// Create 2 client scopes
ClientScopeRepresentation scopeRep = new ClientScopeRepresentation();
scopeRep.setName("scope-def");
scopeRep.setProtocol("openid-connect");
String scopeDefId = createClientScope(scopeRep);
getCleanup().addClientScopeId(scopeDefId);
scopeRep = new ClientScopeRepresentation();
scopeRep.setName("scope-opt");
scopeRep.setProtocol("openid-connect");
String scopeOptId = createClientScope(scopeRep);
getCleanup().addClientScopeId(scopeOptId);
// assign "scope-def" as optional client scope to client
testRealmResource().clients().get(clientUuid).addOptionalClientScope(scopeDefId);
// assign "scope-opt" as default client scope to client
testRealmResource().clients().get(clientUuid).addDefaultClientScope(scopeOptId);
// Add scope-def as default and scope-opt as optional client scope within the realm
testRealmResource().addDefaultDefaultClientScope(scopeDefId);
testRealmResource().addDefaultOptionalClientScope(scopeOptId);
// update client - check it passes (it used to throw ModelDuplicateException before)
clientRep.setDescription("new_description");
testRealmResource().clients().get(clientUuid).update(clientRep);
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method testRemoveClientScopeInUse.
@Test
public void testRemoveClientScopeInUse() {
// Add client scope
ClientScopeRepresentation scopeRep = new ClientScopeRepresentation();
scopeRep.setName("foo-scope");
scopeRep.setProtocol("openid-connect");
String scopeId = createClientScope(scopeRep);
// Add client with the clientScope
ClientRepresentation clientRep = new ClientRepresentation();
clientRep.setClientId("bar-client");
clientRep.setName("bar-client");
clientRep.setProtocol("openid-connect");
clientRep.setDefaultClientScopes(Collections.singletonList("foo-scope"));
String clientDbId = createClient(clientRep);
removeClientScope(scopeId);
removeClient(clientDbId);
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method testRealmDefaultClientScopes.
@Test
public void testRealmDefaultClientScopes() {
// Create 2 client scopes
ClientScopeRepresentation scopeRep = new ClientScopeRepresentation();
scopeRep.setName("scope-def");
scopeRep.setProtocol("openid-connect");
String scopeDefId = createClientScope(scopeRep);
getCleanup().addClientScopeId(scopeDefId);
scopeRep = new ClientScopeRepresentation();
scopeRep.setName("scope-opt");
scopeRep.setProtocol("openid-connect");
String scopeOptId = createClientScope(scopeRep);
getCleanup().addClientScopeId(scopeOptId);
// Add scope-def as default and scope-opt as optional client scope
testRealmResource().addDefaultDefaultClientScope(scopeDefId);
assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, AdminEventPaths.defaultDefaultClientScopePath(scopeDefId), ResourceType.CLIENT_SCOPE);
testRealmResource().addDefaultOptionalClientScope(scopeOptId);
assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, AdminEventPaths.defaultOptionalClientScopePath(scopeOptId), ResourceType.CLIENT_SCOPE);
// Ensure defaults and optional scopes are here
List<String> realmDefaultScopes = getClientScopeNames(testRealmResource().getDefaultDefaultClientScopes());
List<String> realmOptionalScopes = getClientScopeNames(testRealmResource().getDefaultOptionalClientScopes());
assertTrue(realmDefaultScopes.contains("scope-def"));
Assert.assertFalse(realmOptionalScopes.contains("scope-def"));
Assert.assertFalse(realmDefaultScopes.contains("scope-opt"));
assertTrue(realmOptionalScopes.contains("scope-opt"));
// create client. Ensure that it has scope-def and scope-opt scopes assigned
ClientRepresentation clientRep = new ClientRepresentation();
clientRep.setClientId("bar-client");
clientRep.setProtocol("openid-connect");
String clientUuid = createClient(clientRep);
getCleanup().addClientUuid(clientUuid);
List<String> clientDefaultScopes = getClientScopeNames(testRealmResource().clients().get(clientUuid).getDefaultClientScopes());
List<String> clientOptionalScopes = getClientScopeNames(testRealmResource().clients().get(clientUuid).getOptionalClientScopes());
assertTrue(clientDefaultScopes.contains("scope-def"));
Assert.assertFalse(clientOptionalScopes.contains("scope-def"));
Assert.assertFalse(clientDefaultScopes.contains("scope-opt"));
assertTrue(clientOptionalScopes.contains("scope-opt"));
// Unassign scope-def and scope-opt from realm
testRealmResource().removeDefaultDefaultClientScope(scopeDefId);
assertAdminEvents.assertEvent(getRealmId(), OperationType.DELETE, AdminEventPaths.defaultDefaultClientScopePath(scopeDefId), ResourceType.CLIENT_SCOPE);
testRealmResource().removeDefaultOptionalClientScope(scopeOptId);
assertAdminEvents.assertEvent(getRealmId(), OperationType.DELETE, AdminEventPaths.defaultOptionalClientScopePath(scopeOptId), ResourceType.CLIENT_SCOPE);
realmDefaultScopes = getClientScopeNames(testRealmResource().getDefaultDefaultClientScopes());
realmOptionalScopes = getClientScopeNames(testRealmResource().getDefaultOptionalClientScopes());
Assert.assertFalse(realmDefaultScopes.contains("scope-def"));
Assert.assertFalse(realmOptionalScopes.contains("scope-def"));
Assert.assertFalse(realmDefaultScopes.contains("scope-opt"));
Assert.assertFalse(realmOptionalScopes.contains("scope-opt"));
// Create another client. Check it doesn't have scope-def and scope-opt scopes assigned
clientRep = new ClientRepresentation();
clientRep.setClientId("bar-client-2");
clientRep.setProtocol("openid-connect");
clientUuid = createClient(clientRep);
getCleanup().addClientUuid(clientUuid);
clientDefaultScopes = getClientScopeNames(testRealmResource().clients().get(clientUuid).getDefaultClientScopes());
clientOptionalScopes = getClientScopeNames(testRealmResource().clients().get(clientUuid).getOptionalClientScopes());
Assert.assertFalse(clientDefaultScopes.contains("scope-def"));
Assert.assertFalse(clientOptionalScopes.contains("scope-def"));
Assert.assertFalse(clientDefaultScopes.contains("scope-opt"));
Assert.assertFalse(clientOptionalScopes.contains("scope-opt"));
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method dynamicClientScopeCannotBeAssignedAsDefaultClientScope.
@Test
@EnableFeature(value = Profile.Feature.DYNAMIC_SCOPES, skipRestart = true)
public void dynamicClientScopeCannotBeAssignedAsDefaultClientScope() {
ClientRepresentation clientRep = new ClientRepresentation();
clientRep.setClientId("dyn-scope-client");
clientRep.setProtocol("openid-connect");
String clientUuid = createClient(clientRep);
getCleanup().addClientUuid(clientUuid);
ClientScopeRepresentation optionalClientScope = new ClientScopeRepresentation();
optionalClientScope.setName("optional-dynamic-client-scope");
optionalClientScope.setProtocol("openid-connect");
optionalClientScope.setAttributes(new HashMap<String, String>() {
{
put(ClientScopeModel.IS_DYNAMIC_SCOPE, "true");
put(ClientScopeModel.DYNAMIC_SCOPE_REGEXP, "dynamic-scope-def:*");
}
});
String optionalClientScopeId = createClientScope(optionalClientScope);
getCleanup().addClientScopeId(optionalClientScopeId);
try {
ClientResource clientResource = testRealmResource().clients().get(clientUuid);
clientResource.addDefaultClientScope(optionalClientScopeId);
Assert.fail("A Dynamic Scope shouldn't not be assigned as a default scope to a client");
} catch (ClientErrorException ex) {
MatcherAssert.assertThat(ex.getResponse(), Matchers.statusCodeIs(Status.BAD_REQUEST));
}
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method testCreateValidDynamicScope.
@Test
@EnableFeature(value = Profile.Feature.DYNAMIC_SCOPES, skipRestart = true)
public void testCreateValidDynamicScope() {
ClientScopeRepresentation scopeRep = new ClientScopeRepresentation();
scopeRep.setName("dynamic-scope-def");
scopeRep.setProtocol("openid-connect");
scopeRep.setAttributes(new HashMap<String, String>() {
{
put(ClientScopeModel.IS_DYNAMIC_SCOPE, "true");
put(ClientScopeModel.DYNAMIC_SCOPE_REGEXP, "dynamic-scope-def:*");
}
});
String scopeDefId = createClientScope(scopeRep);
getCleanup().addClientScopeId(scopeDefId);
// Assert updated attributes
scopeRep = clientScopes().get(scopeDefId).toRepresentation();
assertEquals("dynamic-scope-def", scopeRep.getName());
assertEquals("true", scopeRep.getAttributes().get(ClientScopeModel.IS_DYNAMIC_SCOPE));
assertEquals("dynamic-scope-def:*", scopeRep.getAttributes().get(ClientScopeModel.DYNAMIC_SCOPE_REGEXP));
}
Aggregations