use of com.enonic.xp.security.Role in project xp by enonic.
the class UpdateProjectRoleNamesCommand method doUpdateRoles.
private void doUpdateRoles() {
for (ProjectRole projectRole : ProjectRole.values()) {
final PrincipalKey roleKey = ProjectAccessHelper.createRoleKey(projectName, projectRole);
final String newRoleDisplayName = createRoleDisplayName(projectRole);
securityService.getRole(roleKey).filter(role -> !newRoleDisplayName.equals(role.getDisplayName())).ifPresent((roleValue) -> doUpdateRoleDisplayName(roleValue, newRoleDisplayName));
}
}
use of com.enonic.xp.security.Role in project xp by enonic.
the class SecurityServiceImplTest method testUpdateRole.
@Test
public void testUpdateRole() throws Exception {
runAsAdmin(() -> {
final CreateRoleParams createRole = CreateRoleParams.create().roleKey(PrincipalKey.ofRole("Role-a")).displayName("Role A").build();
final Role role = securityService.createRole(createRole);
final UpdateRoleParams roleUpdate = UpdateRoleParams.create(role).displayName("___Role B___").description("description").build();
final Role updatedRoleResult = securityService.updateRole(roleUpdate);
refresh();
final Role updatedRole = securityService.getRole(role.getKey()).get();
assertEquals("___Role B___", updatedRoleResult.getDisplayName());
assertEquals("___Role B___", updatedRole.getDisplayName());
assertEquals("description", updatedRoleResult.getDescription());
assertEquals("description", updatedRole.getDescription());
});
}
use of com.enonic.xp.security.Role in project xp by enonic.
the class SecurityServiceImpl method createRole.
@Override
public Role createRole(final CreateRoleParams createRole) {
final Role role = Role.create().key(createRole.getKey()).displayName(createRole.getDisplayName()).modifiedTime(Instant.now(clock)).description(createRole.getDescription()).build();
final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(role);
try {
final Node node = callWithContext(() -> {
final Node createdNode = this.nodeService.create(createNodeParams);
this.nodeService.refresh(RefreshMode.SEARCH);
return createdNode;
});
return PrincipalNodeTranslator.roleFromNode(node);
} catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
throw new PrincipalAlreadyExistsException(createRole.getKey());
}
}
use of com.enonic.xp.security.Role in project xp by enonic.
the class SecurityServiceImplTest method testCreateRole.
@Test
public void testCreateRole() throws Exception {
runAsAdmin(() -> {
final PrincipalKey roleKey1 = PrincipalKey.ofRole("Role-a");
final CreateRoleParams createRole = CreateRoleParams.create().roleKey(roleKey1).displayName("Role A").description("Group A Description").build();
final PrincipalKey roleKey2 = PrincipalKey.ofRole("role-b");
final CreateRoleParams createRole2 = CreateRoleParams.create().roleKey(roleKey2).displayName("Role B").build();
final Role role1 = securityService.createRole(createRole);
final Role role2 = securityService.createRole(createRole2);
final Role createdRole1 = securityService.getRole(roleKey1).get();
final Role createdRole2 = securityService.getRole(roleKey2).get();
assertEquals("Role A", role1.getDisplayName());
assertEquals("Role A", createdRole1.getDisplayName());
assertEquals("Group A Description", role1.getDescription());
assertEquals("Group A Description", createdRole1.getDescription());
assertEquals("Role B", role2.getDisplayName());
assertEquals("Role B", createdRole2.getDisplayName());
assertNull(role2.getDescription());
assertNull(createdRole2.getDescription());
});
}
use of com.enonic.xp.security.Role in project xp by enonic.
the class SecurityServiceImpl method updateRole.
@Override
public Role updateRole(final UpdateRoleParams updateRoleParams) {
return callWithContext(() -> {
final Node node = this.nodeService.getByPath(updateRoleParams.getKey().toPath());
if (node == null) {
throw new PrincipalNotFoundException(updateRoleParams.getKey());
}
final Role existingRole = PrincipalNodeTranslator.roleFromNode(node);
final Role roleToUpdate = updateRoleParams.update(existingRole);
final UpdateNodeParams updateNodeParams = PrincipalNodeTranslator.toUpdateNodeParams(roleToUpdate);
final Node updatedNode = nodeService.update(updateNodeParams);
this.nodeService.refresh(RefreshMode.SEARCH);
return PrincipalNodeTranslator.roleFromNode(updatedNode);
});
}
Aggregations