use of com.enonic.xp.security.PrincipalKey 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.PrincipalKey in project xp by enonic.
the class SecurityServiceImpl method doRemoveMemberships.
private void doRemoveMemberships(final PrincipalKey member) {
final PrincipalKeys memberships = queryDirectMemberships(member);
if (memberships.isEmpty()) {
return;
}
for (PrincipalKey from : memberships) {
final PrincipalRelationship relationship = PrincipalRelationship.from(from).to(member);
final UpdateNodeParams updateNodeParams = PrincipalNodeTranslator.removeRelationshipToUpdateNodeParams(relationship);
nodeService.update(updateNodeParams);
}
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class PrincipalNodeTranslator method relationshipsFromNode.
static PrincipalRelationships relationshipsFromNode(final Node node) {
final PropertyTree rootDataSet = node.data();
final List<Property> members = rootDataSet.getProperties(PrincipalPropertyNames.MEMBER_KEY);
if (members == null || members.isEmpty()) {
return PrincipalRelationships.empty();
}
final ImmutableList.Builder<PrincipalRelationship> relationships = ImmutableList.builder();
final PrincipalKey relationshipFrom = PrincipalKeyNodeTranslator.toKey(node);
for (Property member : members) {
final String memberKey = member.getValue().asString();
final PrincipalKey relationshipTo = PrincipalKey.from(memberKey);
final PrincipalRelationship relationship = PrincipalRelationship.from(relationshipFrom).to(relationshipTo);
relationships.add(relationship);
}
return PrincipalRelationships.from(relationships.build());
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class SecurityServiceImplTest method testUpdateUserDuplicatedEmail.
@Test
public void testUpdateUserDuplicatedEmail() {
try {
runAsAdmin(() -> {
final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("same_email@enonic.com").login("User1").password("123456").build();
final PrincipalKey userKey2 = PrincipalKey.ofUser(SYSTEM, "user2");
final CreateUserParams createUser2 = CreateUserParams.create().userKey(userKey2).displayName("User 2").email("same_email@enonic.com").login("user2").build();
final User user1 = securityService.createUser(createUser1);
securityService.createUser(createUser2);
final UpdateUserParams updateUserParams = UpdateUserParams.create(user1).email("same_email@enonic.com").build();
securityService.updateUser(updateUserParams);
refresh();
});
fail("Expected exception");
} catch (IllegalArgumentException e) {
assertEquals("A user with email 'same_email@enonic.com' already exists in id provider 'system'", e.getMessage());
}
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class SecurityServiceImplTest method testCreateUserDuplicatedEmail.
@Test
public void testCreateUserDuplicatedEmail() {
try {
runAsAdmin(() -> {
final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("same_email@enonic.com").login("User1").password("123456").build();
final PrincipalKey userKey2 = PrincipalKey.ofUser(SYSTEM, "user2");
final CreateUserParams createUser2 = CreateUserParams.create().userKey(userKey2).displayName("User 2").email("same_email@enonic.com").login("user2").build();
securityService.createUser(createUser1);
securityService.createUser(createUser2);
});
fail("Expected exception");
} catch (IllegalArgumentException e) {
assertEquals("A user with email 'same_email@enonic.com' already exists in id provider 'system'", e.getMessage());
}
}
Aggregations