Search in sources :

Example 1 with GlobalRequestResult

use of org.keycloak.representations.adapters.action.GlobalRequestResult 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 2 with GlobalRequestResult

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

the class ResourceAdminManager method logoutAll.

// Methods for logout all
public GlobalRequestResult logoutAll(RealmModel realm) {
    realm.setNotBefore(Time.currentTime());
    GlobalRequestResult finalResult = new GlobalRequestResult();
    AtomicInteger counter = new AtomicInteger(0);
    realm.getClientsStream().forEach(c -> {
        try {
            counter.getAndIncrement();
            GlobalRequestResult currentResult = logoutClient(realm, c, realm.getNotBefore());
            finalResult.addAll(currentResult);
        } catch (ModelIllegalStateException ex) {
            // currently, GlobalRequestResult doesn't allow for information about clients that we were unable to retrieve.
            logger.warn("unable to retrieve client information for logout, skipping resource", ex);
        }
    });
    logger.debugv("logging out {0} resources ", counter);
    return finalResult;
}
Also used : GlobalRequestResult(org.keycloak.representations.adapters.action.GlobalRequestResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ModelIllegalStateException(org.keycloak.models.ModelIllegalStateException)

Example 3 with GlobalRequestResult

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

the class ResourceAdminManager method logoutClient.

protected GlobalRequestResult logoutClient(RealmModel realm, ClientModel resource, int notBefore) {
    if (!resource.isEnabled()) {
        return new GlobalRequestResult();
    }
    List<String> mgmtUrls = getAllManagementUrls(resource);
    if (mgmtUrls.isEmpty()) {
        logger.debug("No management URL or no registered cluster nodes for the client " + resource.getClientId());
        return new GlobalRequestResult();
    }
    if (logger.isDebugEnabled())
        logger.debug("Send logoutClient for URLs: " + mgmtUrls);
    // Propagate this to all hosts
    GlobalRequestResult result = new GlobalRequestResult();
    for (String mgmtUrl : mgmtUrls) {
        if (sendLogoutRequest(realm, resource, null, null, notBefore, mgmtUrl) != null) {
            result.addSuccessRequest(mgmtUrl);
        } else {
            result.addFailedRequest(mgmtUrl);
        }
    }
    return result;
}
Also used : GlobalRequestResult(org.keycloak.representations.adapters.action.GlobalRequestResult)

Example 4 with GlobalRequestResult

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

the class ResourceAdminManager method pushRevocationPolicy.

protected GlobalRequestResult pushRevocationPolicy(RealmModel realm, ClientModel resource, int notBefore) {
    List<String> mgmtUrls = getAllManagementUrls(resource);
    if (mgmtUrls.isEmpty()) {
        logger.debugf("No management URL or no registered cluster nodes for the client %s", resource.getClientId());
        return new GlobalRequestResult();
    }
    if (logger.isDebugEnabled())
        logger.debug("Sending push revocation to URLS: " + mgmtUrls);
    // Propagate this to all hosts
    GlobalRequestResult result = new GlobalRequestResult();
    for (String mgmtUrl : mgmtUrls) {
        if (sendPushRevocationPolicyRequest(realm, resource, notBefore, mgmtUrl)) {
            result.addSuccessRequest(mgmtUrl);
        } else {
            result.addFailedRequest(mgmtUrl);
        }
    }
    return result;
}
Also used : GlobalRequestResult(org.keycloak.representations.adapters.action.GlobalRequestResult)

Example 5 with GlobalRequestResult

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

the class RealmTest method pushNotBefore.

// NOTE: clearKeysCache tested in KcOIDCBrokerWithSignatureTest
@Test
public void pushNotBefore() {
    setupTestAppAndUser();
    int time = Time.currentTime() - 60;
    RealmRepresentation rep = realm.toRepresentation();
    rep.setNotBefore(time);
    realm.update(rep);
    assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, Matchers.nullValue(String.class), rep, ResourceType.REALM);
    GlobalRequestResult globalRequestResult = realm.pushRevocation();
    assertAdminEvents.assertEvent(realmId, OperationType.ACTION, "push-revocation", globalRequestResult, ResourceType.REALM);
    assertThat(globalRequestResult.getSuccessRequests(), containsInAnyOrder(oauth.AUTH_SERVER_ROOT + "/realms/master/app/admin"));
    assertNull(globalRequestResult.getFailedRequests());
    PushNotBeforeAction adminPushNotBefore = testingClient.testApp().getAdminPushNotBefore();
    assertEquals(time, adminPushNotBefore.getNotBefore());
}
Also used : GlobalRequestResult(org.keycloak.representations.adapters.action.GlobalRequestResult) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) PushNotBeforeAction(org.keycloak.representations.adapters.action.PushNotBeforeAction) AbstractAdminTest(org.keycloak.testsuite.admin.AbstractAdminTest) Test(org.junit.Test)

Aggregations

GlobalRequestResult (org.keycloak.representations.adapters.action.GlobalRequestResult)13 Test (org.junit.Test)5 Path (javax.ws.rs.Path)3 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)3 ResourceAdminManager (org.keycloak.services.managers.ResourceAdminManager)3 AbstractAdminTest (org.keycloak.testsuite.admin.AbstractAdminTest)3 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 PushNotBeforeAction (org.keycloak.representations.adapters.action.PushNotBeforeAction)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 GET (javax.ws.rs.GET)1 Response (javax.ws.rs.core.Response)1 NoCache (org.jboss.resteasy.annotations.cache.NoCache)1 ModelIllegalStateException (org.keycloak.models.ModelIllegalStateException)1 TestAvailabilityAction (org.keycloak.representations.adapters.action.TestAvailabilityAction)1 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)1 AbstractServletsAdapterTest (org.keycloak.testsuite.adapter.AbstractServletsAdapterTest)1 AccessTokenResponse (org.keycloak.testsuite.util.OAuthClient.AccessTokenResponse)1