Search in sources :

Example 31 with AuditLog

use of org.craftercms.studio.api.v2.dal.AuditLog in project studio by craftercms.

the class ContentServiceImpl method revertContentItem.

@Override
@ValidateParams
public boolean revertContentItem(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateStringParam(name = "version") String version, boolean major, @ValidateStringParam(name = "comment") String comment) throws SiteNotFoundException {
    boolean toReturn = false;
    String commitId = _contentRepository.revertContent(site, path, version, major, comment);
    if (commitId != null) {
        try {
            dependencyService.upsertDependencies(site, path);
        } catch (ServiceLayerException e) {
            logger.error("Error while extracting dependencies for reverted content. Site: " + site + " path: " + path + " version: " + version);
        }
        // Update the database with the commitId for the target item
        objectStateService.transition(site, path, REVERT);
        objectMetadataManager.updateCommitId(site, path, commitId);
        SiteFeed siteFeed = siteService.getSite(site);
        AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
        auditLog.setOperation(OPERATION_REVERT);
        auditLog.setSiteId(siteFeed.getId());
        auditLog.setActorId(securityService.getCurrentUser());
        auditLog.setPrimaryTargetId(site + ":" + path);
        auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
        auditLog.setPrimaryTargetValue(path);
        auditLog.setPrimaryTargetSubtype(getContentTypeClass(site, path));
        auditServiceInternal.insertAuditLog(auditLog);
        contentRepository.insertGitLog(site, commitId, 1, 1);
        siteService.updateLastCommitId(site, commitId);
        toReturn = true;
    }
    if (toReturn) {
        PreviewEventContext context = new PreviewEventContext();
        context.setSite(site);
        eventService.publish(EVENT_PREVIEW_SYNC, context);
    }
    return toReturn;
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) PreviewEventContext(org.craftercms.studio.api.v1.ebus.PreviewEventContext) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 32 with AuditLog

use of org.craftercms.studio.api.v2.dal.AuditLog 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 33 with AuditLog

use of org.craftercms.studio.api.v2.dal.AuditLog in project studio by craftercms.

the class ContentServiceImpl method generateDeleteActivity.

protected void generateDeleteActivity(String site, String path, String approver) throws SiteNotFoundException {
    // TODO: SJ: activities. Fix in 3.1+ by introducing the audit service and refactoring accordingly
    if (StringUtils.isEmpty(approver)) {
        approver = securityService.getCurrentUser();
    }
    boolean exists = contentExists(site, path);
    if (exists) {
        ContentItemTO item = getContentItem(site, path, 0);
        ItemMetadata properties = objectMetadataManager.getProperties(site, path);
        String user = (properties != null && !StringUtils.isEmpty(properties.getSubmittedBy()) ? properties.getSubmittedBy() : approver);
        Map<String, String> extraInfo = new HashMap<String, String>();
        if (item.isFolder()) {
            extraInfo.put(DmConstants.KEY_CONTENT_TYPE, CONTENT_TYPE_FOLDER);
        } else {
            extraInfo.put(DmConstants.KEY_CONTENT_TYPE, getContentTypeClass(site, path));
        }
        logger.debug("[DELETE] posting delete activity on " + path + " by " + user + " in " + site);
        SiteFeed siteFeed = siteService.getSite(site);
        AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
        auditLog.setOperation(OPERATION_DELETE);
        auditLog.setSiteId(siteFeed.getId());
        auditLog.setActorId(user);
        auditLog.setPrimaryTargetId(site + ":" + path);
        auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
        auditLog.setPrimaryTargetValue(path);
        auditLog.setPrimaryTargetSubtype(getContentTypeClass(site, path));
        auditServiceInternal.insertAuditLog(auditLog);
        // process content life cycle
        if (path.endsWith(DmConstants.XML_PATTERN)) {
            String contentType = item.getContentType();
            dmContentLifeCycleService.process(site, user, path, contentType, DmContentLifeCycleService.ContentLifeCycleOperation.DELETE, null);
        }
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) HashMap(java.util.HashMap) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata)

Example 34 with AuditLog

use of org.craftercms.studio.api.v2.dal.AuditLog in project studio by craftercms.

the class SecurityServiceImpl method logout.

@Override
public boolean logout() throws SiteNotFoundException {
    String username = getCurrentUser();
    RequestContext context = RequestContext.getCurrent();
    if (username != null && context != null) {
        HttpServletRequest httpServletRequest = context.getRequest();
        String ipAddress = httpServletRequest.getRemoteAddr();
        SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
        AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
        auditLog.setOperation(OPERATION_LOGOUT);
        auditLog.setActorId(username);
        auditLog.setSiteId(siteFeed.getId());
        auditLog.setPrimaryTargetId(username);
        auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
        auditLog.setPrimaryTargetValue(username);
        auditServiceInternal.insertAuditLog(auditLog);
        logger.info("User " + username + " logged out from IP: " + ipAddress);
    }
    return true;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) RequestContext(org.craftercms.commons.http.RequestContext) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Example 35 with AuditLog

use of org.craftercms.studio.api.v2.dal.AuditLog in project studio by craftercms.

the class AuthenticationChainImpl method doAuthenticate.

@Override
public boolean doAuthenticate(HttpServletRequest request, HttpServletResponse response, String username, String password) throws Exception {
    boolean authenticated = false;
    Iterator<AuthenticationProvider> iterator = authenticationChain.iterator();
    Exception lastError = null;
    while (iterator.hasNext()) {
        AuthenticationProvider authProvider = iterator.next();
        if (authProvider.isEnabled()) {
            try {
                authenticated = authProvider.doAuthenticate(request, response, this, username, password);
            } catch (Exception e) {
                lastError = e;
            }
            if (authenticated)
                break;
        }
    }
    String ipAddress = request.getRemoteAddr();
    SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    if (authenticated) {
        AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
        auditLog.setOperation(OPERATION_LOGIN);
        auditLog.setActorId(username);
        auditLog.setSiteId(siteFeed.getId());
        auditLog.setPrimaryTargetId(username);
        auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
        auditLog.setPrimaryTargetValue(username);
        auditServiceInternal.insertAuditLog(auditLog);
        logger.info("User " + username + " logged in from IP: " + ipAddress);
    } else {
        AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
        auditLog.setOperation(OPERATION_LOGIN_FAILED);
        auditLog.setActorId(username);
        auditLog.setSiteId(siteFeed.getId());
        auditLog.setPrimaryTargetId(StringUtils.isEmpty(username) ? StringUtils.EMPTY : username);
        auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
        auditLog.setPrimaryTargetValue(username);
        auditServiceInternal.insertAuditLog(auditLog);
        logger.info("Failed to authenticate user " + username + " logging in from IP: " + ipAddress);
        if (lastError == null) {
            lastError = new AuthenticationSystemException("Unknown service error");
        }
        throw lastError;
    }
    return authenticated;
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuthenticationSystemException(org.craftercms.studio.api.v1.exception.security.AuthenticationSystemException) AuthenticationProvider(org.craftercms.studio.api.v2.service.security.AuthenticationProvider) AuthenticationSystemException(org.craftercms.studio.api.v1.exception.security.AuthenticationSystemException) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Aggregations

AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)44 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)38 ArrayList (java.util.ArrayList)16 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)11 AuditLogParameter (org.craftercms.studio.api.v2.dal.AuditLogParameter)11 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)10 Group (org.craftercms.studio.api.v2.dal.Group)10 User (org.craftercms.studio.api.v2.dal.User)9 HashMap (java.util.HashMap)7 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)6 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)5 AuthenticationSystemException (org.craftercms.studio.api.v1.exception.security.AuthenticationSystemException)5 UserAlreadyExistsException (org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException)4 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)4 SiteService (org.craftercms.studio.api.v1.service.site.SiteService)4 UserGroup (org.craftercms.studio.api.v2.dal.UserGroup)4 AuditServiceInternal (org.craftercms.studio.api.v2.service.audit.internal.AuditServiceInternal)4 StudioConfiguration (org.craftercms.studio.api.v2.utils.StudioConfiguration)4 SimpleDateFormat (java.text.SimpleDateFormat)3 GroupDAO (org.craftercms.studio.api.v2.dal.GroupDAO)3