use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class ContextMapper method serializePrincipals.
private void serializePrincipals(final MapGenerator gen, final PrincipalKeys keys) {
if (keys == null) {
return;
}
gen.array("principals");
for (final PrincipalKey key : keys) {
gen.value(key.toString());
}
gen.end();
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class XmlWidgetDescriptorParser method doParse.
@Override
protected void doParse(final DomElement root) throws Exception {
assertTagName(root, "widget");
this.builder.displayName(root.getChildValueTrimmed("display-name"));
this.builder.description(root.getChildValue("description"));
final DomElement interfaces = root.getChild("interfaces");
if (interfaces != null) {
final List<DomElement> interfaceList = interfaces.getChildren("interface");
for (DomElement anInterface : interfaceList) {
this.builder.addInterface(anInterface.getValue().trim());
}
}
final DomElement allowedPrincipals = root.getChild("allow");
if (allowedPrincipals != null) {
final List<PrincipalKey> allowedPrincipalList = allowedPrincipals.getChildren("principal").stream().map(allowedPrincipal -> PrincipalKey.from(allowedPrincipal.getValue().trim())).collect(Collectors.toList());
this.builder.setAllowedPrincipals(allowedPrincipalList);
}
final DomElement config = root.getChild("config");
if (config != null) {
final List<DomElement> properties = config.getChildren("property");
for (DomElement property : properties) {
this.builder.addProperty(property.getAttribute("name"), property.getAttribute("value"));
}
}
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class StatusResource method createContextJson.
private ObjectNode createContextJson() {
final Context context = ContextAccessor.current();
final AuthenticationInfo authInfo = context.getAuthInfo();
final ObjectNode node = JsonNodeFactory.instance.objectNode();
node.put("authenticated", (authInfo != null) && authInfo.isAuthenticated());
final ArrayNode principals = node.putArray("principals");
if (authInfo != null) {
for (final PrincipalKey principal : authInfo.getPrincipals()) {
principals.add(principal.toString());
}
}
return node;
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class CreateScheduledJobParamsTest method testBuilder.
@Test
public void testBuilder() {
final PrincipalKey user = PrincipalKey.ofUser(IdProviderKey.createDefault(), "user");
final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.BASE, "descriptor");
final PropertyTree config = new PropertyTree();
config.addString("property", "value");
final String description = "description";
final ScheduleCalendar calendar = mock(ScheduleCalendar.class);
final CreateScheduledJobParams params = CreateScheduledJobParams.create().name(ScheduledJobName.from("name")).config(config).user(user).descriptor(descriptor).description(description).calendar(calendar).enabled(true).build();
assertEquals(config, params.getConfig());
assertEquals(user, params.getUser());
assertEquals(descriptor, params.getDescriptor());
assertEquals(description, params.getDescription());
assertEquals(calendar, params.getCalendar());
assertTrue(params.isEnabled());
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class ScheduledJobTest method testBuilder.
@Test
public void testBuilder() {
final PrincipalKey user = PrincipalKey.ofUser(IdProviderKey.createDefault(), "user");
final PrincipalKey creator = PrincipalKey.ofUser(IdProviderKey.createDefault(), "creator");
final PrincipalKey modifier = PrincipalKey.ofUser(IdProviderKey.createDefault(), "modifier");
final Instant createdTime = Instant.parse("2016-11-02T10:36:00Z");
final Instant modifiedTime = Instant.parse("2020-11-02T10:36:00Z");
final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.BASE, "descriptor");
final PropertyTree config = new PropertyTree();
config.addString("property", "value");
final String description = "description";
final ScheduledJob job = ScheduledJob.create().name(ScheduledJobName.from("name")).config(config).user(user).descriptor(descriptor).description(description).calendar(mock(ScheduleCalendar.class)).enabled(true).creator(creator).modifier(modifier).createdTime(createdTime).modifiedTime(modifiedTime).build();
assertEquals(config, job.getConfig());
assertEquals(user, job.getUser());
assertEquals(descriptor, job.getDescriptor());
assertEquals(description, job.getDescription());
assertTrue(job.isEnabled());
assertEquals(creator, job.getCreator());
assertEquals(modifier, job.getModifier());
assertEquals(createdTime, job.getCreatedTime());
assertEquals(modifiedTime, job.getModifiedTime());
}
Aggregations