Search in sources :

Example 6 with ClientInitialAccessCreatePresentation

use of org.keycloak.representations.idm.ClientInitialAccessCreatePresentation in project keycloak by keycloak.

the class TestsHelper method generateInitialAccessToken.

private static void generateInitialAccessToken(Keycloak keycloak) {
    ClientInitialAccessCreatePresentation rep = new ClientInitialAccessCreatePresentation();
    rep.setCount(initialAccessTokenCount);
    rep.setExpiration(100);
    ClientInitialAccessPresentation initialAccess = keycloak.realms().realm(testRealm).clientInitialAccess().create(rep);
    initialAccessCode = initialAccess.getToken();
}
Also used : ClientInitialAccessCreatePresentation(org.keycloak.representations.idm.ClientInitialAccessCreatePresentation) ClientInitialAccessPresentation(org.keycloak.representations.idm.ClientInitialAccessPresentation)

Example 7 with ClientInitialAccessCreatePresentation

use of org.keycloak.representations.idm.ClientInitialAccessCreatePresentation in project keycloak by keycloak.

the class DefaultHostnameTest method assertInitialAccessTokenFromMasterRealm.

private void assertInitialAccessTokenFromMasterRealm(Keycloak testAdminClient, String realm, String expectedBaseUrl) throws JWSInputException, ClientRegistrationException {
    ClientInitialAccessCreatePresentation rep = new ClientInitialAccessCreatePresentation();
    rep.setCount(1);
    rep.setExpiration(10000);
    ClientInitialAccessPresentation initialAccess = testAdminClient.realm(realm).clientInitialAccess().create(rep);
    JsonWebToken token = new JWSInput(initialAccess.getToken()).readJsonContent(JsonWebToken.class);
    assertEquals(expectedBaseUrl + "/realms/" + realm, token.getIssuer());
    ClientRegistration clientReg = ClientRegistration.create().url(AUTH_SERVER_ROOT, realm).build();
    clientReg.auth(Auth.token(initialAccess.getToken()));
    ClientRepresentation client = new ClientRepresentation();
    client.setEnabled(true);
    ClientRepresentation response = clientReg.create(client);
    String registrationAccessToken = response.getRegistrationAccessToken();
    JsonWebToken registrationToken = new JWSInput(registrationAccessToken).readJsonContent(JsonWebToken.class);
    assertEquals(expectedBaseUrl + "/realms/" + realm, registrationToken.getIssuer());
}
Also used : ClientRegistration(org.keycloak.client.registration.ClientRegistration) ClientInitialAccessCreatePresentation(org.keycloak.representations.idm.ClientInitialAccessCreatePresentation) JWSInput(org.keycloak.jose.jws.JWSInput) ClientInitialAccessPresentation(org.keycloak.representations.idm.ClientInitialAccessPresentation) JsonWebToken(org.keycloak.representations.JsonWebToken) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation)

Example 8 with ClientInitialAccessCreatePresentation

use of org.keycloak.representations.idm.ClientInitialAccessCreatePresentation in project keycloak by keycloak.

the class FixedHostnameTest method assertInitialAccessTokenFromMasterRealm.

private void assertInitialAccessTokenFromMasterRealm(Keycloak testAdminClient, String realm, String expectedBaseUrl) throws JWSInputException, ClientRegistrationException {
    ClientInitialAccessCreatePresentation rep = new ClientInitialAccessCreatePresentation();
    rep.setCount(1);
    rep.setExpiration(10000);
    ClientInitialAccessPresentation initialAccess = testAdminClient.realm(realm).clientInitialAccess().create(rep);
    JsonWebToken token = new JWSInput(initialAccess.getToken()).readJsonContent(JsonWebToken.class);
    assertEquals(expectedBaseUrl + "/auth/realms/" + realm, token.getIssuer());
    ClientRegistration clientReg = ClientRegistration.create().url(authServerUrl, realm).build();
    clientReg.auth(Auth.token(initialAccess.getToken()));
    ClientRepresentation client = new ClientRepresentation();
    client.setEnabled(true);
    ClientRepresentation response = clientReg.create(client);
    String registrationAccessToken = response.getRegistrationAccessToken();
    JsonWebToken registrationToken = new JWSInput(registrationAccessToken).readJsonContent(JsonWebToken.class);
    assertEquals(expectedBaseUrl + "/auth/realms/" + realm, registrationToken.getIssuer());
}
Also used : ClientRegistration(org.keycloak.client.registration.ClientRegistration) ClientInitialAccessCreatePresentation(org.keycloak.representations.idm.ClientInitialAccessCreatePresentation) JWSInput(org.keycloak.jose.jws.JWSInput) ClientInitialAccessPresentation(org.keycloak.representations.idm.ClientInitialAccessPresentation) JsonWebToken(org.keycloak.representations.JsonWebToken) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation)

Example 9 with ClientInitialAccessCreatePresentation

use of org.keycloak.representations.idm.ClientInitialAccessCreatePresentation in project keycloak by keycloak.

the class ClientRegistrationPoliciesTest method testProtocolMappersCreate.

// PROTOCOL MAPPERS
@Test
// We would need to do domain name -> ip address to set trusted host
@AuthServerContainerExclude(AuthServer.REMOTE)
public void testProtocolMappersCreate() throws Exception {
    setTrustedHost("localhost");
    // Try to add client with some "hardcoded role" mapper. Should fail
    ClientRepresentation clientRep = createRep("test-app");
    clientRep.setProtocolMappers(Collections.singletonList(createHardcodedMapperRep()));
    assertFail(ClientRegOp.CREATE, clientRep, 403, "ProtocolMapper type not allowed");
    // Try the same authenticated. Should still fail.
    ClientInitialAccessPresentation token = adminClient.realm(REALM_NAME).clientInitialAccess().create(new ClientInitialAccessCreatePresentation(0, 10));
    reg.auth(Auth.token(token));
    assertFail(ClientRegOp.CREATE, clientRep, 403, "ProtocolMapper type not allowed");
    // Update the "authenticated" policy and allow hardcoded role mapper
    ComponentRepresentation protocolMapperPolicyRep = findPolicyByProviderAndAuth(ProtocolMappersClientRegistrationPolicyFactory.PROVIDER_ID, getPolicyAuth());
    protocolMapperPolicyRep.getConfig().add(ProtocolMappersClientRegistrationPolicyFactory.ALLOWED_PROTOCOL_MAPPER_TYPES, HardcodedRole.PROVIDER_ID);
    realmResource().components().component(protocolMapperPolicyRep.getId()).update(protocolMapperPolicyRep);
    // Check authenticated registration is permitted
    ClientRepresentation registeredClient = reg.create(clientRep);
    Assert.assertNotNull(registeredClient.getRegistrationAccessToken());
    // Check "anonymous" registration still fails
    clientRep = createRep("test-app-2");
    clientRep.setProtocolMappers(Collections.singletonList(createHardcodedMapperRep()));
    reg.auth(null);
    assertFail(ClientRegOp.CREATE, clientRep, 403, "ProtocolMapper type not allowed");
    // Revert policy change
    ApiUtil.findClientResourceByClientId(realmResource(), "test-app").remove();
    protocolMapperPolicyRep.getConfig().remove(ProtocolMappersClientRegistrationPolicyFactory.ALLOWED_PROTOCOL_MAPPER_TYPES, HardcodedRole.PROVIDER_ID);
    realmResource().components().component(protocolMapperPolicyRep.getId()).update(protocolMapperPolicyRep);
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) ClientInitialAccessCreatePresentation(org.keycloak.representations.idm.ClientInitialAccessCreatePresentation) ClientInitialAccessPresentation(org.keycloak.representations.idm.ClientInitialAccessPresentation) OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test)

Example 10 with ClientInitialAccessCreatePresentation

use of org.keycloak.representations.idm.ClientInitialAccessCreatePresentation in project keycloak by keycloak.

the class OIDCPairwiseClientRegistrationTest method before.

@Before
public void before() throws Exception {
    super.before();
    ClientInitialAccessPresentation token = adminClient.realm(REALM_NAME).clientInitialAccess().create(new ClientInitialAccessCreatePresentation(0, 10));
    reg.auth(Auth.token(token));
}
Also used : ClientInitialAccessCreatePresentation(org.keycloak.representations.idm.ClientInitialAccessCreatePresentation) ClientInitialAccessPresentation(org.keycloak.representations.idm.ClientInitialAccessPresentation) Before(org.junit.Before)

Aggregations

ClientInitialAccessCreatePresentation (org.keycloak.representations.idm.ClientInitialAccessCreatePresentation)20 ClientInitialAccessPresentation (org.keycloak.representations.idm.ClientInitialAccessPresentation)20 Test (org.junit.Test)9 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)9 ClientRegistrationException (org.keycloak.client.registration.ClientRegistrationException)6 Before (org.junit.Before)5 ClientRegistration (org.keycloak.client.registration.ClientRegistration)3 JWSInput (org.keycloak.jose.jws.JWSInput)3 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)3 ClientInitialAccessResource (org.keycloak.admin.client.resource.ClientInitialAccessResource)2 JsonWebToken (org.keycloak.representations.JsonWebToken)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 CoreMatchers.allOf (org.hamcrest.CoreMatchers.allOf)1 Matchers.greaterThanOrEqualTo (org.hamcrest.Matchers.greaterThanOrEqualTo)1 Matchers.lessThanOrEqualTo (org.hamcrest.Matchers.lessThanOrEqualTo)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertNull (org.junit.Assert.assertNull)1 Assert.assertThat (org.junit.Assert.assertThat)1