Search in sources :

Example 6 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 7 with TimePolicyRepresentation

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

the class TimePolicyProviderFactory method toRepresentation.

@Override
public TimePolicyRepresentation toRepresentation(Policy policy, AuthorizationProvider authorization) {
    TimePolicyRepresentation representation = new TimePolicyRepresentation();
    Map<String, String> config = policy.getConfig();
    representation.setDayMonth(config.get("dayMonth"));
    representation.setDayMonthEnd(config.get("dayMonthEnd"));
    representation.setMonth(config.get("month"));
    representation.setMonthEnd(config.get("monthEnd"));
    representation.setYear(config.get("year"));
    representation.setYearEnd(config.get("yearEnd"));
    representation.setHour(config.get("hour"));
    representation.setHourEnd(config.get("hourEnd"));
    representation.setMinute(config.get("minute"));
    representation.setMinuteEnd(config.get("minuteEnd"));
    representation.setNotBefore(config.get("nbf"));
    representation.setNotOnOrAfter(config.get("noa"));
    return representation;
}
Also used : TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation)

Example 8 with TimePolicyRepresentation

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

the class Policies method update.

public void update(String name, AbstractPolicyRepresentation representation) {
    for (WebElement row : policies().rows()) {
        PolicyRepresentation actual = policies().toRepresentation(row);
        if (actual.getName().equalsIgnoreCase(name)) {
            clickLink(row.findElements(tagName("a")).get(0));
            String type = representation.getType();
            if ("role".equals(type)) {
                rolePolicy.form().populate((RolePolicyRepresentation) representation, true);
            } else if ("user".equals(type)) {
                userPolicy.form().populate((UserPolicyRepresentation) representation, true);
            } else if ("aggregate".equals(type)) {
                aggregatePolicy.form().populate((AggregatePolicyRepresentation) representation, true);
            } else if ("js".equals(type)) {
                jsPolicy.form().populate((JSPolicyRepresentation) representation, true);
            } else if ("time".equals(type)) {
                timePolicy.form().populate((TimePolicyRepresentation) representation, true);
            } else if ("client".equals(type)) {
                clientPolicy.form().populate((ClientPolicyRepresentation) representation, true);
            } else if ("group".equals(type)) {
                groupPolicy.form().populate((GroupPolicyRepresentation) representation, true);
            }
            return;
        }
    }
}
Also used : RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) AbstractPolicyRepresentation(org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation) GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation) PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) UserPolicyRepresentation(org.keycloak.representations.idm.authorization.UserPolicyRepresentation) AggregatePolicyRepresentation(org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation) JSPolicyRepresentation(org.keycloak.representations.idm.authorization.JSPolicyRepresentation) ClientPolicyRepresentation(org.keycloak.representations.idm.authorization.ClientPolicyRepresentation) ClientPolicyRepresentation(org.keycloak.representations.idm.authorization.ClientPolicyRepresentation) UserPolicyRepresentation(org.keycloak.representations.idm.authorization.UserPolicyRepresentation) JSPolicyRepresentation(org.keycloak.representations.idm.authorization.JSPolicyRepresentation) WebElement(org.openqa.selenium.WebElement)

Example 9 with TimePolicyRepresentation

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

the class TimePolicyForm method toRepresentation.

public TimePolicyRepresentation toRepresentation() {
    TimePolicyRepresentation representation = new TimePolicyRepresentation();
    representation.setName(UIUtils.getTextInputValue(name));
    representation.setDescription(UIUtils.getTextInputValue(description));
    representation.setLogic(Logic.valueOf(UIUtils.getTextFromElement(logic.getFirstSelectedOption()).toUpperCase()));
    representation.setDayMonth(UIUtils.getTextInputValue(dayMonth));
    representation.setDayMonthEnd(UIUtils.getTextInputValue(dayMonthEnd));
    representation.setMonth(UIUtils.getTextInputValue(month));
    representation.setMonthEnd(UIUtils.getTextInputValue(monthEnd));
    representation.setYear(UIUtils.getTextInputValue(year));
    representation.setYearEnd(UIUtils.getTextInputValue(yearEnd));
    representation.setHour(UIUtils.getTextInputValue(hour));
    representation.setHourEnd(UIUtils.getTextInputValue(hourEnd));
    representation.setMinute(UIUtils.getTextInputValue(minute));
    representation.setMinuteEnd(UIUtils.getTextInputValue(minuteEnd));
    representation.setNotBefore(UIUtils.getTextInputValue(notBefore));
    representation.setNotOnOrAfter(UIUtils.getTextInputValue(notOnOrAfter));
    return representation;
}
Also used : TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation)

Example 10 with TimePolicyRepresentation

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

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