use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class RepresentationToModel method createClientScopes.
// CLIENT SCOPES
private static Map<String, ClientScopeModel> createClientScopes(KeycloakSession session, List<ClientScopeRepresentation> clientScopes, RealmModel realm) {
Map<String, ClientScopeModel> appMap = new HashMap<>();
for (ClientScopeRepresentation resourceRep : clientScopes) {
ClientScopeModel app = createClientScope(session, realm, resourceRep);
appMap.put(app.getName(), app);
}
return appMap;
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class RepresentationToModel method convertDeprecatedClientTemplates.
private static void convertDeprecatedClientTemplates(RealmRepresentation realm) {
if (realm.getClientTemplates() != null) {
logger.warnf("Using deprecated 'clientTemplates' configuration in JSON representation for realm '%s'. It will be removed in future versions", realm.getRealm());
List<ClientScopeRepresentation> clientScopes = new LinkedList<>();
for (ClientTemplateRepresentation template : realm.getClientTemplates()) {
ClientScopeRepresentation scopeRep = new ClientScopeRepresentation();
scopeRep.setId(template.getId());
scopeRep.setName(template.getName());
scopeRep.setProtocol(template.getProtocol());
scopeRep.setDescription(template.getDescription());
scopeRep.setAttributes(template.getAttributes());
scopeRep.setProtocolMappers(template.getProtocolMappers());
clientScopes.add(scopeRep);
}
realm.setClientScopes(clientScopes);
}
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class AudienceProtocolMappersTest method testAudienceResolveNoFullScopeClientScopes.
@Test
public void testAudienceResolveNoFullScopeClientScopes() throws Exception {
// create the mapper using a client scope
ClientScopeRepresentation clientScope = new ClientScopeRepresentation();
clientScope.setName("audience-mapper-test-client-scope");
clientScope.setProtocol("saml");
clientScope.setProtocolMappers(Collections.singletonList(createSamlProtocolMapper(SAMLAudienceResolveProtocolMapper.PROVIDER_ID)));
Response res = adminClient.realm(REALM_NAME).clientScopes().create(clientScope);
Assert.assertEquals(Response.Status.CREATED.getStatusCode(), res.getStatus());
String clientScopeId = ApiUtil.getCreatedId(res);
try {
// add a mapping to the client scope to employee2.employee role (this way employee should be in the audience)
String employee2Id = adminClient.realm(REALM_NAME).clients().findByClientId("http://localhost:8280/employee2/").get(0).getId();
Assert.assertNotNull(employee2Id);
String employeeId = adminClient.realm(REALM_NAME).clients().findByClientId("http://localhost:8280/employee/").get(0).getId();
Assert.assertNotNull(employeeId);
List<RoleRepresentation> availables = adminClient.realm(REALM_NAME).clientScopes().get(clientScopeId).getScopeMappings().clientLevel(employeeId).listAvailable();
Assert.assertThat(availables.size(), greaterThan(0));
adminClient.realm(REALM_NAME).clientScopes().get(clientScopeId).getScopeMappings().clientLevel(employeeId).add(availables);
// remove full scope and add the client scope
try (ClientAttributeUpdater cau = ClientAttributeUpdater.forClient(adminClient, REALM_NAME, SAML_CLIENT_ID_EMPLOYEE_2).setFullScopeAllowed(false).addDefaultClientScope("audience-mapper-test-client-scope").update()) {
this.testExpectedAudiences(SAML_CLIENT_ID_EMPLOYEE_2, "http://localhost:8280/employee/");
}
} finally {
adminClient.realm(REALM_NAME).clientScopes().get(clientScopeId).remove();
}
}
use of org.keycloak.representations.idm.ClientScopeRepresentation 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);
}
use of org.keycloak.representations.idm.ClientScopeRepresentation in project keycloak by keycloak.
the class DynamicScopesRARParseTest method generatedAuthorizationRequestsShouldMatchRequestedDynamicAndDefaultScopes.
@Test
public void generatedAuthorizationRequestsShouldMatchRequestedDynamicAndDefaultScopes() {
Response response = createScope("dynamic-scope", true);
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);
List<ClientScopeRepresentation> defScopes = testApp.getDefaultClientScopes();
oauth.openLoginForm();
oauth.scope("openid dynamic-scope:param");
oauth.doLogin("rar-test", "password");
events.expectLogin().user(userId).assertEvent();
AuthorizationRequestContextHolder contextHolder = fetchAuthorizationRequestContextHolder(userId);
List<AuthorizationRequestContextHolder.AuthorizationRequestHolder> authorizationRequestHolders = contextHolder.getAuthorizationRequestHolders().stream().filter(authorizationRequestHolder -> authorizationRequestHolder.getSource().equals(AuthorizationRequestSource.SCOPE)).collect(Collectors.toList());
assertEquals(defScopes.size(), authorizationRequestHolders.size() - 1);
Assert.assertFalse(authorizationRequestHolders.stream().map(AuthorizationRequestContextHolder.AuthorizationRequestHolder::getAuthorizationDetails).allMatch(rep -> rep.getType().equalsIgnoreCase(AuthorizationDetailsJSONRepresentation.STATIC_SCOPE_RAR_TYPE)));
Optional<AuthorizationRequestContextHolder.AuthorizationRequestHolder> authorizationRequestContextHolderOpt = authorizationRequestHolders.stream().filter(authorizationRequestHolder -> authorizationRequestHolder.getAuthorizationDetails().getType().equalsIgnoreCase(AuthorizationDetailsJSONRepresentation.DYNAMIC_SCOPE_RAR_TYPE)).findAny();
Assert.assertTrue(authorizationRequestContextHolderOpt.isPresent());
AuthorizationRequestContextHolder.AuthorizationRequestHolder authorizationRequestHolder = authorizationRequestContextHolderOpt.get();
Assert.assertTrue(authorizationRequestHolder.getAuthorizationDetails().getScopeNameFromCustomData().equalsIgnoreCase("dynamic-scope:param"));
Assert.assertTrue(authorizationRequestHolder.getAuthorizationDetails().getCustomData().get("scope_parameter").equals("param"));
testApp.removeOptionalClientScope(scopeId);
}
Aggregations