Java Code Examples for org.keycloak.representations.idm.ClientRepresentation#setRootUrl()

The following examples show how to use org.keycloak.representations.idm.ClientRepresentation#setRootUrl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Test
public void createClientValidation() {
    ClientRepresentation rep = new ClientRepresentation();
    rep.setClientId("my-app");
    rep.setDescription("my-app description");
    rep.setEnabled(true);

    rep.setRootUrl("invalid");
    createClientExpectingValidationError(rep, "Invalid URL in rootUrl");

    rep.setRootUrl(null);
    rep.setBaseUrl("invalid");
    createClientExpectingValidationError(rep, "Invalid URL in baseUrl");

    rep.setRootUrl(null);
    rep.setBaseUrl("/valid");
    createClientExpectingSuccessfulClientCreation(rep);

    rep.setRootUrl("");
    rep.setBaseUrl("/valid");
    createClientExpectingSuccessfulClientCreation(rep);
}
 
Example 2
Source File: PartialImportTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Before
public void createClientWithServiceAccount() {
    ClientRepresentation client = new ClientRepresentation();
    client.setClientId(CLIENT_SERVICE_ACCOUNT);
    client.setName(CLIENT_SERVICE_ACCOUNT);
    client.setRootUrl("http://localhost/foo");
    client.setProtocol("openid-connect");
    client.setPublicClient(false);
    client.setSecret("secret");
    client.setServiceAccountsEnabled(true);
    try (Response resp = testRealmResource().clients().create(client)) {
        String id = ApiUtil.getCreatedId(resp);
        UserRepresentation serviceAccountUser = testRealmResource().clients().get(id).getServiceAccountUser();
        assertNotNull(serviceAccountUser);
    }
}
 
Example 3
Source File: ClientRegistrationTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Test
public void registerClientValidation() throws IOException {
	authCreateClients();
	ClientRepresentation client = buildClient();
	client.setRootUrl("invalid");

	try {
        registerClient(client);
    } catch (ClientRegistrationException e) {
        HttpErrorException c = (HttpErrorException) e.getCause();
        assertEquals(400, c.getStatusLine().getStatusCode());

        OAuth2ErrorRepresentation error = JsonSerialization.readValue(c.getErrorResponse(), OAuth2ErrorRepresentation.class);

        assertEquals("invalid_client_metadata", error.getError());
        assertEquals("Invalid URL in rootUrl", error.getErrorDescription());
    }
}
 
Example 4
Source File: ClientRegistrationTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Test
public void updateClientValidation() throws IOException, ClientRegistrationException {
    registerClientAsAdmin();

    ClientRepresentation client = reg.get(CLIENT_ID);
    client.setRootUrl("invalid");

	try {
        reg.update(client);
    } catch (ClientRegistrationException e) {
        HttpErrorException c = (HttpErrorException) e.getCause();
        assertEquals(400, c.getStatusLine().getStatusCode());

        OAuth2ErrorRepresentation error = JsonSerialization.readValue(c.getErrorResponse(), OAuth2ErrorRepresentation.class);

        assertEquals("invalid_client_metadata", error.getError());
        assertEquals("Invalid URL in rootUrl", error.getErrorDescription());
    }

    ClientRepresentation updatedClient = reg.get(CLIENT_ID);
    assertNull(updatedClient.getRootUrl());
}
 
Example 5
Source File: ClientTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Test
public void updateClientValidation() {
    ClientRepresentation rep = createClient();

    rep.setClientId("my-app");
    rep.setDescription("my-app description");
    rep.setEnabled(true);

    rep.setRootUrl("invalid");
    updateClientExpectingValidationError(rep, "Invalid URL in rootUrl");

    rep.setRootUrl(null);
    rep.setBaseUrl("invalid");
    updateClientExpectingValidationError(rep, "Invalid URL in baseUrl");

    ClientRepresentation stored = realm.clients().get(rep.getId()).toRepresentation();
    assertNull(stored.getRootUrl());
    assertNull(stored.getBaseUrl());

    rep.setRootUrl(null);
    rep.setBaseUrl("/valid");
    updateClientExpectingSuccessfulClientUpdate(rep, null, "/valid");

    rep.setRootUrl("");
    rep.setBaseUrl("/valid");
    updateClientExpectingSuccessfulClientUpdate(rep, "", "/valid");
}
 
Example 6
Source File: GroupTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * KEYCLOAK-2716
 * @throws Exception
 */
@Test
public void testClientRemoveWithClientRoleGroupMapping() throws Exception {
    RealmResource realm = adminClient.realms().realm("test");

    ClientRepresentation client = new ClientRepresentation();
    client.setClientId("foo");
    client.setRootUrl("http://foo");
    client.setProtocol("openid-connect");
    Response response = realm.clients().create(client);
    response.close();
    String clientUuid = ApiUtil.getCreatedId(response);
    assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.clientResourcePath(clientUuid), client, ResourceType.CLIENT);
    client = realm.clients().findByClientId("foo").get(0);

    RoleRepresentation role = new RoleRepresentation();
    role.setName("foo-role");
    realm.clients().get(client.getId()).roles().create(role);
    assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.clientRoleResourcePath(clientUuid, "foo-role"), role, ResourceType.CLIENT_ROLE);
    role = realm.clients().get(client.getId()).roles().get("foo-role").toRepresentation();

    GroupRepresentation group = new GroupRepresentation();
    group.setName("2716");
    group = createGroup(realm, group);

    List<RoleRepresentation> list = new LinkedList<>();
    list.add(role);
    realm.groups().group(group.getId()).roles().clientLevel(client.getId()).add(list);
    assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesClientRolesPath(group.getId(), clientUuid), list, ResourceType.CLIENT_ROLE_MAPPING);

    realm.clients().get(client.getId()).remove();
    assertAdminEvents.assertEvent("test", OperationType.DELETE, AdminEventPaths.clientResourcePath(clientUuid), ResourceType.CLIENT);
}
 
Example 7
Source File: AdapterInstallationConfigTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Before
@Override
public void before() throws Exception {
    super.before();

    client = new ClientRepresentation();
    client.setEnabled(true);
    client.setClientId("RegistrationAccessTokenTest");
    client.setSecret("RegistrationAccessTokenTestClientSecret");
    client.setPublicClient(false);
    client.setRegistrationAccessToken("RegistrationAccessTokenTestRegistrationAccessToken");
    client.setRootUrl("http://root");
    client = createClient(client);
    client.setSecret("RegistrationAccessTokenTestClientSecret");
    getCleanup().addClientUuid(client.getId());

    client2 = new ClientRepresentation();
    client2.setEnabled(true);
    client2.setClientId("RegistrationAccessTokenTest2");
    client2.setSecret("RegistrationAccessTokenTestClientSecret");
    client2.setPublicClient(false);
    client2.setRegistrationAccessToken("RegistrationAccessTokenTestRegistrationAccessToken");
    client2.setRootUrl("http://root");
    client2 = createClient(client2);
    getCleanup().addClientUuid(client2.getId());

    clientPublic = new ClientRepresentation();
    clientPublic.setEnabled(true);
    clientPublic.setClientId("RegistrationAccessTokenTestPublic");
    clientPublic.setPublicClient(true);
    clientPublic.setRegistrationAccessToken("RegistrationAccessTokenTestRegistrationAccessTokenPublic");
    clientPublic.setRootUrl("http://root");
    clientPublic = createClient(clientPublic);
    getCleanup().addClientUuid(clientPublic.getId());
}