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