use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class PermissionsTest method clientScopes.
@Test
public void clientScopes() {
invoke((RealmResource realm) -> {
realm.clientScopes().findAll();
}, Resource.CLIENT, false, true);
invoke((RealmResource realm, AtomicReference<Response> response) -> {
ClientScopeRepresentation scope = new ClientScopeRepresentation();
scope.setName("scope");
response.set(realm.clientScopes().create(scope));
}, Resource.CLIENT, true);
ClientScopeRepresentation scope = adminClient.realms().realm(REALM_NAME).clientScopes().findAll().get(0);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).toRepresentation();
}, Resource.CLIENT, false);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).update(scope);
}, Resource.CLIENT, true);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).remove();
realm.clientScopes().create(scope);
}, Resource.CLIENT, true);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getProtocolMappers().getMappers();
}, Resource.CLIENT, false, true);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getProtocolMappers().getMappersPerProtocol("nosuch");
}, Resource.CLIENT, false, true);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getProtocolMappers().getMapperById("nosuch");
}, Resource.CLIENT, false, true);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getProtocolMappers().update("nosuch", new ProtocolMapperRepresentation());
}, Resource.CLIENT, true);
invoke((RealmResource realm, AtomicReference<Response> response) -> {
response.set(realm.clientScopes().get(scope.getId()).getProtocolMappers().createMapper(new ProtocolMapperRepresentation()));
}, Resource.CLIENT, true);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getProtocolMappers().createMapper(Collections.<ProtocolMapperRepresentation>emptyList());
}, Resource.CLIENT, true);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getProtocolMappers().delete("nosuch");
}, Resource.CLIENT, true);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getScopeMappings().getAll();
}, Resource.CLIENT, false);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getScopeMappings().realmLevel().listAll();
}, Resource.CLIENT, false);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getScopeMappings().realmLevel().listAvailable();
}, Resource.CLIENT, false);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getScopeMappings().realmLevel().listEffective();
}, Resource.CLIENT, false);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getScopeMappings().realmLevel().add(Collections.<RoleRepresentation>emptyList());
}, Resource.CLIENT, true);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getScopeMappings().realmLevel().remove(Collections.<RoleRepresentation>emptyList());
}, Resource.CLIENT, true);
ClientRepresentation realmAccessClient = adminClient.realms().realm(REALM_NAME).clients().findByClientId(Constants.REALM_MANAGEMENT_CLIENT_ID).get(0);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getScopeMappings().clientLevel(realmAccessClient.getId()).listAll();
}, Resource.CLIENT, false);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getScopeMappings().clientLevel(realmAccessClient.getId()).listAvailable();
}, Resource.CLIENT, false);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getScopeMappings().clientLevel(realmAccessClient.getId()).listEffective();
}, Resource.CLIENT, false);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getScopeMappings().clientLevel(realmAccessClient.getId()).add(Collections.<RoleRepresentation>emptyList());
}, Resource.CLIENT, true);
invoke((RealmResource realm) -> {
realm.clientScopes().get(scope.getId()).getScopeMappings().clientLevel(realmAccessClient.getId()).remove(Collections.<RoleRepresentation>emptyList());
}, Resource.CLIENT, true);
// this should throw forbidden as "query-users" role isn't enough
invoke(new Invocation() {
public void invoke(RealmResource realm) {
clients.get(AdminRoles.QUERY_USERS).realm(REALM_NAME).clientScopes().findAll();
}
}, clients.get(AdminRoles.QUERY_USERS), false);
}
use of org.keycloak.representations.idm.ClientScopeRepresentation 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.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class LoginTest method loginSuccessfulWithDynamicScope.
@Test
@EnableFeature(value = Profile.Feature.DYNAMIC_SCOPES, skipRestart = true)
public void loginSuccessfulWithDynamicScope() {
ProfileAssume.assumeFeatureEnabled(DYNAMIC_SCOPES);
ClientScopeRepresentation clientScope = new ClientScopeRepresentation();
clientScope.setName("dynamic");
clientScope.setAttributes(new HashMap<String, String>() {
{
put(ClientScopeModel.IS_DYNAMIC_SCOPE, "true");
put(ClientScopeModel.DYNAMIC_SCOPE_REGEXP, "dynamic:*");
}
});
clientScope.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL);
Response response = testRealm().clientScopes().create(clientScope);
String scopeId = ApiUtil.getCreatedId(response);
getCleanup().addClientScopeId(scopeId);
response.close();
ClientResource testApp = ApiUtil.findClientByClientId(testRealm(), "test-app");
ClientRepresentation testAppRep = testApp.toRepresentation();
testApp.update(testAppRep);
testApp.addOptionalClientScope(scopeId);
oauth.scope("dynamic:scope");
oauth.doLogin("login@test.com", "password");
events.expectLogin().user(userId).assertEvent();
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class ClientResource method toRepresentation.
private static ClientScopeRepresentation toRepresentation(ClientScopeModel clientScopeModel) {
ClientScopeRepresentation rep = new ClientScopeRepresentation();
rep.setId(clientScopeModel.getId());
rep.setName(clientScopeModel.getName());
return rep;
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class AccountRestServiceTest method updateConsentForClient.
@Test
public void updateConsentForClient() throws IOException {
TokenUtil token = new TokenUtil("manage-consent-access", "password");
String appId = "security-admin-console";
ClientScopeRepresentation clientScopeRepresentation = testRealm().clientScopes().findAll().get(0);
ConsentScopeRepresentation consentScopeRepresentation = new ConsentScopeRepresentation();
consentScopeRepresentation.setId(clientScopeRepresentation.getId());
ConsentRepresentation requestedConsent = new ConsentRepresentation();
requestedConsent.setGrantedScopes(Collections.singletonList(consentScopeRepresentation));
ConsentRepresentation consentRepresentation = SimpleHttp.doPost(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asJson(ConsentRepresentation.class);
assertTrue(consentRepresentation.getCreatedDate() > 0);
assertTrue(consentRepresentation.getLastUpdatedDate() > 0);
assertEquals(1, consentRepresentation.getGrantedScopes().size());
assertEquals(consentScopeRepresentation.getId(), consentRepresentation.getGrantedScopes().get(0).getId());
clientScopeRepresentation = testRealm().clientScopes().findAll().get(1);
consentScopeRepresentation = new ConsentScopeRepresentation();
consentScopeRepresentation.setId(clientScopeRepresentation.getId());
requestedConsent = new ConsentRepresentation();
requestedConsent.setGrantedScopes(Collections.singletonList(consentScopeRepresentation));
ConsentRepresentation consentRepresentation2 = SimpleHttp.doPost(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asJson(ConsentRepresentation.class);
assertTrue(consentRepresentation2.getCreatedDate() > 0);
assertEquals(consentRepresentation.getCreatedDate(), consentRepresentation2.getCreatedDate());
assertTrue(consentRepresentation2.getLastUpdatedDate() > 0);
assertTrue(consentRepresentation2.getLastUpdatedDate() > consentRepresentation.getLastUpdatedDate());
assertEquals(1, consentRepresentation2.getGrantedScopes().size());
assertEquals(consentScopeRepresentation.getId(), consentRepresentation2.getGrantedScopes().get(0).getId());
}
Aggregations