Search in sources :

Example 36 with User

use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.

the class UserService method createOrUpdateTechnicalUser.

/**
 * Validates and persists the given {@link User} as technical user.<br/>
 * This functionality is available to all users regardless of their privileges. <br/>
 * Failures in authorization may occur in a broader context, as technical users are created
 * and specifically associated to a {@link org.eclipse.vorto.repository.domain.Namespace}, so the
 * user performing the operation must have the right authorities to do so in context.
 *
 * @param technicalUser
 * @return
 * @throws InvalidUserException
 */
public User createOrUpdateTechnicalUser(User actor, User technicalUser) throws InvalidUserException {
    // boilerplate null validation
    ServiceValidationUtil.validateNulls(technicalUser);
    // validates technical user
    userUtil.validateNewUser(technicalUser);
    // sets createdby for tech user
    technicalUser.setCreatedBy(actor.getId());
    // save the technical user
    User result = userRepository.save(technicalUser);
    if (result != null) {
        eventPublisher.publishEvent(new AppEvent(this, technicalUser.getUsername(), EventType.USER_ADDED));
    }
    return result;
}
Also used : AppEvent(org.eclipse.vorto.repository.core.events.AppEvent) User(org.eclipse.vorto.repository.domain.User)

Aggregations

User (org.eclipse.vorto.repository.domain.User)36 ResponseEntity (org.springframework.http.ResponseEntity)13 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 IUserContext (org.eclipse.vorto.repository.core.IUserContext)8 DoesNotExistException (org.eclipse.vorto.repository.services.exceptions.DoesNotExistException)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 OperationForbiddenException (org.eclipse.vorto.repository.services.exceptions.OperationForbiddenException)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 Optional (java.util.Optional)6 InvalidUserException (org.eclipse.vorto.repository.services.exceptions.InvalidUserException)6 ApiParam (io.swagger.annotations.ApiParam)5 Collection (java.util.Collection)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 DefaultUserAccountService (org.eclipse.vorto.repository.account.impl.DefaultUserAccountService)5 Namespace (org.eclipse.vorto.repository.domain.Namespace)5 NamespaceService (org.eclipse.vorto.repository.services.NamespaceService)5 UserNamespaceRoleService (org.eclipse.vorto.repository.services.UserNamespaceRoleService)5 Test (org.junit.Test)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5