Search in sources :

Example 1 with SiteFeed

use of org.craftercms.studio.api.v1.dal.SiteFeed in project studio by craftercms.

the class ConfigurationServiceImpl method generateAuditLog.

private void generateAuditLog(String siteId, String path, String user) throws SiteNotFoundException {
    SiteFeed siteFeed = siteService.getSite(siteId);
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_UPDATE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(user);
    auditLog.setPrimaryTargetId(siteId + ":" + path);
    auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
    auditLog.setPrimaryTargetValue(path);
    auditLog.setPrimaryTargetSubtype(CONTENT_TYPE_CONFIGURATION);
    auditServiceInternal.insertAuditLog(auditLog);
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Example 2 with SiteFeed

use of org.craftercms.studio.api.v1.dal.SiteFeed 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);
    }
}
Also used : Group(org.craftercms.studio.api.v2.dal.Group) User(org.craftercms.studio.api.v2.dal.User) AuthenticatedUser(org.craftercms.studio.model.AuthenticatedUser) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ArrayList(java.util.ArrayList) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) GroupNotFoundException(org.craftercms.studio.api.v1.exception.security.GroupNotFoundException) AuditLogParameter(org.craftercms.studio.api.v2.dal.AuditLogParameter) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 3 with SiteFeed

use of org.craftercms.studio.api.v1.dal.SiteFeed in project studio by craftercms.

the class UserServiceImpl method createUser.

@Override
@HasPermission(type = DefaultPermission.class, action = "create_users")
public User createUser(User user) throws UserAlreadyExistsException, ServiceLayerException, AuthenticationException {
    try {
        entitlementValidator.validateEntitlement(EntitlementType.USER, 1);
    } catch (EntitlementException e) {
        throw new ServiceLayerException("Unable to complete request due to entitlement limits. Please contact " + "your system administrator.", e);
    }
    User toRet = userServiceInternal.createUser(user);
    SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_CREATE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(getCurrentUser().getUsername());
    auditLog.setPrimaryTargetId(user.getUsername());
    auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
    auditLog.setPrimaryTargetValue(user.getUsername());
    auditServiceInternal.insertAuditLog(auditLog);
    return toRet;
}
Also used : EntitlementException(org.craftercms.commons.entitlements.exception.EntitlementException) User(org.craftercms.studio.api.v2.dal.User) AuthenticatedUser(org.craftercms.studio.model.AuthenticatedUser) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 4 with SiteFeed

use of org.craftercms.studio.api.v1.dal.SiteFeed in project studio by craftercms.

the class PublishServiceImpl method createAuditLogEntry.

private void createAuditLogEntry(String siteId, List<AuditLogParameter> auditLogParameters) throws SiteNotFoundException {
    SiteFeed siteFeed = siteService.getSite(siteId);
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_CANCEL_PUBLISHING_PACKAGE);
    auditLog.setActorId(securityService.getCurrentUser());
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setPrimaryTargetId(siteId);
    auditLog.setPrimaryTargetType(TARGET_TYPE_SITE);
    auditLog.setPrimaryTargetValue(siteId);
    auditLog.setParameters(auditLogParameters);
    auditServiceInternal.insertAuditLog(auditLog);
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Example 5 with SiteFeed

use of org.craftercms.studio.api.v1.dal.SiteFeed 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)

Aggregations

SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)58 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)39 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)21 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)18 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)15 AuditLogParameter (org.craftercms.studio.api.v2.dal.AuditLogParameter)12 Group (org.craftercms.studio.api.v2.dal.Group)12 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)11 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)11 User (org.craftercms.studio.api.v2.dal.User)10 IOException (java.io.IOException)9 ClusterMember (org.craftercms.studio.api.v2.dal.ClusterMember)9 CryptoException (org.craftercms.commons.crypto.CryptoException)8 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)8 EntitlementException (org.craftercms.commons.entitlements.exception.EntitlementException)6 ZonedDateTime (java.time.ZonedDateTime)5 AuthenticationSystemException (org.craftercms.studio.api.v1.exception.security.AuthenticationSystemException)5 UserAlreadyExistsException (org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException)5 SiteService (org.craftercms.studio.api.v1.service.site.SiteService)5