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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations