Search in sources :

Example 11 with TimePolicyRepresentation

use of org.keycloak.representations.idm.authorization.TimePolicyRepresentation 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 12 with TimePolicyRepresentation

use of org.keycloak.representations.idm.authorization.TimePolicyRepresentation 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)

Example 13 with TimePolicyRepresentation

use of org.keycloak.representations.idm.authorization.TimePolicyRepresentation in project keycloak by keycloak.

the class TimePolicyManagementTest method testDelete.

@Test
public void testDelete() {
    authorizationPage.navigateTo();
    TimePolicyRepresentation expected = new TimePolicyRepresentation();
    expected.setName("Test Time Policy");
    expected.setDescription("description");
    expected.setNotBefore("2017-01-01 00:00:00");
    expected.setNotOnOrAfter("2018-01-01 00:00:00");
    expected.setDayMonth("1");
    expected.setDayMonthEnd("2");
    expected.setMonth("3");
    expected.setMonthEnd("4");
    expected.setYear("5");
    expected.setYearEnd("6");
    expected.setHour("7");
    expected.setHourEnd("8");
    expected.setMinute("9");
    expected.setMinuteEnd("10");
    expected = createPolicy(expected);
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().policies().delete(expected.getName());
    assertAlertSuccess();
    authorizationPage.navigateTo();
    assertNull(authorizationPage.authorizationTabs().policies().policies().findByName(expected.getName()));
}
Also used : TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation) Test(org.junit.Test)

Example 14 with TimePolicyRepresentation

use of org.keycloak.representations.idm.authorization.TimePolicyRepresentation in project keycloak by keycloak.

the class TimePolicyManagementTest method testUpdate.

@Test
public void testUpdate() {
    authorizationPage.navigateTo();
    TimePolicyRepresentation expected = new TimePolicyRepresentation();
    expected.setName("Test Time Policy");
    expected.setDescription("description");
    expected.setNotBefore("2017-01-01 00:00:00");
    expected.setNotOnOrAfter("2018-01-01 00:00:00");
    expected.setDayMonth("1");
    expected.setDayMonthEnd("2");
    expected.setMonth("3");
    expected.setMonthEnd("4");
    expected.setYear("5");
    expected.setYearEnd("6");
    expected.setHour("7");
    expected.setHourEnd("8");
    expected.setMinute("9");
    expected.setMinuteEnd("10");
    expected = createPolicy(expected);
    String previousName = expected.getName();
    expected.setName("Changed Test Time Policy");
    expected.setDescription("Changed description");
    expected.setLogic(Logic.NEGATIVE);
    expected.setNotBefore("2018-01-01 00:00:00");
    expected.setNotOnOrAfter("2019-01-01 00:00:00");
    expected.setDayMonth("23");
    expected.setDayMonthEnd("25");
    expected.setMonth("11");
    expected.setMonthEnd("12");
    expected.setYear("2020");
    expected.setYearEnd("2021");
    expected.setHour("17");
    expected.setHourEnd("18");
    expected.setMinute("19");
    expected.setMinuteEnd("20");
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().policies().update(previousName, expected);
    assertAlertSuccess();
    authorizationPage.navigateTo();
    TimePolicy actual = authorizationPage.authorizationTabs().policies().name(expected.getName());
    assertPolicy(expected, actual);
    expected.setNotBefore("");
    expected.setNotOnOrAfter("");
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().policies().update(expected.getName(), expected);
    assertAlertSuccess();
}
Also used : TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation) TimePolicy(org.keycloak.testsuite.console.page.clients.authorization.policy.TimePolicy) Test(org.junit.Test)

Aggregations

TimePolicyRepresentation (org.keycloak.representations.idm.authorization.TimePolicyRepresentation)14 Test (org.junit.Test)6 TimePoliciesResource (org.keycloak.admin.client.resource.TimePoliciesResource)3 TimePolicyResource (org.keycloak.admin.client.resource.TimePolicyResource)3 Response (javax.ws.rs.core.Response)2 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)2 AggregatePolicyRepresentation (org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation)2 ClientPolicyRepresentation (org.keycloak.representations.idm.authorization.ClientPolicyRepresentation)2 GroupPolicyRepresentation (org.keycloak.representations.idm.authorization.GroupPolicyRepresentation)2 JSPolicyRepresentation (org.keycloak.representations.idm.authorization.JSPolicyRepresentation)2 RolePolicyRepresentation (org.keycloak.representations.idm.authorization.RolePolicyRepresentation)2 UserPolicyRepresentation (org.keycloak.representations.idm.authorization.UserPolicyRepresentation)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 NotFoundException (javax.ws.rs.NotFoundException)1 AuthorizationProvider (org.keycloak.authorization.AuthorizationProvider)1 Policy (org.keycloak.authorization.model.Policy)1 ResourceServer (org.keycloak.authorization.model.ResourceServer)1