Search in sources :

Example 21 with ServiceLayerException

use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.

the class UserServiceInternalImpl method getAllUsers.

@Override
public List<User> getAllUsers(int offset, int limit, String sort) throws ServiceLayerException {
    Map<String, Object> params = new HashMap<>();
    params.put(OFFSET, offset);
    params.put(LIMIT, limit);
    params.put(SORT, sort);
    try {
        return userDao.getAllUsers(params);
    } catch (Exception e) {
        throw new ServiceLayerException("Unknown database error", e);
    }
}
Also used : HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) PasswordDoesNotMatchException(org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException) UserAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) UserExternallyManagedException(org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException) PasswordRequirementsFailedException(org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Example 22 with ServiceLayerException

use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.

the class UserServiceInternalImpl method getAllUsersForSite.

@Override
public List<User> getAllUsersForSite(long orgId, List<String> groupNames, int offset, int limit, String sort) throws ServiceLayerException {
    Map<String, Object> params = new HashMap<>();
    params.put(GROUP_NAMES, groupNames);
    params.put(OFFSET, offset);
    params.put(LIMIT, limit);
    params.put(SORT, StringUtils.EMPTY);
    try {
        return userDao.getAllUsersForSite(params);
    } catch (Exception e) {
        throw new ServiceLayerException("Unknown database error", e);
    }
}
Also used : HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) PasswordDoesNotMatchException(org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException) UserAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) UserExternallyManagedException(org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException) PasswordRequirementsFailedException(org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Example 23 with ServiceLayerException

use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.

the class UserServiceInternalImpl method getUserByIdOrUsername.

@Override
public User getUserByIdOrUsername(long userId, String username) throws ServiceLayerException, UserNotFoundException {
    Map<String, Object> params = new HashMap<>();
    params.put(USER_ID, userId);
    params.put(USERNAME, username);
    User user;
    try {
        user = userDao.getUserByIdOrUsername(params);
    } catch (Exception e) {
        throw new ServiceLayerException("Unknown database error", e);
    }
    if (user == null) {
        throw new UserNotFoundException("No user found for username '" + username + "' or id '" + userId + "'");
    }
    return user;
}
Also used : UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) User(org.craftercms.studio.api.v2.dal.User) HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) PasswordDoesNotMatchException(org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException) UserAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) UserExternallyManagedException(org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException) PasswordRequirementsFailedException(org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Example 24 with ServiceLayerException

use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.

the class GroupServiceImpl method updateGroup.

@Override
@HasPermission(type = DefaultPermission.class, action = "update_groups")
public Group updateGroup(long orgId, Group group) throws ServiceLayerException, GroupNotFoundException, AuthenticationException {
    Group toRet = groupServiceInternal.updateGroup(orgId, group);
    SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_UPDATE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(userService.getCurrentUser().getUsername());
    auditLog.setPrimaryTargetId(group.getGroupName());
    auditLog.setPrimaryTargetType(TARGET_TYPE_GROUP);
    auditLog.setPrimaryTargetValue(group.getGroupName());
    auditServiceInternal.insertAuditLog(auditLog);
    return toRet;
}
Also used : Group(org.craftercms.studio.api.v2.dal.Group) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 25 with ServiceLayerException

use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.

the class GroupServiceImpl method removeGroupMembers.

@Override
@HasPermission(type = DefaultPermission.class, action = "update_groups")
public void removeGroupMembers(long groupId, List<Long> userIds, List<String> usernames) throws ServiceLayerException, UserNotFoundException, GroupNotFoundException, AuthenticationException {
    Group group = getGroup(groupId);
    generalLockService.lock(REMOVE_SYSTEM_ADMIN_MEMBER_LOCK);
    try {
        if (group.getGroupName().equals(SYSTEM_ADMIN_GROUP)) {
            List<User> members = getGroupMembers(groupId, 0, Integer.MAX_VALUE, StringUtils.EMPTY);
            if (CollectionUtils.isNotEmpty(members)) {
                List<User> membersAfterRemove = new ArrayList<User>();
                membersAfterRemove.addAll(members);
                members.forEach(m -> {
                    if (CollectionUtils.isNotEmpty(userIds)) {
                        if (userIds.contains(m.getId())) {
                            membersAfterRemove.remove(m);
                        }
                    }
                    if (CollectionUtils.isNotEmpty(usernames)) {
                        if (usernames.contains(m.getUsername())) {
                            membersAfterRemove.remove(m);
                        }
                    }
                });
                if (CollectionUtils.isEmpty(membersAfterRemove)) {
                    throw new ServiceLayerException("Removing all members of the System Admin group is not allowed." + " We must have at least one system administrator.");
                }
            }
        }
        List<User> users = userServiceInternal.getUsersByIdOrUsername(userIds, usernames);
        groupServiceInternal.removeGroupMembers(groupId, userIds, usernames);
        SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
        AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
        auditLog.setOperation(OPERATION_REMOVE_MEMBERS);
        auditLog.setActorId(userService.getCurrentUser().getUsername());
        auditLog.setSiteId(siteFeed.getId());
        auditLog.setPrimaryTargetId(Long.toString(group.getId()));
        auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
        auditLog.setPrimaryTargetValue(group.getGroupName());
        List<AuditLogParameter> paramters = new ArrayList<AuditLogParameter>();
        for (User user : users) {
            AuditLogParameter paramter = new AuditLogParameter();
            paramter.setTargetId(Long.toString(user.getId()));
            paramter.setTargetType(TARGET_TYPE_USER);
            paramter.setTargetValue(user.getUsername());
            paramters.add(paramter);
        }
        auditLog.setParameters(paramters);
        auditServiceInternal.insertAuditLog(auditLog);
    } finally {
        generalLockService.unlock(REMOVE_SYSTEM_ADMIN_MEMBER_LOCK);
    }
}
Also used : Group(org.craftercms.studio.api.v2.dal.Group) User(org.craftercms.studio.api.v2.dal.User) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ArrayList(java.util.ArrayList) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) AuditLogParameter(org.craftercms.studio.api.v2.dal.AuditLogParameter) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Aggregations

ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)124 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)62 HashMap (java.util.HashMap)55 ArrayList (java.util.ArrayList)45 IOException (java.io.IOException)39 User (org.craftercms.studio.api.v2.dal.User)36 Repository (org.eclipse.jgit.lib.Repository)35 Git (org.eclipse.jgit.api.Git)33 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)33 ContentRepository (org.craftercms.studio.api.v1.repository.ContentRepository)32 RemoteRepository (org.craftercms.studio.api.v2.dal.RemoteRepository)30 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)29 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)29 CryptoException (org.craftercms.commons.crypto.CryptoException)28 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)27 GitRepositoryHelper (org.craftercms.studio.api.v2.utils.GitRepositoryHelper)24 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)23 Path (java.nio.file.Path)21 InvalidRemoteUrlException (org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException)21 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)20