Search in sources :

Example 11 with SiteFeed

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

the class StudioAuditLogProcessingTask method processAuditLog.

private void processAuditLog(String site) throws SiteNotFoundException {
    logger.debug("Getting last verified commit for site: " + site);
    SiteFeed siteFeed = siteService.getSite(site);
    if (checkSiteUuid(site, siteFeed.getSiteUuid())) {
        String lastSyncedCommit = siteService.getLastSyncedGitlogCommitId(site);
        if (StringUtils.isNotEmpty(lastSyncedCommit)) {
            logger.debug("Update gitlog for site " + site + " from last synced commit " + lastSyncedCommit);
            contentRepository.updateGitlog(site, lastSyncedCommit, batchSizeGitLog);
            processAuditLogFromRepo(site, batchSizeAudited);
        }
    }
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed)

Example 12 with SiteFeed

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

the class StudioAuditLogProcessingTask method processAuditLogFromRepo.

private void processAuditLogFromRepo(String siteId, int batchSize) throws SiteNotFoundException {
    List<GitLog> unauditedGitlogs = contentRepository.getUnauditedCommits(siteId, batchSize);
    if (unauditedGitlogs != null) {
        SiteFeed siteFeed = siteService.getSite(siteId);
        for (GitLog gl : unauditedGitlogs) {
            if (contentRepository.commitIdExists(siteId, gl.getCommitId())) {
                String prevCommitId = gl.getCommitId() + PREVIOUS_COMMIT_SUFFIX;
                List<RepoOperation> operations = contentRepository.getOperationsFromDelta(siteId, prevCommitId, gl.getCommitId());
                for (RepoOperation repoOperation : operations) {
                    Map<String, String> activityInfo = new HashMap<String, String>();
                    String contentClass;
                    AuditLog auditLog;
                    switch(repoOperation.getAction()) {
                        case CREATE:
                        case COPY:
                            contentClass = contentService.getContentTypeClass(siteId, repoOperation.getPath());
                            if (repoOperation.getPath().endsWith(DmConstants.XML_PATTERN)) {
                                activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
                            }
                            logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getPath());
                            auditLog = auditServiceInternal.createAuditLogEntry();
                            auditLog.setOperation(OPERATION_CREATE);
                            auditLog.setOperationTimestamp(repoOperation.getDateTime());
                            auditLog.setSiteId(siteFeed.getId());
                            auditLog.setActorId(repoOperation.getAuthor());
                            auditLog.setActorDetails(repoOperation.getAuthor());
                            auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getPath());
                            auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
                            auditLog.setPrimaryTargetValue(repoOperation.getPath());
                            auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getPath()));
                            auditLog.setOrigin(ORIGIN_GIT);
                            auditServiceInternal.insertAuditLog(auditLog);
                            break;
                        case UPDATE:
                            contentClass = contentService.getContentTypeClass(siteId, repoOperation.getPath());
                            if (repoOperation.getPath().endsWith(DmConstants.XML_PATTERN)) {
                                activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
                            }
                            logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getPath());
                            auditLog = auditServiceInternal.createAuditLogEntry();
                            auditLog.setOperation(OPERATION_UPDATE);
                            auditLog.setOperationTimestamp(repoOperation.getDateTime());
                            auditLog.setSiteId(siteFeed.getId());
                            auditLog.setActorId(repoOperation.getAuthor());
                            auditLog.setActorDetails(repoOperation.getAuthor());
                            auditLog.setOrigin(ORIGIN_GIT);
                            auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getPath());
                            auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
                            auditLog.setPrimaryTargetValue(repoOperation.getPath());
                            auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getPath()));
                            auditServiceInternal.insertAuditLog(auditLog);
                            break;
                        case DELETE:
                            contentClass = contentService.getContentTypeClass(siteId, repoOperation.getPath());
                            if (repoOperation.getPath().endsWith(DmConstants.XML_PATTERN)) {
                                activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
                            }
                            logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getPath());
                            auditLog = auditServiceInternal.createAuditLogEntry();
                            auditLog.setOperation(OPERATION_DELETE);
                            auditLog.setOperationTimestamp(repoOperation.getDateTime());
                            auditLog.setSiteId(siteFeed.getId());
                            auditLog.setOrigin(ORIGIN_GIT);
                            auditLog.setActorId(repoOperation.getAuthor());
                            auditLog.setActorDetails(repoOperation.getAuthor());
                            auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getPath());
                            auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
                            auditLog.setPrimaryTargetValue(repoOperation.getPath());
                            auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getPath()));
                            auditServiceInternal.insertAuditLog(auditLog);
                            break;
                        case MOVE:
                            contentClass = contentService.getContentTypeClass(siteId, repoOperation.getMoveToPath());
                            if (repoOperation.getMoveToPath().endsWith(DmConstants.XML_PATTERN)) {
                                activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
                            }
                            logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getMoveToPath());
                            auditLog = auditServiceInternal.createAuditLogEntry();
                            auditLog.setOperation(OPERATION_MOVE);
                            auditLog.setOperationTimestamp(repoOperation.getDateTime());
                            auditLog.setSiteId(siteFeed.getId());
                            auditLog.setActorId(repoOperation.getAuthor());
                            auditLog.setActorDetails(repoOperation.getAuthor());
                            auditLog.setOrigin(ORIGIN_GIT);
                            auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getMoveToPath());
                            auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
                            auditLog.setPrimaryTargetValue(repoOperation.getMoveToPath());
                            auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getMoveToPath()));
                            auditServiceInternal.insertAuditLog(auditLog);
                            break;
                        default:
                            logger.error("Error: Unknown repo operation for site " + siteId + " operation: " + repoOperation.getAction());
                            break;
                    }
                }
            }
            contentRepository.markGitLogAudited(siteId, gl.getCommitId());
        }
    }
}
Also used : RepoOperation(org.craftercms.studio.api.v2.dal.RepoOperation) HashMap(java.util.HashMap) GitLog(org.craftercms.studio.api.v2.dal.GitLog) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Example 13 with SiteFeed

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

the class StudioAbstractAccessDecisionVoter method isSiteMember.

protected boolean isSiteMember(String siteId, User currentUser) {
    try {
        int total = siteService.getSitesPerUserTotal(currentUser.getUsername());
        List<SiteFeed> sitesFeed = siteService.getSitesPerUser(currentUser.getUsername(), 0, total);
        Set<String> sites = new HashSet<String>();
        for (SiteFeed site : sitesFeed) {
            sites.add(site.getSiteId());
        }
        return sites.contains(siteId);
    } catch (UserNotFoundException e) {
        logger.info("User is not site member", e);
        return false;
    } catch (ServiceLayerException e) {
        logger.warn("Error getting user membership", e);
        return false;
    }
}
Also used : UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) HashSet(java.util.HashSet)

Example 14 with SiteFeed

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

the class StudioAbstractAccessDecisionVoter method isSiteAdmin.

protected boolean isSiteAdmin(String siteId, User currentUser) {
    try {
        int total = siteService.getSitesPerUserTotal(currentUser.getUsername());
        List<SiteFeed> sitesFeed = siteService.getSitesPerUser(currentUser.getUsername(), 0, total);
        Map<String, Long> sites = new HashMap<String, Long>();
        for (SiteFeed site : sitesFeed) {
            sites.put(site.getSiteId(), site.getId());
        }
        boolean toRet = sites.containsKey(siteId);
        if (toRet) {
            List<Group> userGroups = userServiceInternal.getUserGroups(sites.get(siteId), currentUser.getUsername());
            for (Group g : userGroups) {
                if (g.getGroupName().equals(studioConfiguration.getProperty(CONFIGURATION_DEFAULT_ADMIN_GROUP))) {
                    toRet = true;
                    break;
                }
            }
            toRet = userGroups.contains(studioConfiguration.getProperty(CONFIGURATION_DEFAULT_ADMIN_GROUP));
        }
        return toRet;
    } catch (UserNotFoundException e) {
        logger.info("User is not site member", e);
        return false;
    } catch (ServiceLayerException e) {
        logger.error("Error getting user memberships", e);
        return false;
    }
}
Also used : UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) Group(org.craftercms.studio.api.v2.dal.Group) HashMap(java.util.HashMap) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Example 15 with SiteFeed

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

the class ContentServiceImpl method createFolder.

@Override
@ValidateParams
public boolean createFolder(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateStringParam(name = "name") String name) throws SiteNotFoundException {
    boolean toRet = false;
    String commitId = _contentRepository.createFolder(site, path, name);
    if (commitId != null) {
        SiteFeed siteFeed = siteService.getSite(site);
        AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
        auditLog.setOperation(OPERATION_CREATE);
        auditLog.setSiteId(siteFeed.getId());
        auditLog.setActorId(securityService.getCurrentUser());
        auditLog.setPrimaryTargetId(site + ":" + path + FILE_SEPARATOR + name);
        auditLog.setPrimaryTargetType(TARGET_TYPE_FOLDER);
        auditLog.setPrimaryTargetValue(path + FILE_SEPARATOR + name);
        auditServiceInternal.insertAuditLog(auditLog);
        contentRepository.insertGitLog(site, commitId, 1, 1);
        siteService.updateLastCommitId(site, commitId);
        toRet = true;
    }
    return toRet;
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

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