Search in sources :

Example 1 with PrincipalNotFoundException

use of com.enonic.xp.security.PrincipalNotFoundException 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);
    });
}
Also used : Group(com.enonic.xp.security.Group) Node(com.enonic.xp.node.Node) PrincipalNotFoundException(com.enonic.xp.security.PrincipalNotFoundException) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams)

Example 2 with PrincipalNotFoundException

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

the class SecurityServiceImpl method doUpdateUser.

private User doUpdateUser(final UpdateUserParams updateUserParams) {
    return callWithContext(() -> {
        final Node node = this.nodeService.getByPath(updateUserParams.getKey().toPath());
        if (node == null) {
            throw new PrincipalNotFoundException(updateUserParams.getKey());
        }
        final User existingUser = PrincipalNodeTranslator.userFromNode(node);
        final User userToUpdate = updateUserParams.update(existingUser);
        duplicateEmailValidation(userToUpdate.getKey(), userToUpdate.getEmail());
        final UpdateNodeParams updateNodeParams = PrincipalNodeTranslator.toUpdateNodeParams(userToUpdate);
        final Node updatedNode = nodeService.update(updateNodeParams);
        this.nodeService.refresh(RefreshMode.SEARCH);
        return PrincipalNodeTranslator.userFromNode(updatedNode);
    });
}
Also used : User(com.enonic.xp.security.User) Node(com.enonic.xp.node.Node) PrincipalNotFoundException(com.enonic.xp.security.PrincipalNotFoundException) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams)

Example 3 with PrincipalNotFoundException

use of com.enonic.xp.security.PrincipalNotFoundException 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);
    });
}
Also used : Role(com.enonic.xp.security.Role) Node(com.enonic.xp.node.Node) PrincipalNotFoundException(com.enonic.xp.security.PrincipalNotFoundException) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams)

Example 4 with PrincipalNotFoundException

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

the class DeletePrincipalHandlerTest method testDeleteNonExistingUser.

@Test
public void testDeleteNonExistingUser() {
    final PrincipalKey principalKey = PrincipalKey.from("user:myIdProvider:XXX");
    Mockito.doThrow(new PrincipalNotFoundException(principalKey)).when(securityService).deletePrincipal(principalKey);
    runFunction("/test/deletePrincipal-test.js", "deleteNonExistingUser");
}
Also used : PrincipalNotFoundException(com.enonic.xp.security.PrincipalNotFoundException) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Aggregations

PrincipalNotFoundException (com.enonic.xp.security.PrincipalNotFoundException)4 Node (com.enonic.xp.node.Node)3 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)3 Group (com.enonic.xp.security.Group)1 PrincipalKey (com.enonic.xp.security.PrincipalKey)1 Role (com.enonic.xp.security.Role)1 User (com.enonic.xp.security.User)1 Test (org.junit.jupiter.api.Test)1