Search in sources :

Example 1 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 2 with PrincipalKey

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

the class JsonExceptionMapper method createContextJson.

private static 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 3 with PrincipalKey

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

the class ChangePasswordHandler method changePassword.

public void changePassword() {
    final PrincipalKey principalKey = PrincipalKey.from(userKey);
    this.securityService.get().setPassword(principalKey, normalize(password));
}
Also used : PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 4 with PrincipalKey

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

the class GetMembershipsHandlerTest method testGetTransitiveUserMemberships.

@Test
public void testGetTransitiveUserMemberships() {
    final Group group = TestDataFixtures.getTestGroup();
    final PrincipalKeys principalKeys = PrincipalKeys.from(group.getKey());
    final PrincipalKey pKey = PrincipalKey.from("user:myIdProvider:userId");
    Mockito.when(securityService.getAllMemberships(pKey)).thenReturn(principalKeys);
    Mockito.verify(securityService, Mockito.never()).getMemberships(pKey);
    Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(group));
    runFunction("/test/getMemberships-test.js", "getTransitiveUserMemberships");
}
Also used : Group(com.enonic.xp.security.Group) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 5 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)

Aggregations

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