use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class ClientModelTest method json.
@Test
@ModelTest
public void json(KeycloakSession session) {
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionJson) -> {
currentSession = sessionJson;
RealmModel realm = currentSession.realms().getRealmByName(realmName);
client = setUpClient(realm);
ClientRepresentation representation = ModelToRepresentation.toRepresentation(client, currentSession);
representation.setId(null);
for (ProtocolMapperRepresentation protocolMapper : representation.getProtocolMappers()) {
protocolMapper.setId(null);
}
realm = currentSession.realms().createRealm("copy");
ClientModel copyClient = RepresentationToModel.createClient(currentSession, realm, representation);
assertEquals(client, copyClient);
client.unregisterNode("node1");
client.unregisterNode("10.20.30.40");
currentSession.clients().removeClient(realm, client.getId());
currentSession.clients().removeClient(realm, copyClient.getId());
currentSession.realms().removeRealm(realm.getId());
});
}
use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class AccessTokenResponseTest method addTestRealms.
@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
RealmRepresentation realm = loadJson(getClass().getResourceAsStream("/testrealm.json"), RealmRepresentation.class);
UserBuilder user = UserBuilder.create().id(KeycloakModelUtils.generateId()).username("no-permissions").addRoles("user").password("password");
realm.getUsers().add(user.build());
ProtocolMapperRepresentation customClaimHardcodedMapper = new ProtocolMapperRepresentation();
customClaimHardcodedMapper.setName("custom-claim-hardcoded-mapper");
customClaimHardcodedMapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL);
customClaimHardcodedMapper.setProtocolMapper(HardcodedClaim.PROVIDER_ID);
Map<String, String> config = new HashMap<>();
config.put(OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME, "custom_hardcoded_claim");
config.put(HardcodedClaim.CLAIM_VALUE, "custom_claim");
config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ACCESS_TOKEN_RESPONSE, "true");
customClaimHardcodedMapper.setConfig(config);
realm.getClients().stream().filter(clientRepresentation -> "test-app".equals(clientRepresentation.getClientId())).forEach(clientRepresentation -> {
clientRepresentation.setProtocolMappers(Collections.singletonList(customClaimHardcodedMapper));
clientRepresentation.setFullScopeAllowed(false);
});
testRealms.add(realm);
}
use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class ClientsPartialImport method create.
@Override
public void create(RealmModel realm, KeycloakSession session, ClientRepresentation clientRep) {
clientRep.setId(KeycloakModelUtils.generateId());
List<ProtocolMapperRepresentation> mappers = clientRep.getProtocolMappers();
if (mappers != null) {
for (ProtocolMapperRepresentation mapper : mappers) {
mapper.setId(KeycloakModelUtils.generateId());
}
}
ClientModel client = RepresentationToModel.createClient(session, realm, clientRep);
RepresentationToModel.importAuthorizationSettings(clientRep, client, session);
}
use of org.keycloak.representations.idm.ProtocolMapperRepresentation 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);
}
use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class ClientRegistrationPoliciesTest method createHardcodedMapperRep.
private ProtocolMapperRepresentation createHardcodedMapperRep() {
ProtocolMapperRepresentation protocolMapper = new ProtocolMapperRepresentation();
protocolMapper.setName("Hardcoded foo role");
protocolMapper.setProtocolMapper(HardcodedRole.PROVIDER_ID);
protocolMapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL);
protocolMapper.getConfig().put(HardcodedRole.ROLE_CONFIG, "foo-role");
return protocolMapper;
}
Aggregations