use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method updateAssignedDefaultClientScopeToDynamicScope.
@Test
@EnableFeature(value = Profile.Feature.DYNAMIC_SCOPES, skipRestart = true)
public void updateAssignedDefaultClientScopeToDynamicScope() {
ClientRepresentation clientRep = new ClientRepresentation();
clientRep.setClientId("dyn-scope-client");
clientRep.setProtocol("openid-connect");
String clientUuid = createClient(clientRep);
getCleanup().addClientUuid(clientUuid);
ClientScopeRepresentation scopeRep = new ClientScopeRepresentation();
scopeRep.setName("dynamic-scope-def");
scopeRep.setProtocol("openid-connect");
String scopeDefId = createClientScope(scopeRep);
getCleanup().addClientScopeId(scopeDefId);
testRealmResource().clients().get(clientUuid).addDefaultClientScope(scopeDefId);
scopeRep.setAttributes(new HashMap<String, String>() {
{
put(ClientScopeModel.IS_DYNAMIC_SCOPE, "true");
put(ClientScopeModel.DYNAMIC_SCOPE_REGEXP, "dynamic-scope-def:*:*");
}
});
try {
clientScopes().get(scopeDefId).update(scopeRep);
Assert.fail("This update should fail");
} 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 scopesRemainAfterClientUpdate.
// KEYCLOAK-18332
@Test
public void scopesRemainAfterClientUpdate() {
// Create a bunch of 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);
// Create a client
ClientRepresentation clientRep = new ClientRepresentation();
clientRep.setClientId("bar-client");
clientRep.setProtocol("openid-connect");
String clientUuid = createClient(clientRep);
ClientResource client = testRealmResource().clients().get(clientUuid);
getCleanup().addClientUuid(clientUuid);
assertTrue(getClientScopeNames(client.getDefaultClientScopes()).contains("scope-def"));
assertTrue(getClientScopeNames(client.getOptionalClientScopes()).contains("scope-opt"));
// Remove the scopes from client
client.removeDefaultClientScope(scopeDefId);
client.removeOptionalClientScope(scopeOptId);
List<String> expectedDefScopes = getClientScopeNames(client.getDefaultClientScopes());
List<String> expectedOptScopes = getClientScopeNames(client.getOptionalClientScopes());
assertFalse(expectedDefScopes.contains("scope-def"));
assertFalse(expectedOptScopes.contains("scope-opt"));
// Update the client
clientRep = client.toRepresentation();
// Make a small change
clientRep.setDescription("desc");
client.update(clientRep);
// Assert scopes are intact
assertEquals(expectedDefScopes, getClientScopeNames(client.getDefaultClientScopes()));
assertEquals(expectedOptScopes, getClientScopeNames(client.getOptionalClientScopes()));
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method testRemoveClientScope.
@Test
public void testRemoveClientScope() {
// Create scope1
ClientScopeRepresentation scopeRep = new ClientScopeRepresentation();
scopeRep.setName("scope1");
String scope1Id = createClientScope(scopeRep);
List<ClientScopeRepresentation> clientScopes = clientScopes().findAll();
assertTrue(getClientScopeNames(clientScopes).contains("scope1"));
// Create scope2
scopeRep = new ClientScopeRepresentation();
scopeRep.setName("scope2");
String scope2Id = createClientScope(scopeRep);
clientScopes = clientScopes().findAll();
assertTrue(getClientScopeNames(clientScopes).contains("scope2"));
// Remove scope1
removeClientScope(scope1Id);
clientScopes = clientScopes().findAll();
Assert.assertFalse(getClientScopeNames(clientScopes).contains("scope1"));
assertTrue(getClientScopeNames(clientScopes).contains("scope2"));
// Remove scope2
removeClientScope(scope2Id);
clientScopes = clientScopes().findAll();
Assert.assertFalse(getClientScopeNames(clientScopes).contains("scope1"));
Assert.assertFalse(getClientScopeNames(clientScopes).contains("scope2"));
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method testCreateInvalidRegexpDynamicScope.
@Test
@EnableFeature(value = Profile.Feature.DYNAMIC_SCOPES, skipRestart = true)
public void testCreateInvalidRegexpDynamicScope() {
ClientScopeRepresentation scopeRep = new ClientScopeRepresentation();
scopeRep.setName("dynamic-scope-def4");
scopeRep.setProtocol("openid-connect");
scopeRep.setAttributes(new HashMap<String, String>() {
{
put(ClientScopeModel.IS_DYNAMIC_SCOPE, "true");
put(ClientScopeModel.DYNAMIC_SCOPE_REGEXP, "dynamic-scope-def:*:*");
}
});
handleExpectedCreateFailure(scopeRep, 400, "Invalid format for the Dynamic Scope regexp dynamic-scope-def:*:*");
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientScopeTest method defaultOptionalClientScopeCanBeAssignedToClientAsDefaultScope.
// KEYCLOAK-9999
@Test
public void defaultOptionalClientScopeCanBeAssignedToClientAsDefaultScope() {
// Create optional client scope
ClientScopeRepresentation optionalClientScope = new ClientScopeRepresentation();
optionalClientScope.setName("optional-client-scope");
optionalClientScope.setProtocol("openid-connect");
String optionalClientScopeId = createClientScope(optionalClientScope);
getCleanup().addClientScopeId(optionalClientScopeId);
testRealmResource().addDefaultOptionalClientScope(optionalClientScopeId);
assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, AdminEventPaths.defaultOptionalClientScopePath(optionalClientScopeId), ResourceType.CLIENT_SCOPE);
// Ensure that scope is optional
List<String> realmOptionalScopes = getClientScopeNames(testRealmResource().getDefaultOptionalClientScopes());
assertTrue(realmOptionalScopes.contains("optional-client-scope"));
// Create client
ClientRepresentation client = new ClientRepresentation();
client.setClientId("test-client");
client.setDefaultClientScopes(Collections.singletonList("optional-client-scope"));
String clientUuid = createClient(client);
getCleanup().addClientUuid(clientUuid);
// Ensure that default optional client scope is a default scope of the client
List<String> clientDefaultScopes = getClientScopeNames(testRealmResource().clients().get(clientUuid).getDefaultClientScopes());
assertTrue(clientDefaultScopes.contains("optional-client-scope"));
// Ensure that no optional scopes are assigned to the client, even if there are default optional scopes!
List<String> clientOptionalScopes = getClientScopeNames(testRealmResource().clients().get(clientUuid).getOptionalClientScopes());
assertTrue(clientOptionalScopes.isEmpty());
// Unassign optional client scope from realm for cleanup
testRealmResource().removeDefaultOptionalClientScope(optionalClientScopeId);
assertAdminEvents.assertEvent(getRealmId(), OperationType.DELETE, AdminEventPaths.defaultOptionalClientScopePath(optionalClientScopeId), ResourceType.CLIENT_SCOPE);
}
Aggregations