Search in sources :

Example 1 with TimePoliciesResource

use of org.keycloak.admin.client.resource.TimePoliciesResource in project keycloak by keycloak.

the class TimePolicyManagementTest method testDelete.

@Test
public void testDelete() {
    AuthorizationResource authorization = getClient().authorization();
    TimePolicyRepresentation representation = createRepresentation("Test Delete Policy");
    TimePoliciesResource policies = authorization.policies().time();
    try (Response response = policies.create(representation)) {
        TimePolicyRepresentation created = response.readEntity(TimePolicyRepresentation.class);
        policies.findById(created.getId()).remove();
        TimePolicyResource removed = policies.findById(created.getId());
        try {
            removed.toRepresentation();
            fail("Permission not removed");
        } catch (NotFoundException ignore) {
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) TimePolicyResource(org.keycloak.admin.client.resource.TimePolicyResource) TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation) TimePoliciesResource(org.keycloak.admin.client.resource.TimePoliciesResource) NotFoundException(javax.ws.rs.NotFoundException) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) Test(org.junit.Test)

Example 2 with TimePoliciesResource

use of org.keycloak.admin.client.resource.TimePoliciesResource in project keycloak by keycloak.

the class TimePolicyManagementTest method assertCreated.

private void assertCreated(AuthorizationResource authorization, TimePolicyRepresentation representation) {
    TimePoliciesResource permissions = authorization.policies().time();
    try (Response response = permissions.create(representation)) {
        TimePolicyRepresentation created = response.readEntity(TimePolicyRepresentation.class);
        TimePolicyResource permission = permissions.findById(created.getId());
        assertRepresentation(representation, permission);
    }
}
Also used : Response(javax.ws.rs.core.Response) TimePolicyResource(org.keycloak.admin.client.resource.TimePolicyResource) TimePoliciesResource(org.keycloak.admin.client.resource.TimePoliciesResource) TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation)

Example 3 with TimePoliciesResource

use of org.keycloak.admin.client.resource.TimePoliciesResource in project keycloak by keycloak.

the class TimePolicyManagementTest method testUpdate.

@Test
public void testUpdate() {
    AuthorizationResource authorization = getClient().authorization();
    TimePolicyRepresentation representation = createRepresentation("Update Time Policy");
    assertCreated(authorization, representation);
    representation.setName("changed");
    representation.setDescription("changed");
    representation.setDecisionStrategy(DecisionStrategy.AFFIRMATIVE);
    representation.setLogic(Logic.POSITIVE);
    representation.setDayMonth("11");
    representation.setDayMonthEnd("22");
    representation.setMonth("7");
    representation.setMonthEnd("9");
    representation.setYear("2019");
    representation.setYearEnd("2030");
    representation.setHour("15");
    representation.setHourEnd("23");
    representation.setMinute("55");
    representation.setMinuteEnd("58");
    representation.setNotBefore("2019-01-01 00:00:00");
    representation.setNotOnOrAfter("2019-02-03 00:00:00");
    TimePoliciesResource policies = authorization.policies().time();
    TimePolicyResource permission = policies.findById(representation.getId());
    permission.update(representation);
    assertRepresentation(representation, permission);
    representation.setDayMonth(null);
    representation.setDayMonthEnd(null);
    representation.setMonth(null);
    representation.setMonthEnd(null);
    representation.setYear(null);
    representation.setYearEnd(null);
    representation.setHour(null);
    representation.setHourEnd(null);
    representation.setMinute(null);
    representation.setMinuteEnd(null);
    representation.setNotBefore(null);
    representation.setNotOnOrAfter("2019-02-03 00:00:00");
    permission.update(representation);
    assertRepresentation(representation, permission);
    representation.setNotOnOrAfter(null);
    representation.setHour("2");
    permission.update(representation);
    assertRepresentation(representation, permission);
}
Also used : TimePolicyResource(org.keycloak.admin.client.resource.TimePolicyResource) TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation) TimePoliciesResource(org.keycloak.admin.client.resource.TimePoliciesResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) Test(org.junit.Test)

Aggregations

TimePoliciesResource (org.keycloak.admin.client.resource.TimePoliciesResource)3 TimePolicyResource (org.keycloak.admin.client.resource.TimePolicyResource)3 TimePolicyRepresentation (org.keycloak.representations.idm.authorization.TimePolicyRepresentation)3 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)2 NotFoundException (javax.ws.rs.NotFoundException)1