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) {
}
}
}
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);
}
}
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);
}
Aggregations