Search in sources :

Example 56 with PrincipalKey

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();
}
Also used : PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 57 with PrincipalKey

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"));
        }
    }
}
Also used : WidgetDescriptor(com.enonic.xp.admin.widget.WidgetDescriptor) List(java.util.List) PrincipalKey(com.enonic.xp.security.PrincipalKey) XmlModelParser(com.enonic.xp.xml.parser.XmlModelParser) DomElement(com.enonic.xp.xml.DomElement) Collectors(java.util.stream.Collectors) DomElement(com.enonic.xp.xml.DomElement) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 58 with PrincipalKey

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;
}
Also used : Context(com.enonic.xp.context.Context) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PrincipalKey(com.enonic.xp.security.PrincipalKey) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo)

Example 59 with PrincipalKey

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());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 60 with PrincipalKey

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());
}
Also used : Instant(java.time.Instant) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Aggregations

PrincipalKey (com.enonic.xp.security.PrincipalKey)84 Test (org.junit.jupiter.api.Test)47 PropertyTree (com.enonic.xp.data.PropertyTree)22 User (com.enonic.xp.security.User)18 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)15 CreateUserParams (com.enonic.xp.security.CreateUserParams)14 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)14 Instant (java.time.Instant)12 Node (com.enonic.xp.node.Node)10 DescriptorKey (com.enonic.xp.page.DescriptorKey)10 Context (com.enonic.xp.context.Context)9 IdProviderKey (com.enonic.xp.security.IdProviderKey)9 PrincipalRelationship (com.enonic.xp.security.PrincipalRelationship)9 CreateGroupParams (com.enonic.xp.security.CreateGroupParams)8 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)8 NodeId (com.enonic.xp.node.NodeId)7 NodeQuery (com.enonic.xp.node.NodeQuery)7 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)7 Group (com.enonic.xp.security.Group)6 AccessControlList (com.enonic.xp.security.acl.AccessControlList)6