use of org.craftercms.studio.api.v1.exception.security.GroupNotFoundException in project studio by craftercms.
the class UserServiceImpl method deleteUsers.
@Override
@HasPermission(type = DefaultPermission.class, action = "delete_users")
public void deleteUsers(List<Long> userIds, List<String> usernames) throws ServiceLayerException, AuthenticationException, UserNotFoundException {
User currentUser = getCurrentUser();
if (CollectionUtils.containsAny(userIds, Arrays.asList(currentUser.getId())) || CollectionUtils.containsAny(usernames, Arrays.asList(currentUser.getUsername()))) {
throw new ServiceLayerException("Cannot delete self.");
}
generalLockService.lock(REMOVE_SYSTEM_ADMIN_MEMBER_LOCK);
try {
try {
Group g = groupServiceInternal.getGroupByName(SYSTEM_ADMIN_GROUP);
List<User> members = groupServiceInternal.getGroupMembers(g.getId(), 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.");
}
}
} catch (GroupNotFoundException e) {
throw new ServiceLayerException("The System Admin group is not found.", e);
}
List<User> toDelete = userServiceInternal.getUsersByIdOrUsername(userIds, usernames);
userServiceInternal.deleteUsers(userIds, usernames);
SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_DELETE);
auditLog.setActorId(getCurrentUser().getUsername());
auditLog.setPrimaryTargetId(siteFeed.getSiteId());
auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
auditLog.setPrimaryTargetValue(siteFeed.getName());
List<AuditLogParameter> paramters = new ArrayList<AuditLogParameter>();
for (User deletedUser : toDelete) {
AuditLogParameter paramter = new AuditLogParameter();
paramter.setTargetId(Long.toString(deletedUser.getId()));
paramter.setTargetType(TARGET_TYPE_USER);
paramter.setTargetValue(deletedUser.getUsername());
paramters.add(paramter);
}
auditLog.setParameters(paramters);
auditServiceInternal.insertAuditLog(auditLog);
} finally {
generalLockService.unlock(REMOVE_SYSTEM_ADMIN_MEMBER_LOCK);
}
}
use of org.craftercms.studio.api.v1.exception.security.GroupNotFoundException in project studio by craftercms.
the class GroupServiceInternalImpl method deleteGroup.
@RetryingOperation
@Override
public void deleteGroup(List<Long> groupIds) throws GroupNotFoundException, ServiceLayerException {
for (Long groupId : groupIds) {
if (!groupExists(groupId, StringUtils.EMPTY)) {
throw new GroupNotFoundException("No group found for id '" + groupId + "'");
}
}
Map<String, Object> params = new HashMap<>();
params.put(GROUP_IDS, groupIds);
try {
groupDao.deleteGroups(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
use of org.craftercms.studio.api.v1.exception.security.GroupNotFoundException in project studio by craftercms.
the class GroupServiceInternalImpl method getGroup.
@Override
public Group getGroup(long groupId) throws GroupNotFoundException, ServiceLayerException {
Map<String, Object> params = new HashMap<>();
params.put(GROUP_ID, groupId);
Group group;
try {
group = groupDao.getGroup(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
if (group != null) {
return group;
} else {
throw new GroupNotFoundException("No group found for id '" + groupId + "'");
}
}
use of org.craftercms.studio.api.v1.exception.security.GroupNotFoundException in project studio by craftercms.
the class GroupServiceInternalImpl method updateGroup.
@RetryingOperation
@Override
public Group updateGroup(long orgId, Group group) throws GroupNotFoundException, ServiceLayerException {
if (!groupExists(group.getId(), StringUtils.EMPTY)) {
throw new GroupNotFoundException("No group found for id '" + group.getId() + "'");
}
Map<String, Object> params = new HashMap<>();
params.put(ID, group.getId());
params.put(ORG_ID, orgId);
params.put(GROUP_NAME, group.getGroupName());
params.put(GROUP_DESCRIPTION, group.getGroupDescription());
try {
groupDao.updateGroup(params);
return group;
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
use of org.craftercms.studio.api.v1.exception.security.GroupNotFoundException in project studio by craftercms.
the class GroupServiceInternalImpl method getGroups.
@Override
public List<Group> getGroups(List<Long> groupIds) throws GroupNotFoundException, ServiceLayerException {
Map<String, Object> params = new HashMap<>();
params.put(GROUP_IDS, groupIds);
List<Group> groups;
try {
groups = groupDao.getGroups(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
if (groups != null) {
return groups;
} else {
throw new GroupNotFoundException("No group found for id '" + groupIds + "'");
}
}
Aggregations