Search in sources :

Example 1 with TimePolicyRepresentation

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

the class AggregatePolicyManagementTest method testCreateWithChildAndSelectedPolicy.

@Test
public void testCreateWithChildAndSelectedPolicy() {
    refreshPageAndWaitForLoad();
    AggregatePolicyRepresentation expected = new AggregatePolicyRepresentation();
    expected.setName("Test Child Create And Select Aggregate Policy");
    expected.setDescription("description");
    expected.addPolicy("Policy C");
    AggregatePolicy policy = authorizationPage.authorizationTabs().policies().create(expected, false);
    RolePolicyRepresentation childRolePolicy = new RolePolicyRepresentation();
    childRolePolicy.setName(UUID.randomUUID().toString());
    childRolePolicy.addRole("Role A");
    policy.createPolicy(childRolePolicy);
    expected.addPolicy(childRolePolicy.getName());
    UserPolicyRepresentation childUserPolicy = new UserPolicyRepresentation();
    childUserPolicy.setName(UUID.randomUUID().toString());
    childUserPolicy.setDescription("description");
    childUserPolicy.addUser("user a");
    policy.createPolicy(childUserPolicy);
    expected.addPolicy(childUserPolicy.getName());
    ClientPolicyRepresentation childClientPolicy = new ClientPolicyRepresentation();
    childClientPolicy.setName(UUID.randomUUID().toString());
    childClientPolicy.setDescription("description");
    childClientPolicy.addClient("client a");
    policy.createPolicy(childClientPolicy);
    expected.addPolicy(childClientPolicy.getName());
    JSPolicyRepresentation childJSPolicy = new JSPolicyRepresentation();
    childJSPolicy.setName(UUID.randomUUID().toString());
    childJSPolicy.setDescription("description");
    childJSPolicy.setCode("$evaluation.grant();");
    policy.createPolicy(childJSPolicy);
    expected.addPolicy(childJSPolicy.getName());
    TimePolicyRepresentation childTimePolicy = new TimePolicyRepresentation();
    childTimePolicy.setName(UUID.randomUUID().toString());
    childTimePolicy.setDescription("description");
    childTimePolicy.setNotBefore("2017-01-01 00:00:00");
    childTimePolicy.setNotBefore("2018-01-01 00:00:00");
    policy.createPolicy(childTimePolicy);
    expected.addPolicy(childTimePolicy.getName());
    GroupPolicyRepresentation childGroupPolicy = new GroupPolicyRepresentation();
    childGroupPolicy.setName(UUID.randomUUID().toString());
    childGroupPolicy.setDescription("description");
    childGroupPolicy.setGroupsClaim("groups");
    childGroupPolicy.addGroupPath("/Group A", true);
    policy.createPolicy(childGroupPolicy);
    expected.addPolicy(childGroupPolicy.getName());
    policy.form().save();
    assertAlertSuccess();
    authorizationPage.navigateTo();
    AggregatePolicy actual = authorizationPage.authorizationTabs().policies().name(expected.getName());
    assertPolicy(expected, actual);
}
Also used : RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) ClientPolicyRepresentation(org.keycloak.representations.idm.authorization.ClientPolicyRepresentation) UserPolicyRepresentation(org.keycloak.representations.idm.authorization.UserPolicyRepresentation) JSPolicyRepresentation(org.keycloak.representations.idm.authorization.JSPolicyRepresentation) TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation) AggregatePolicy(org.keycloak.testsuite.console.page.clients.authorization.policy.AggregatePolicy) GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) AggregatePolicyRepresentation(org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation) Test(org.junit.Test)

Example 2 with TimePolicyRepresentation

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

the class TimePolicyManagementTest method testDeleteFromList.

@Test
public void testDeleteFromList() {
    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().deleteFromList(expected.getName());
    authorizationPage.navigateTo();
    assertNull(authorizationPage.authorizationTabs().policies().policies().findByName(expected.getName()));
}
Also used : TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation) Test(org.junit.Test)

Example 3 with TimePolicyRepresentation

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

the class TimePolicyManagementTest method assertPolicy.

private TimePolicyRepresentation assertPolicy(TimePolicyRepresentation expected, TimePolicy policy) {
    TimePolicyRepresentation actual = policy.toRepresentation();
    assertEquals(expected.getName(), actual.getName());
    assertEquals(expected.getDescription(), actual.getDescription());
    assertEquals(expected.getLogic(), actual.getLogic());
    assertEquals(expected.getNotBefore(), actual.getNotBefore());
    assertEquals(expected.getNotOnOrAfter(), actual.getNotOnOrAfter());
    assertEquals(expected.getDayMonth(), actual.getDayMonth());
    assertEquals(expected.getDayMonthEnd(), actual.getDayMonthEnd());
    assertEquals(expected.getHour(), actual.getHour());
    assertEquals(expected.getHourEnd(), actual.getHourEnd());
    assertEquals(expected.getMinute(), actual.getMinute());
    assertEquals(expected.getMinuteEnd(), actual.getMinuteEnd());
    assertEquals(expected.getMonth(), actual.getMonth());
    assertEquals(expected.getMonthEnd(), actual.getMonthEnd());
    assertEquals(expected.getYear(), actual.getYear());
    assertEquals(expected.getYearEnd(), actual.getYearEnd());
    return actual;
}
Also used : TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation)

Example 4 with TimePolicyRepresentation

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

the class TimePolicyManagementTest method assertRepresentation.

private void assertRepresentation(TimePolicyRepresentation representation, TimePolicyResource permission) {
    TimePolicyRepresentation actual = permission.toRepresentation();
    assertRepresentation(representation, actual, () -> permission.resources(), () -> Collections.emptyList(), () -> permission.associatedPolicies());
    assertEquals(representation.getDayMonth(), actual.getDayMonth());
    assertEquals(representation.getDayMonthEnd(), actual.getDayMonthEnd());
    assertEquals(representation.getMonth(), actual.getMonth());
    assertEquals(representation.getMonthEnd(), actual.getMonthEnd());
    assertEquals(representation.getYear(), actual.getYear());
    assertEquals(representation.getYearEnd(), actual.getYearEnd());
    assertEquals(representation.getHour(), actual.getHour());
    assertEquals(representation.getHourEnd(), actual.getHourEnd());
    assertEquals(representation.getMinute(), actual.getMinute());
    assertEquals(representation.getMinuteEnd(), actual.getMinuteEnd());
    assertEquals(representation.getNotBefore(), actual.getNotBefore());
    assertEquals(representation.getNotOnOrAfter(), actual.getNotOnOrAfter());
}
Also used : TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation)

Example 5 with TimePolicyRepresentation

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

the class TimePolicyManagementTest method createRepresentation.

private TimePolicyRepresentation createRepresentation(String name) {
    TimePolicyRepresentation representation = new TimePolicyRepresentation();
    representation.setName(name);
    representation.setDescription("description");
    representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    representation.setLogic(Logic.NEGATIVE);
    representation.setDayMonth("1");
    representation.setDayMonthEnd("2");
    representation.setMonth("3");
    representation.setMonthEnd("4");
    representation.setYear("5");
    representation.setYearEnd("6");
    representation.setHour("7");
    representation.setHourEnd("8");
    representation.setMinute("9");
    representation.setMinuteEnd("10");
    representation.setNotBefore("2017-01-01 00:00:00");
    representation.setNotOnOrAfter("2017-02-01 00:00:00");
    return representation;
}
Also used : TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation)

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