Search in sources :

Example 61 with ProtocolMapperRepresentation

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());
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) ClientModel(org.keycloak.models.ClientModel) KeycloakSession(org.keycloak.models.KeycloakSession) ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) ModelTest(org.keycloak.testsuite.arquillian.annotation.ModelTest) ModelTest(org.keycloak.testsuite.arquillian.annotation.ModelTest) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Example 62 with ProtocolMapperRepresentation

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);
}
Also used : HardcodedClaim(org.keycloak.protocol.oidc.mappers.HardcodedClaim) OIDCAttributeMapperHelper(org.keycloak.protocol.oidc.mappers.OIDCAttributeMapperHelper) AbstractAdminTest.loadJson(org.keycloak.testsuite.admin.AbstractAdminTest.loadJson) KeycloakModelUtils(org.keycloak.models.utils.KeycloakModelUtils) AssertEvents(org.keycloak.testsuite.AssertEvents) HashMap(java.util.HashMap) Test(org.junit.Test) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) OAuthClient(org.keycloak.testsuite.util.OAuthClient) List(java.util.List) Rule(org.junit.Rule) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest) UserBuilder(org.keycloak.testsuite.util.UserBuilder) Map(java.util.Map) OIDCLoginProtocol(org.keycloak.protocol.oidc.OIDCLoginProtocol) Collections(java.util.Collections) ClientManager(org.keycloak.testsuite.util.ClientManager) Assert.assertEquals(org.junit.Assert.assertEquals) OAuth2Constants(org.keycloak.OAuth2Constants) Before(org.junit.Before) HashMap(java.util.HashMap) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) UserBuilder(org.keycloak.testsuite.util.UserBuilder)

Example 63 with ProtocolMapperRepresentation

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);
}
Also used : ClientModel(org.keycloak.models.ClientModel) ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation)

Example 64 with ProtocolMapperRepresentation

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);
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) RealmResource(org.keycloak.admin.client.resource.RealmResource) ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) ClientResource(org.keycloak.admin.client.resource.ClientResource) ClientScopesResource(org.keycloak.admin.client.resource.ClientScopesResource) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation)

Example 65 with ProtocolMapperRepresentation

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;
}
Also used : ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation)

Aggregations

ProtocolMapperRepresentation (org.keycloak.representations.idm.ProtocolMapperRepresentation)107 Test (org.junit.Test)68 HashMap (java.util.HashMap)30 Response (javax.ws.rs.core.Response)30 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)27 Map (java.util.Map)23 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)20 ClientResource (org.keycloak.admin.client.resource.ClientResource)19 OAuthClient (org.keycloak.testsuite.util.OAuthClient)17 RealmResource (org.keycloak.admin.client.resource.RealmResource)14 List (java.util.List)13 ProtocolMappersResource (org.keycloak.admin.client.resource.ProtocolMappersResource)12 IDToken (org.keycloak.representations.IDToken)12 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)11 ClientScopeRepresentation (org.keycloak.representations.idm.ClientScopeRepresentation)11 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)10 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)8 ArrayList (java.util.ArrayList)7 LinkedList (java.util.LinkedList)7 AccessToken (org.keycloak.representations.AccessToken)7