Search in sources :

Example 1 with PushNotBeforeAction

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

the class PreAuthActionsHandler method handlePushNotBefore.

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

Example 2 with PushNotBeforeAction

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

the class ClientTest method pushRevocation.

@Test
public void pushRevocation() {
    testingClient.testApp().clearAdminActions();
    ClientRepresentation client = createAppClient();
    String id = client.getId();
    realm.clients().get(id).pushRevocation();
    PushNotBeforeAction pushNotBefore = testingClient.testApp().getAdminPushNotBefore();
    assertEquals(client.getNotBefore().intValue(), pushNotBefore.getNotBefore());
    assertAdminEvents.assertEvent(realmId, OperationType.ACTION, AdminEventPaths.clientPushRevocationPath(id), ResourceType.CLIENT);
}
Also used : PushNotBeforeAction(org.keycloak.representations.adapters.action.PushNotBeforeAction) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 3 with PushNotBeforeAction

use of org.keycloak.representations.adapters.action.PushNotBeforeAction 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)

Example 4 with PushNotBeforeAction

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

the class RealmTest method pushNotBeforeWithSamlApp.

@Test
public void pushNotBeforeWithSamlApp() {
    setupTestAppAndUser();
    setupTestSamlApp();
    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"));
    assertThat(globalRequestResult.getFailedRequests(), containsInAnyOrder(oauth.AUTH_SERVER_ROOT + "/realms/master/saml-app/saml"));
    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)

Example 5 with PushNotBeforeAction

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

the class OIDCLoginProtocol method sendPushRevocationPolicyRequest.

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

Aggregations

PushNotBeforeAction (org.keycloak.representations.adapters.action.PushNotBeforeAction)5 Test (org.junit.Test)3 GlobalRequestResult (org.keycloak.representations.adapters.action.GlobalRequestResult)2 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)2 AbstractAdminTest (org.keycloak.testsuite.admin.AbstractAdminTest)2 IOException (java.io.IOException)1 URI (java.net.URI)1 VerificationException (org.keycloak.common.VerificationException)1 HttpClientProvider (org.keycloak.connections.httpclient.HttpClientProvider)1 JWSInput (org.keycloak.jose.jws.JWSInput)1 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)1