use of com.enonic.xp.security.Group in project xp by enonic.
the class GetMembersHandlerTest method testGetNoMembers.
@Test
public void testGetNoMembers() {
final Group group = TestDataFixtures.getTestGroup();
final PrincipalRelationships relationships = PrincipalRelationships.empty();
Mockito.when(securityService.getRelationships(group.getKey())).thenReturn(relationships);
Mockito.when(securityService.getPrincipals(PrincipalKeys.empty())).thenReturn(Principals.empty());
runFunction("/test/getMembers-test.js", "getNoMembers");
}
use of com.enonic.xp.security.Group in project xp by enonic.
the class GetMembershipsHandlerTest method testGetTransitiveUserMemberships.
@Test
public void testGetTransitiveUserMemberships() {
final Group group = TestDataFixtures.getTestGroup();
final PrincipalKeys principalKeys = PrincipalKeys.from(group.getKey());
final PrincipalKey pKey = PrincipalKey.from("user:myIdProvider:userId");
Mockito.when(securityService.getAllMemberships(pKey)).thenReturn(principalKeys);
Mockito.verify(securityService, Mockito.never()).getMemberships(pKey);
Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(group));
runFunction("/test/getMemberships-test.js", "getTransitiveUserMemberships");
}
use of com.enonic.xp.security.Group in project xp by enonic.
the class SecurityServiceImplTest method testUpdateGroup.
@Test
public void testUpdateGroup() throws Exception {
runAsAdmin(() -> {
final CreateGroupParams createGroup = CreateGroupParams.create().groupKey(PrincipalKey.ofGroup(SYSTEM, "Group-a")).displayName("Group A").build();
final Group group = securityService.createGroup(createGroup);
refresh();
final UpdateGroupParams groupUpdate = UpdateGroupParams.create(group).displayName("___Group B___").description("description").build();
final Group updatedGroupResult = securityService.updateGroup(groupUpdate);
refresh();
final Group updatedGroup = securityService.getGroup(group.getKey()).get();
assertEquals("___Group B___", updatedGroupResult.getDisplayName());
assertEquals("___Group B___", updatedGroup.getDisplayName());
assertEquals("description", updatedGroupResult.getDescription());
assertEquals("description", updatedGroup.getDescription());
});
}
use of com.enonic.xp.security.Group in project xp by enonic.
the class SecurityServiceImpl method createGroup.
@Override
public Group createGroup(final CreateGroupParams createGroup) {
final Group group = Group.create().key(createGroup.getKey()).displayName(createGroup.getDisplayName()).modifiedTime(Instant.now(clock)).description(createGroup.getDescription()).build();
final CreateNodeParams createGroupParams = PrincipalNodeTranslator.toCreateNodeParams(group);
try {
final Node node = callWithContext(() -> {
final Node createdNode = this.nodeService.create(createGroupParams);
this.nodeService.refresh(RefreshMode.SEARCH);
return createdNode;
});
return PrincipalNodeTranslator.groupFromNode(node);
} catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
throw new PrincipalAlreadyExistsException(createGroup.getKey());
}
}
use of com.enonic.xp.security.Group in project xp by enonic.
the class SecurityServiceImpl method updateGroup.
@Override
public Group updateGroup(final UpdateGroupParams updateGroupParams) {
return callWithContext(() -> {
final Node node = this.nodeService.getByPath(updateGroupParams.getKey().toPath());
if (node == null) {
throw new PrincipalNotFoundException(updateGroupParams.getKey());
}
final Group existingGroup = PrincipalNodeTranslator.groupFromNode(node);
final Group groupToUpdate = updateGroupParams.update(existingGroup);
final UpdateNodeParams updateNodeParams = PrincipalNodeTranslator.toUpdateNodeParams(groupToUpdate);
final Node updatedNode = nodeService.update(updateNodeParams);
this.nodeService.refresh(RefreshMode.SEARCH);
return PrincipalNodeTranslator.groupFromNode(updatedNode);
});
}
Aggregations