Search in sources :

Example 41 with PrincipalKey

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

the class UserNodeTranslatorTest method toUser.

@Test
public void toUser() throws Exception {
    final PrincipalKey userKey = PrincipalKey.ofUser(IdProviderKey.system(), "i-am-a-user");
    final PropertyTree rootDataSet = new PropertyTree();
    rootDataSet.setString(PrincipalPropertyNames.LOGIN_KEY, "loginkey");
    rootDataSet.setString(PrincipalPropertyNames.EMAIL_KEY, "rmy@enonic.com");
    rootDataSet.setString(PrincipalPropertyNames.DISPLAY_NAME_KEY, "displayname");
    rootDataSet.setString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY, userKey.getType().toString());
    rootDataSet.setString(PrincipalPropertyNames.ID_PROVIDER_KEY, userKey.getIdProviderKey().toString());
    rootDataSet.setString(PrincipalPropertyNames.AUTHENTICATION_HASH_KEY, "clear:password");
    final Node node = Node.create().id(NodeId.from("id")).name(PrincipalKeyNodeTranslator.toNodeName(userKey)).data(rootDataSet).build();
    final User user = (User) PrincipalNodeTranslator.fromNode(node);
    assertEquals("loginkey", user.getLogin());
    assertEquals("rmy@enonic.com", user.getEmail());
    assertEquals(userKey, user.getKey());
    assertEquals("clear:password", user.getAuthenticationHash());
}
Also used : User(com.enonic.xp.security.User) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 42 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 43 with PrincipalKey

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

the class IssueCommentQueryNodeQueryTranslator method translate.

public static NodeQuery translate(final IssueCommentQuery issueCommentQuery, NodeName parentName) {
    final NodeQuery.Builder builder = NodeQuery.create();
    builder.parent(NodePath.create(IssueConstants.ISSUE_ROOT_PATH, parentName.toString()).build());
    final ValueFilter issueCommentsCollectionFilter = ValueFilter.create().fieldName(NodeIndexPath.NODE_TYPE.getPath()).addValue(ValueFactory.newString(IssueCommentConstants.NODE_COLLECTION.getName())).build();
    if (issueCommentQuery.isCount()) {
        builder.searchMode(SearchMode.COUNT);
    }
    builder.from(issueCommentQuery.getFrom()).size(issueCommentQuery.getSize()).addQueryFilter(issueCommentsCollectionFilter);
    final PrincipalKey creator = issueCommentQuery.getCreator();
    if (creator != null) {
        builder.addQueryFilter(ValueFilter.create().fieldName(CREATOR).addValues(creator.toString()).build());
    }
    builder.setOrderExpressions(issueCommentQuery.getOrder().getOrderExpressions());
    return builder.build();
}
Also used : NodeQuery(com.enonic.xp.node.NodeQuery) ValueFilter(com.enonic.xp.query.filter.ValueFilter) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 44 with PrincipalKey

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

the class IssueQueryNodeQueryTranslator method translate.

public static NodeQuery translate(final IssueQuery issueQuery) {
    final NodeQuery.Builder builder = NodeQuery.create();
    final ValueFilter issueCollectionFilter = ValueFilter.create().fieldName(NodeIndexPath.NODE_TYPE.getPath()).addValue(ValueFactory.newString(IssueConstants.ISSUE_NODE_COLLECTION.getName())).build();
    if (issueQuery.isCount()) {
        builder.searchMode(SearchMode.COUNT);
    }
    builder.from(issueQuery.getFrom()).size(issueQuery.getSize()).addQueryFilter(issueCollectionFilter);
    final PrincipalKey creator = issueQuery.getCreator();
    if (creator != null) {
        builder.addQueryFilter(ValueFilter.create().fieldName(CREATOR).addValues(creator.toString()).build());
    }
    final PrincipalKeys approvers = issueQuery.getApprovers();
    if (approvers != null && approvers.isNotEmpty()) {
        builder.addQueryFilter(ValueFilter.create().fieldName(APPROVERS).addValues(approvers.stream().map(PrincipalKey::toString).collect(toList())).build());
    }
    final ContentIds items = issueQuery.getItems();
    if (items != null && items.isNotEmpty()) {
        builder.addQueryFilter(ValueFilter.create().fieldName(PUBLISH_REQUEST_ITEM_ID).addValues(items.stream().map(ContentId::toString).collect(toList())).build());
    }
    final IssueStatus status = issueQuery.getStatus();
    if (status != null) {
        builder.addQueryFilter(ValueFilter.create().fieldName(STATUS).addValues(status.toString()).build());
    }
    final IssueType type = issueQuery.getType();
    if (type != null) {
        final Filter isOfType = ValueFilter.create().fieldName(TYPE).addValues(type.toString()).build();
        if (type == IssueType.STANDARD) {
            final Filter notExists = BooleanFilter.create().mustNot(ExistsFilter.create().fieldName(TYPE).build()).build();
            final Filter isStandard = BooleanFilter.create().should(isOfType).should(notExists).build();
            builder.addQueryFilter(isStandard);
        } else {
            builder.addQueryFilter(isOfType);
        }
    }
    builder.setOrderExpressions(IssueConstants.DEFAULT_CHILD_ORDER.getOrderExpressions());
    return builder.build();
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) ValueFilter(com.enonic.xp.query.filter.ValueFilter) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) Filter(com.enonic.xp.query.filter.Filter) IssueType(com.enonic.xp.issue.IssueType) NodeQuery(com.enonic.xp.node.NodeQuery) ContentIds(com.enonic.xp.content.ContentIds) ValueFilter(com.enonic.xp.query.filter.ValueFilter) ContentId(com.enonic.xp.content.ContentId) PrincipalKey(com.enonic.xp.security.PrincipalKey) IssueStatus(com.enonic.xp.issue.IssueStatus)

Example 45 with PrincipalKey

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

the class UpdateProjectRolesCommand method doSetRoleMembers.

private Set<PrincipalKey> doSetRoleMembers(final ProjectRole projectRole) {
    final PrincipalKey roleKey = ProjectAccessHelper.createRoleKey(projectName, projectRole);
    final PrincipalRelationships currRoleMembers = securityService.getRelationships(roleKey);
    final PrincipalKeys newRoleMembers = this.permissions.getPermission(projectRole);
    doGetAddedMembers(currRoleMembers, newRoleMembers, roleKey).forEach(securityService::addRelationship);
    doGetRemovedMembers(currRoleMembers, newRoleMembers).forEach(securityService::removeRelationship);
    return securityService.getRelationships(roleKey).stream().map(PrincipalRelationship::getTo).collect(Collectors.toSet());
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalKey(com.enonic.xp.security.PrincipalKey) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships)

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