Search in sources :

Example 26 with PrincipalKey

use of com.enonic.xp.security.PrincipalKey in project xp by enonic.

the class IssueServiceImplTest_updateComment method updateComment.

@Test
public void updateComment() throws Exception {
    Issue issue = this.createIssue(CreateIssueParams.create().title("issue-1"));
    final Instant created = Instant.now().minus(1, ChronoUnit.MINUTES);
    final PrincipalKey creator = PrincipalKey.from("user:store:me");
    final String creatorDisplayName = "Me Myself";
    final CreateIssueCommentParams params = CreateIssueCommentParams.create().text("text").issue(issue.getId()).creator(creator).creatorDisplayName(creatorDisplayName).created(created).build();
    final IssueComment comment = this.issueService.createComment(params);
    final IssueComment updatedComment = this.issueService.updateComment(UpdateIssueCommentParams.create().comment(comment.getId()).text("updated text").build());
    assertNotNull(updatedComment);
    assertEquals("updated text", updatedComment.getText());
    assertEquals(creator, updatedComment.getCreator());
    assertEquals(creatorDisplayName, updatedComment.getCreatorDisplayName());
    assertEquals(created, updatedComment.getCreated());
}
Also used : Issue(com.enonic.xp.issue.Issue) Instant(java.time.Instant) IssueComment(com.enonic.xp.issue.IssueComment) PrincipalKey(com.enonic.xp.security.PrincipalKey) CreateIssueCommentParams(com.enonic.xp.issue.CreateIssueCommentParams) Test(org.junit.jupiter.api.Test)

Example 27 with PrincipalKey

use of com.enonic.xp.security.PrincipalKey in project xp by enonic.

the class XmlServiceDescriptorParser method doParse.

@Override
protected void doParse(final DomElement root) throws Exception {
    assertTagName(root, "service");
    final DomElement allowedPrincipals = root.getChild("allow");
    if (allowedPrincipals != null) {
        final List<PrincipalKey> allowedPrincipalKeys = new ArrayList<>();
        final List<DomElement> allowedPrincipalList = allowedPrincipals.getChildren("principal");
        for (DomElement allowedPrincipal : allowedPrincipalList) {
            allowedPrincipalKeys.add(PrincipalKey.from(allowedPrincipal.getValue().trim()));
        }
        this.builder.setAllowedPrincipals(allowedPrincipalKeys);
    }
}
Also used : DomElement(com.enonic.xp.xml.DomElement) ArrayList(java.util.ArrayList) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 28 with PrincipalKey

use of com.enonic.xp.security.PrincipalKey in project xp by enonic.

the class UpdateProjectRoleNamesCommand method doUpdateRoles.

private void doUpdateRoles() {
    for (ProjectRole projectRole : ProjectRole.values()) {
        final PrincipalKey roleKey = ProjectAccessHelper.createRoleKey(projectName, projectRole);
        final String newRoleDisplayName = createRoleDisplayName(projectRole);
        securityService.getRole(roleKey).filter(role -> !newRoleDisplayName.equals(role.getDisplayName())).ifPresent((roleValue) -> doUpdateRoleDisplayName(roleValue, newRoleDisplayName));
    }
}
Also used : UpdateRoleParams(com.enonic.xp.security.UpdateRoleParams) ProjectRole(com.enonic.xp.project.ProjectRole) PrincipalKey(com.enonic.xp.security.PrincipalKey) Preconditions(com.google.common.base.Preconditions) Role(com.enonic.xp.security.Role) ProjectRole(com.enonic.xp.project.ProjectRole) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 29 with PrincipalKey

use of com.enonic.xp.security.PrincipalKey in project xp by enonic.

the class CreateProjectRolesCommand method doCreateRoles.

private void doCreateRoles() {
    for (ProjectRole projectRole : ProjectRole.values()) {
        final PrincipalKey roleKey = ProjectAccessHelper.createRoleKey(projectName, projectRole);
        final String roleDisplayName = createRoleDisplayName(projectRole);
        securityService.getRole(roleKey).orElseGet(() -> doCreateRole(roleKey, roleDisplayName));
    }
}
Also used : ProjectRole(com.enonic.xp.project.ProjectRole) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 30 with PrincipalKey

use of com.enonic.xp.security.PrincipalKey in project xp by enonic.

the class EditableScheduledJobTest method testChanged.

@Test
public void testChanged() {
    final ScheduledJob source = ScheduledJob.create().name(ScheduledJobName.from("name")).descriptor(DescriptorKey.from("app:key")).calendar(mock(ScheduleCalendar.class)).creator(PrincipalKey.from("user:system:creator")).modifier(PrincipalKey.from("user:system:creator")).createdTime(Instant.parse("2016-11-02T10:36:00Z")).modifiedTime(Instant.parse("2016-11-02T10:36:00Z")).build();
    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 EditableScheduledJob editable = new EditableScheduledJob(source);
    editable.config = config;
    editable.user = user;
    editable.descriptor = descriptor;
    editable.description = description;
    editable.calendar = mock(ScheduleCalendar.class);
    editable.enabled = true;
    final ScheduledJob target = editable.build();
    assertEquals(source.getName(), target.getName());
    assertEquals(config, target.getConfig());
    assertEquals(user, target.getUser());
    assertEquals(descriptor, target.getDescriptor());
    assertEquals(description, target.getDescription());
    assertTrue(target.isEnabled());
}
Also used : ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) ScheduleCalendar(com.enonic.xp.scheduler.ScheduleCalendar) PrincipalKey(com.enonic.xp.security.PrincipalKey) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob) 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