Search in sources :

Example 1 with PrincipalAlreadyExistsException

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

the class SecurityServiceImpl method doCreateUser.

private User doCreateUser(final CreateUserParams createUser) {
    final User user = User.create().key(createUser.getKey()).login(createUser.getLogin()).email(createUser.getEmail()).displayName(createUser.getDisplayName()).modifiedTime(Instant.now(clock)).build();
    final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(user);
    try {
        final Node node = callWithContext(() -> {
            final Node createdNode = nodeService.create(createNodeParams);
            this.nodeService.refresh(RefreshMode.SEARCH);
            return createdNode;
        });
        if (createUser.getPassword() != null) {
            return setPassword(user.getKey(), createUser.getPassword());
        }
        return PrincipalNodeTranslator.userFromNode(node);
    } catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
        throw new PrincipalAlreadyExistsException(createUser.getKey());
    }
}
Also used : User(com.enonic.xp.security.User) PrincipalAlreadyExistsException(com.enonic.xp.security.PrincipalAlreadyExistsException) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 2 with PrincipalAlreadyExistsException

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

Example 3 with PrincipalAlreadyExistsException

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

Aggregations

CreateNodeParams (com.enonic.xp.node.CreateNodeParams)3 Node (com.enonic.xp.node.Node)3 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)3 NodeIdExistsException (com.enonic.xp.node.NodeIdExistsException)3 PrincipalAlreadyExistsException (com.enonic.xp.security.PrincipalAlreadyExistsException)3 Group (com.enonic.xp.security.Group)1 Role (com.enonic.xp.security.Role)1 User (com.enonic.xp.security.User)1