Search in sources :

Example 6 with AuthenticationException

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

the class ContentServiceImpl method pushToRemote.

@Override
public boolean pushToRemote(String siteId, String remoteName, String remoteBranch) throws ServiceLayerException, InvalidRemoteUrlException, AuthenticationException, CryptoException {
    if (!siteService.exists(siteId)) {
        throw new SiteNotFoundException();
    }
    boolean toRet = _contentRepository.pushToRemote(siteId, remoteName, remoteBranch);
    SiteFeed siteFeed = siteService.getSite(siteId);
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_PUSH_TO_REMOTE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(userService.getCurrentUser().getUsername());
    auditLog.setPrimaryTargetId(remoteName + "/" + remoteBranch);
    auditLog.setPrimaryTargetType(TARGET_TYPE_REMOTE_REPOSITORY);
    auditLog.setPrimaryTargetValue(remoteName + "/" + remoteBranch);
    auditServiceInternal.insertAuditLog(auditLog);
    return toRet;
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Example 7 with AuthenticationException

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

the class ContentServiceImpl method pullFromRemote.

@Override
public boolean pullFromRemote(String siteId, String remoteName, String remoteBranch) throws ServiceLayerException, InvalidRemoteUrlException, AuthenticationException, CryptoException {
    if (!siteService.exists(siteId)) {
        throw new SiteNotFoundException(siteId);
    }
    boolean toRet = _contentRepository.pullFromRemote(siteId, remoteName, remoteBranch);
    SiteFeed siteFeed = siteService.getSite(siteId);
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_PULL_FROM_REMOTE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(userService.getCurrentUser().getUsername());
    auditLog.setPrimaryTargetId(remoteName + "/" + remoteBranch);
    auditLog.setPrimaryTargetType(TARGET_TYPE_REMOTE_REPOSITORY);
    auditLog.setPrimaryTargetValue(remoteName + "/" + remoteBranch);
    auditServiceInternal.insertAuditLog(auditLog);
    return toRet;
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Example 8 with AuthenticationException

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

the class GroupServiceImpl method addGroupMembers.

@Override
@HasPermission(type = DefaultPermission.class, action = "update_groups")
public List<User> addGroupMembers(long groupId, List<Long> userIds, List<String> usernames) throws ServiceLayerException, UserNotFoundException, GroupNotFoundException, AuthenticationException {
    List<User> users = groupServiceInternal.addGroupMembers(groupId, userIds, usernames);
    Group group = groupServiceInternal.getGroup(groupId);
    SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    List<AuditLogParameter> parameters = new ArrayList<AuditLogParameter>();
    for (User user : users) {
        AuditLogParameter parameter = new AuditLogParameter();
        parameter.setTargetId(Long.toString(user.getId()));
        parameter.setTargetType(TARGET_TYPE_USER);
        parameter.setTargetValue(user.getUsername());
        parameters.add(parameter);
    }
    auditLog.setParameters(parameters);
    auditLog.setOperation(OPERATION_ADD_MEMBERS);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(userService.getCurrentUser().getUsername());
    auditLog.setPrimaryTargetId(Long.toString(groupId));
    auditLog.setPrimaryTargetType(TARGET_TYPE_GROUP);
    auditLog.setPrimaryTargetValue(group.getGroupName());
    auditServiceInternal.insertAuditLog(auditLog);
    return users;
}
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) 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 9 with AuthenticationException

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

the class GroupServiceImpl method deleteGroup.

@Override
@HasPermission(type = DefaultPermission.class, action = "delete_groups")
public void deleteGroup(List<Long> groupIds) throws ServiceLayerException, GroupNotFoundException, AuthenticationException {
    Group sysAdminGroup;
    try {
        sysAdminGroup = groupServiceInternal.getGroupByName(SYSTEM_ADMIN_GROUP);
    } catch (GroupNotFoundException e) {
        throw new ServiceLayerException("The System Admin group is not found", e);
    }
    if (CollectionUtils.isNotEmpty(groupIds)) {
        if (groupIds.contains(sysAdminGroup.getId())) {
            throw new ServiceLayerException("Deleting the System Admin group is not allowed.");
        }
    }
    List<Group> groups = groupServiceInternal.getGroups(groupIds);
    groupServiceInternal.deleteGroup(groupIds);
    SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_DELETE);
    auditLog.setActorId(userService.getCurrentUser().getUsername());
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setPrimaryTargetId(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    auditLog.setPrimaryTargetType(TARGET_TYPE_GROUP);
    auditLog.setPrimaryTargetValue(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    List<AuditLogParameter> paramters = new ArrayList<AuditLogParameter>();
    for (Group g : groups) {
        AuditLogParameter paramter = new AuditLogParameter();
        paramter.setTargetId(Long.toString(g.getId()));
        paramter.setTargetType(TARGET_TYPE_GROUP);
        paramter.setTargetValue(g.getGroupName());
        paramters.add(paramter);
    }
    auditLog.setParameters(paramters);
    auditServiceInternal.insertAuditLog(auditLog);
}
Also used : Group(org.craftercms.studio.api.v2.dal.Group) 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 10 with AuthenticationException

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

the class GroupServiceImpl method createGroup.

@Override
@HasPermission(type = DefaultPermission.class, action = "create_groups")
public Group createGroup(long orgId, String groupName, String groupDescription) throws GroupAlreadyExistsException, ServiceLayerException, AuthenticationException {
    Group toRet = groupServiceInternal.createGroup(orgId, groupName, groupDescription);
    SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_CREATE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(userService.getCurrentUser().getUsername());
    auditLog.setPrimaryTargetId(groupName);
    auditLog.setPrimaryTargetType(TARGET_TYPE_GROUP);
    auditLog.setPrimaryTargetValue(groupName);
    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)13 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)13 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)9 Group (org.craftercms.studio.api.v2.dal.Group)7 User (org.craftercms.studio.api.v2.dal.User)7 ArrayList (java.util.ArrayList)6 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)6 AuditLogParameter (org.craftercms.studio.api.v2.dal.AuditLogParameter)5 AuthenticatedUser (org.craftercms.studio.model.AuthenticatedUser)4 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)3 AuthenticationException (org.craftercms.studio.api.v1.exception.security.AuthenticationException)2 GroupNotFoundException (org.craftercms.studio.api.v1.exception.security.GroupNotFoundException)2 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 NamingEnumeration (javax.naming.NamingEnumeration)1