Search in sources :

Example 1 with Principal

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

the class PrincipalsResultMapperTest method testGroupsSerialized.

@Test
public void testGroupsSerialized() throws Exception {
    final Principal group1 = Group.create().key(PrincipalKey.ofGroup(IdProviderKey.system(), "group1")).displayName("Group1").modifiedTime(Instant.now(clock)).description("description1").build();
    final Principal group2 = Group.create().key(PrincipalKey.ofGroup(IdProviderKey.system(), "group2")).displayName("Group2").modifiedTime(Instant.now(clock)).description("description2").build();
    final PrincipalsResultMapper principalsResultMapper = new PrincipalsResultMapper(Principals.from(group1, group2), 5);
    JsonAssert.assertJson(getClass(), "groupPrincipals", principalsResultMapper);
}
Also used : Principal(com.enonic.xp.security.Principal) Test(org.junit.jupiter.api.Test)

Example 2 with Principal

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

the class PrincipalsResultMapperTest method createUserPrincipals.

private Principals createUserPrincipals() {
    final Principal user1 = User.create().key(PrincipalKey.ofUser(IdProviderKey.from("enonic"), "user1")).displayName("User 1").modifiedTime(Instant.now(clock)).email("user1@enonic.com").login("user1").build();
    final Principal user2 = User.create().key(PrincipalKey.ofUser(IdProviderKey.from("enonic"), "user2")).displayName("User 2").modifiedTime(Instant.now(clock)).email("user2@enonic.com").login("user2").build();
    return Principals.from(user1, user2);
}
Also used : Principal(com.enonic.xp.security.Principal)

Example 3 with Principal

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

the class SecurityServiceImpl method resolveMemberships.

private PrincipalKeys resolveMemberships(final PrincipalKey userKey) {
    final PrincipalKeys directMemberships = queryDirectMemberships(userKey);
    final Set<PrincipalKey> resolvedMemberships = new LinkedHashSet<>(directMemberships.getSet());
    final Set<PrincipalKey> queriedMemberships = new LinkedHashSet<>();
    do {
        final Set<PrincipalKey> newMemberships = new LinkedHashSet<>();
        resolvedMemberships.stream().filter(principal -> !queriedMemberships.contains(principal)).forEach(principal -> {
            final PrincipalKeys indirectMemberships = queryDirectMemberships(principal);
            newMemberships.addAll(indirectMemberships.getSet());
            queriedMemberships.add(principal);
        });
        resolvedMemberships.addAll(newMemberships);
    } while (resolvedMemberships.size() > queriedMemberships.size());
    return PrincipalKeys.from(resolvedMemberships);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Nodes(com.enonic.xp.node.Nodes) ValueExpr(com.enonic.xp.query.expr.ValueExpr) IdProviderKey(com.enonic.xp.security.IdProviderKey) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) FieldExpr(com.enonic.xp.query.expr.FieldExpr) CreateGroupParams(com.enonic.xp.security.CreateGroupParams) IndexService(com.enonic.xp.index.IndexService) ValueFilter(com.enonic.xp.query.filter.ValueFilter) Role(com.enonic.xp.security.Role) SecureRandom(java.security.SecureRandom) Matcher(java.util.regex.Matcher) LogicalExpr(com.enonic.xp.query.expr.LogicalExpr) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeService(com.enonic.xp.node.NodeService) AuthenticationException(com.enonic.xp.security.auth.AuthenticationException) ContextBuilder(com.enonic.xp.context.ContextBuilder) VerifiedEmailAuthToken(com.enonic.xp.security.auth.VerifiedEmailAuthToken) QueryExpr(com.enonic.xp.query.expr.QueryExpr) UpdateIdProviderParams(com.enonic.xp.security.UpdateIdProviderParams) SystemConstants(com.enonic.xp.security.SystemConstants) SecurityService(com.enonic.xp.security.SecurityService) UserQueryResult(com.enonic.xp.security.UserQueryResult) IdProviderNotFoundException(com.enonic.xp.security.IdProviderNotFoundException) UpdateRoleParams(com.enonic.xp.security.UpdateRoleParams) CreateUserParams(com.enonic.xp.security.CreateUserParams) User(com.enonic.xp.security.User) DEFAULT_ID_PROVIDER_ACL(com.enonic.xp.core.impl.security.SecurityInitializer.DEFAULT_ID_PROVIDER_ACL) PrincipalRelationship(com.enonic.xp.security.PrincipalRelationship) PrincipalType(com.enonic.xp.security.PrincipalType) Set(java.util.Set) ValueFactory(com.enonic.xp.data.ValueFactory) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) Objects(java.util.Objects) List(java.util.List) SecurityConstants(com.enonic.xp.security.SecurityConstants) Optional(java.util.Optional) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) Pattern(java.util.regex.Pattern) IdProvider(com.enonic.xp.security.IdProvider) HashFunction(com.google.common.hash.HashFunction) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) RefreshMode(com.enonic.xp.node.RefreshMode) CreateRoleParams(com.enonic.xp.security.CreateRoleParams) CompareExpr(com.enonic.xp.query.expr.CompareExpr) UpdateUserParams(com.enonic.xp.security.UpdateUserParams) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Callable(java.util.concurrent.Callable) Hashing(com.google.common.hash.Hashing) UsernamePasswordAuthToken(com.enonic.xp.security.auth.UsernamePasswordAuthToken) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) UserQuery(com.enonic.xp.security.UserQuery) Strings(com.google.common.base.Strings) Charset(java.nio.charset.Charset) ImmutableList(com.google.common.collect.ImmutableList) VerifiedUsernameAuthToken(com.enonic.xp.security.auth.VerifiedUsernameAuthToken) PrincipalQuery(com.enonic.xp.security.PrincipalQuery) NodeQuery(com.enonic.xp.node.NodeQuery) IdProviderConfig(com.enonic.xp.security.IdProviderConfig) PrincipalNotFoundException(com.enonic.xp.security.PrincipalNotFoundException) EmailPasswordAuthToken(com.enonic.xp.security.auth.EmailPasswordAuthToken) LinkedHashSet(java.util.LinkedHashSet) PropertyTree(com.enonic.xp.data.PropertyTree) Group(com.enonic.xp.security.Group) IdProviders(com.enonic.xp.security.IdProviders) AuthenticationToken(com.enonic.xp.security.auth.AuthenticationToken) Striped(com.google.common.util.concurrent.Striped) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) Principal(com.enonic.xp.security.Principal) NodePath(com.enonic.xp.node.NodePath) UpdateGroupParams(com.enonic.xp.security.UpdateGroupParams) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Ints(com.google.common.primitives.Ints) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) PrincipalQueryResult(com.enonic.xp.security.PrincipalQueryResult) Lock(java.util.concurrent.locks.Lock) Principals(com.enonic.xp.security.Principals) CreateIdProviderParams(com.enonic.xp.security.CreateIdProviderParams) IdProviderAlreadyExistsException(com.enonic.xp.security.IdProviderAlreadyExistsException) PrincipalKey(com.enonic.xp.security.PrincipalKey) ApplyNodePermissionsParams(com.enonic.xp.node.ApplyNodePermissionsParams) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) PrincipalAlreadyExistsException(com.enonic.xp.security.PrincipalAlreadyExistsException) Clock(java.time.Clock) Preconditions(com.google.common.base.Preconditions) NodeIds(com.enonic.xp.node.NodeIds) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 4 with Principal

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

the class PrincipalsResultMapper method serialize.

private void serialize(final MapGenerator gen, final Principals principals) {
    gen.array("hits");
    for (final Principal principal : principals) {
        gen.map();
        new PrincipalMapper(principal, detailed).serialize(gen);
        gen.end();
    }
    gen.end();
}
Also used : PrincipalMapper(com.enonic.xp.lib.common.PrincipalMapper) Principal(com.enonic.xp.security.Principal)

Example 5 with Principal

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

the class PrincipalsResultMapperTest method testRolesSerialized.

@Test
public void testRolesSerialized() throws Exception {
    final Principal role1 = Role.create().key(PrincipalKey.ofRole("Role 1")).displayName("Role 1 Display Name").modifiedTime(Instant.now(clock)).description("description1").build();
    final Principal role2 = Role.create().key(PrincipalKey.ofRole("Role 2")).displayName("Role 2 Display Name").modifiedTime(Instant.now(clock)).description("description2").build();
    final PrincipalsResultMapper principalsResultMapper = new PrincipalsResultMapper(Principals.from(role1, role2), 3);
    JsonAssert.assertJson(getClass(), "rolePrincipals", principalsResultMapper);
}
Also used : Principal(com.enonic.xp.security.Principal) Test(org.junit.jupiter.api.Test)

Aggregations

Principal (com.enonic.xp.security.Principal)5 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 DEFAULT_ID_PROVIDER_ACL (com.enonic.xp.core.impl.security.SecurityInitializer.DEFAULT_ID_PROVIDER_ACL)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 ValueFactory (com.enonic.xp.data.ValueFactory)1 IndexService (com.enonic.xp.index.IndexService)1 PrincipalMapper (com.enonic.xp.lib.common.PrincipalMapper)1 ApplyNodePermissionsParams (com.enonic.xp.node.ApplyNodePermissionsParams)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)1 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1 Node (com.enonic.xp.node.Node)1 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)1 NodeId (com.enonic.xp.node.NodeId)1 NodeIdExistsException (com.enonic.xp.node.NodeIdExistsException)1 NodeIds (com.enonic.xp.node.NodeIds)1 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)1