Search in sources :

Example 61 with PrincipalKey

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

the class AuthenticationInfoTest method testSerializationWithUserProfile.

@Test
void testSerializationWithUserProfile() throws Exception {
    final PropertySet data = new PropertySet();
    data.setString("subString", "subStringValue");
    data.setLong("subLong", 123L);
    final PropertyTree userProfile = new PropertyTree();
    userProfile.setSet("myApp", data);
    userProfile.setString("string", "stringValue");
    final User user = User.create().login("userlogin").displayName("my user").key(PrincipalKey.ofUser(IdProviderKey.from("myidprovider"), "userid")).email("user@email").modifiedTime(Instant.now(clock)).profile(userProfile).build();
    final IdProviderKey idProvider = IdProviderKey.from("myStore");
    final PrincipalKey group1 = PrincipalKey.ofGroup(idProvider, "group1");
    final PrincipalKey group2 = PrincipalKey.from("group:myStore:group2");
    final PrincipalKey role1 = PrincipalKey.from("role:administrators");
    final AuthenticationInfo info = AuthenticationInfo.create().user(user).principals(group1).principals(PrincipalKeys.from(group2, role1)).build();
    final byte[] serializedObject = serialize(info);
    final AuthenticationInfo deserializedObject = (AuthenticationInfo) deserialize(serializedObject);
    assertEquals(deserializedObject, info);
}
Also used : User(com.enonic.xp.security.User) PropertyTree(com.enonic.xp.data.PropertyTree) IdProviderKey(com.enonic.xp.security.IdProviderKey) PropertySet(com.enonic.xp.data.PropertySet) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 62 with PrincipalKey

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

the class FindIssueCommentsCommandTest method testFindIssuesNoIssue.

@Test
public void testFindIssuesNoIssue() throws Exception {
    final PrincipalKey creator = PrincipalKey.from("user:store:one");
    final IssueCommentQuery commentQuery = IssueCommentQuery.create().from(0).size(20).creator(creator).build();
    final FindIssueCommentsCommand command = createCommand(commentQuery);
    assertThrows(IllegalArgumentException.class, () -> command.execute());
}
Also used : IssueCommentQuery(com.enonic.xp.issue.IssueCommentQuery) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 63 with PrincipalKey

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

the class FindIssueCommentsCommandTest method testFindIssues.

@Test
public void testFindIssues() throws Exception {
    final IssueId issueId = IssueId.create();
    final Node issueNode = Node.create().id(NodeId.from(issueId)).name("parent-issue").build();
    final PrincipalKey creator = PrincipalKey.from("user:store:one");
    final IssueCommentQuery commentQuery = IssueCommentQuery.create().from(0).size(20).issue(issueId).creator(creator).build();
    final FindIssueCommentsCommand command = createCommand(commentQuery);
    Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenReturn(issueNode);
    Mockito.when(nodeService.findByQuery(Mockito.any(NodeQuery.class))).thenReturn(FindNodesByQueryResult.create().hits(20).totalHits(40).build());
    Mockito.when(nodeService.getByIds(Mockito.any(NodeIds.class))).thenReturn(Nodes.from(IssueCommentNodeTranslatorTest.createNode(Instant.now())));
    FindIssueCommentsResult result = command.execute();
    Mockito.verify(nodeService, Mockito.times(1)).findByQuery(Mockito.any(NodeQuery.class));
    Mockito.verify(nodeService, Mockito.times(1)).getByIds(Mockito.any(NodeIds.class));
    assertEquals(20, result.getHits());
    assertEquals(40, result.getTotalHits());
    assertEquals(1, result.getIssueComments().size());
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) NodeId(com.enonic.xp.node.NodeId) FindIssueCommentsResult(com.enonic.xp.issue.FindIssueCommentsResult) IssueId(com.enonic.xp.issue.IssueId) IssueCommentQuery(com.enonic.xp.issue.IssueCommentQuery) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 64 with PrincipalKey

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

the class FindIssueCommentsCommandTest method testFindIssuesIssueNotExists.

@Test
public void testFindIssuesIssueNotExists() throws Exception {
    final IssueId issueId = IssueId.create();
    final PrincipalKey creator = PrincipalKey.from("user:store:one");
    final IssueCommentQuery commentQuery = IssueCommentQuery.create().from(0).size(20).issue(issueId).creator(creator).build();
    final FindIssueCommentsCommand command = createCommand(commentQuery);
    Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenThrow(new NodeNotFoundException("Node not found"));
    assertThrows(NodeNotFoundException.class, () -> command.execute());
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeId(com.enonic.xp.node.NodeId) IssueId(com.enonic.xp.issue.IssueId) IssueCommentQuery(com.enonic.xp.issue.IssueCommentQuery) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 65 with PrincipalKey

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

the class DefaultPermissionsMergingStrategy method mergePermissions.

@Override
public AccessControlList mergePermissions(final AccessControlList childAcl, final AccessControlList parentAcl) {
    final AccessControlList.Builder effective = AccessControlList.create();
    // apply parent entries
    for (AccessControlEntry parentEntry : parentAcl) {
        final PrincipalKey principal = parentEntry.getPrincipal();
        if (childAcl.contains(principal)) {
            final AccessControlEntry childEntry = childAcl.getEntry(principal);
            final AccessControlEntry mergedEntry = mergeAccessControlEntries(childEntry, parentEntry);
            effective.add(mergedEntry);
        } else {
            effective.add(parentEntry);
        }
    }
    // apply child entries not in parent
    for (AccessControlEntry childEntry : childAcl) {
        if (!parentAcl.contains(childEntry.getPrincipal())) {
            effective.add(childEntry);
        }
    }
    return effective.build();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) PrincipalKey(com.enonic.xp.security.PrincipalKey)

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