Search in sources :

Example 1 with NodeIdExistsException

use of com.enonic.xp.node.NodeIdExistsException in project xp by enonic.

the class CreateNodeCommand method verifyNotExistsAlready.

private void verifyNotExistsAlready() {
    if (this.params.getNodeId() != null) {
        final Node existingNode = doGetById(this.params.getNodeId());
        if (existingNode != null) {
            throw new NodeIdExistsException(existingNode.id());
        }
    }
    NodePath nodePath = NodePath.create(params.getParent(), params.getName()).build();
    CheckNodeExistsCommand.create(this).nodePath(nodePath).throwIfExists().build().execute();
}
Also used : NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath)

Example 2 with NodeIdExistsException

use of com.enonic.xp.node.NodeIdExistsException 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 3 with NodeIdExistsException

use of com.enonic.xp.node.NodeIdExistsException 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 4 with NodeIdExistsException

use of com.enonic.xp.node.NodeIdExistsException 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)

Example 5 with NodeIdExistsException

use of com.enonic.xp.node.NodeIdExistsException in project xp by enonic.

the class SecurityServiceImpl method createIdProvider.

@Override
public IdProvider createIdProvider(final CreateIdProviderParams createIdProviderParams) {
    final PropertyTree data = new PropertyTree();
    data.setString(IdProviderPropertyNames.DISPLAY_NAME_KEY, createIdProviderParams.getDisplayName());
    data.setString(IdProviderPropertyNames.DESCRIPTION_KEY, createIdProviderParams.getDescription());
    final IdProviderConfig idProviderConfig = createIdProviderParams.getIdProviderConfig();
    if (idProviderConfig != null) {
        data.setString(IdProviderPropertyNames.ID_PROVIDER_APPLICATION_KEY, idProviderConfig.getApplicationKey().toString());
        data.setSet(IdProviderPropertyNames.ID_PROVIDER_CONFIG_FORM_KEY, idProviderConfig.getConfig().getRoot());
    }
    try {
        final Node node = callWithContext(() -> {
            final IdProviderAccessControlList permissions = createIdProviderParams.getIdProviderPermissions();
            AccessControlList idProviderNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToIdProviderNodePermissions(permissions);
            AccessControlList usersNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToUsersNodePermissions(permissions);
            AccessControlList groupsNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToGroupsNodePermissions(permissions);
            final Node rootNode = nodeService.getRoot();
            idProviderNodePermissions = mergeWithRootPermissions(idProviderNodePermissions, rootNode.getPermissions());
            usersNodePermissions = mergeWithRootPermissions(usersNodePermissions, rootNode.getPermissions());
            groupsNodePermissions = mergeWithRootPermissions(groupsNodePermissions, rootNode.getPermissions());
            final Node idProviderNode = nodeService.create(CreateNodeParams.create().parent(IdProviderNodeTranslator.getIdProvidersParentPath()).name(createIdProviderParams.getKey().toString()).data(data).permissions(idProviderNodePermissions).build());
            nodeService.create(CreateNodeParams.create().parent(idProviderNode.path()).name(IdProviderNodeTranslator.USER_FOLDER_NODE_NAME).permissions(usersNodePermissions).build());
            nodeService.create(CreateNodeParams.create().parent(idProviderNode.path()).name(IdProviderNodeTranslator.GROUP_FOLDER_NODE_NAME).permissions(groupsNodePermissions).build());
            final ApplyNodePermissionsParams applyPermissions = ApplyNodePermissionsParams.create().nodeId(rootNode.id()).overwriteChildPermissions(false).build();
            nodeService.applyPermissions(applyPermissions);
            this.nodeService.refresh(RefreshMode.SEARCH);
            return idProviderNode;
        });
        return IdProviderNodeTranslator.fromNode(node);
    } catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
        throw new IdProviderAlreadyExistsException(createIdProviderParams.getKey());
    }
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) ApplyNodePermissionsParams(com.enonic.xp.node.ApplyNodePermissionsParams) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) IdProviderAlreadyExistsException(com.enonic.xp.security.IdProviderAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) IdProviderConfig(com.enonic.xp.security.IdProviderConfig)

Aggregations

Node (com.enonic.xp.node.Node)5 NodeIdExistsException (com.enonic.xp.node.NodeIdExistsException)5 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)4 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)3 PrincipalAlreadyExistsException (com.enonic.xp.security.PrincipalAlreadyExistsException)3 PropertyTree (com.enonic.xp.data.PropertyTree)1 ApplyNodePermissionsParams (com.enonic.xp.node.ApplyNodePermissionsParams)1 NodePath (com.enonic.xp.node.NodePath)1 Group (com.enonic.xp.security.Group)1 IdProviderAlreadyExistsException (com.enonic.xp.security.IdProviderAlreadyExistsException)1 IdProviderConfig (com.enonic.xp.security.IdProviderConfig)1 Role (com.enonic.xp.security.Role)1 User (com.enonic.xp.security.User)1 AccessControlList (com.enonic.xp.security.acl.AccessControlList)1 IdProviderAccessControlList (com.enonic.xp.security.acl.IdProviderAccessControlList)1