Search in sources :

Example 1 with TestAvailabilityAction

use of org.keycloak.representations.adapters.action.TestAvailabilityAction in project keycloak by keycloak.

the class PreAuthActionsHandler method handleTestAvailable.

protected void handleTestAvailable() {
    if (log.isTraceEnabled()) {
        log.trace("K_TEST_AVAILABLE sent");
    }
    try {
        JWSInput token = verifyAdminRequest();
        if (token == null) {
            return;
        }
        TestAvailabilityAction action = JsonSerialization.readValue(token.getContent(), TestAvailabilityAction.class);
        validateAction(action);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : JWSInput(org.keycloak.jose.jws.JWSInput) TestAvailabilityAction(org.keycloak.representations.adapters.action.TestAvailabilityAction) VerificationException(org.keycloak.common.VerificationException)

Example 2 with TestAvailabilityAction

use of org.keycloak.representations.adapters.action.TestAvailabilityAction in project keycloak by keycloak.

the class ClientTest method nodes.

@Test
public void nodes() {
    testingClient.testApp().clearAdminActions();
    ClientRepresentation client = createAppClient();
    String id = client.getId();
    String myhost = suiteContext.getAuthServerInfo().getContextRoot().getHost();
    realm.clients().get(id).registerNode(Collections.singletonMap("node", myhost));
    realm.clients().get(id).registerNode(Collections.singletonMap("node", "invalid"));
    assertAdminEvents.assertEvent(realmId, OperationType.CREATE, AdminEventPaths.clientNodePath(id, myhost), ResourceType.CLUSTER_NODE);
    assertAdminEvents.assertEvent(realmId, OperationType.CREATE, AdminEventPaths.clientNodePath(id, "invalid"), ResourceType.CLUSTER_NODE);
    GlobalRequestResult result = realm.clients().get(id).testNodesAvailable();
    assertEquals(1, result.getSuccessRequests().size());
    assertEquals(1, result.getFailedRequests().size());
    assertAdminEvents.assertEvent(realmId, OperationType.ACTION, AdminEventPaths.clientTestNodesAvailablePath(id), result, ResourceType.CLUSTER_NODE);
    TestAvailabilityAction testAvailable = testingClient.testApp().getTestAvailable();
    assertEquals("test-app", testAvailable.getResource());
    assertEquals(2, realm.clients().get(id).toRepresentation().getRegisteredNodes().size());
    realm.clients().get(id).unregisterNode("invalid");
    assertAdminEvents.assertEvent(realmId, OperationType.DELETE, AdminEventPaths.clientNodePath(id, "invalid"), ResourceType.CLUSTER_NODE);
    assertEquals(1, realm.clients().get(id).toRepresentation().getRegisteredNodes().size());
}
Also used : GlobalRequestResult(org.keycloak.representations.adapters.action.GlobalRequestResult) TestAvailabilityAction(org.keycloak.representations.adapters.action.TestAvailabilityAction) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 3 with TestAvailabilityAction

use of org.keycloak.representations.adapters.action.TestAvailabilityAction in project keycloak by keycloak.

the class ResourceAdminManager method sendTestNodeAvailabilityRequest.

protected boolean sendTestNodeAvailabilityRequest(RealmModel realm, ClientModel client, String managementUrl) {
    TestAvailabilityAction adminAction = new TestAvailabilityAction(TokenIdGenerator.generateId(), Time.currentTime() + 30, client.getClientId());
    String token = session.tokens().encode(adminAction);
    logger.debugv("testNodes availability resource: {0} url: {1}", client.getClientId(), managementUrl);
    URI target = UriBuilder.fromUri(managementUrl).path(AdapterConstants.K_TEST_AVAILABLE).build();
    try {
        int status = session.getProvider(HttpClientProvider.class).postText(target.toString(), token);
        boolean success = status == 204 || status == 200;
        logger.debugf("testAvailability success for %s: %s", managementUrl, success);
        return success;
    } catch (IOException e) {
        ServicesLogger.LOGGER.availabilityTestFailed(managementUrl);
        return false;
    }
}
Also used : HttpClientProvider(org.keycloak.connections.httpclient.HttpClientProvider) IOException(java.io.IOException) URI(java.net.URI) TestAvailabilityAction(org.keycloak.representations.adapters.action.TestAvailabilityAction)

Aggregations

TestAvailabilityAction (org.keycloak.representations.adapters.action.TestAvailabilityAction)3 IOException (java.io.IOException)1 URI (java.net.URI)1 Test (org.junit.Test)1 VerificationException (org.keycloak.common.VerificationException)1 HttpClientProvider (org.keycloak.connections.httpclient.HttpClientProvider)1 JWSInput (org.keycloak.jose.jws.JWSInput)1 GlobalRequestResult (org.keycloak.representations.adapters.action.GlobalRequestResult)1 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)1