use of org.craftercms.studio.api.v1.service.workflow.context.RequestContext in project studio by craftercms.
the class UserServiceImpl method sendForgotPasswordEmail.
private void sendForgotPasswordEmail(String emailAddress, String token) {
try {
Template emailTemplate = freeMarkerConfig.getObject().getConfiguration().getTemplate(studioConfiguration.getProperty(SECURITY_FORGOT_PASSWORD_EMAIL_TEMPLATE));
Writer out = new StringWriter();
Map<String, Object> model = new HashMap<String, Object>();
RequestContext context = RequestContext.getCurrent();
HttpServletRequest request = context.getRequest();
String authoringUrl = request.getRequestURL().toString().replace(request.getPathInfo(), "");
String serviceUrl = studioConfiguration.getProperty(SECURITY_RESET_PASSWORD_SERVICE_URL);
model.put("authoringUrl", authoringUrl);
model.put("serviceUrl", serviceUrl);
model.put("token", token);
if (emailTemplate != null) {
emailTemplate.process(model, out);
}
MimeMessage mimeMessage = emailService.createMimeMessage();
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage);
messageHelper.setFrom(studioConfiguration.getProperty(MAIL_FROM_DEFAULT));
messageHelper.setTo(emailAddress);
messageHelper.setSubject(studioConfiguration.getProperty(SECURITY_FORGOT_PASSWORD_MESSAGE_SUBJECT));
messageHelper.setText(out.toString(), true);
logger.info("Sending password recovery message to " + emailAddress);
if (isAuthenticatedSMTP()) {
emailService.send(mimeMessage);
} else {
emailServiceNoAuth.send(mimeMessage);
}
logger.info("Password recovery message successfully sent to " + emailAddress);
} catch (Exception e) {
logger.error("Failed to send password recovery message to " + emailAddress, e);
}
}
use of org.craftercms.studio.api.v1.service.workflow.context.RequestContext in project studio by craftercms.
the class DebugUtils method addDebugStack.
public static void addDebugStack(Logger logger) {
if (logger.getLevel().equals(Logger.LEVEL_DEBUG)) {
Thread thread = Thread.currentThread();
String threadName = thread.getName();
logger.debug("Thread: " + threadName);
StackTraceElement[] stackTraceElements = thread.getStackTrace();
StringBuilder sbStack = new StringBuilder();
int stackSize = (20 < stackTraceElements.length - 2) ? 20 : stackTraceElements.length;
for (int i = 2; i < stackSize + 2; i++) {
sbStack.append("\n\t").append(stackTraceElements[i].toString());
}
RequestContext context = RequestContext.getCurrent();
CronJobContext cronJobContext = CronJobContext.getCurrent();
if (context != null) {
HttpServletRequest request = context.getRequest();
String url = request.getRequestURI() + "?" + request.getQueryString();
logger.debug("Http request: " + url);
} else if (cronJobContext != null) {
logger.debug("Cron Job");
}
logger.debug("Stack trace (depth 20): " + sbStack.toString());
}
}
use of org.craftercms.studio.api.v1.service.workflow.context.RequestContext in project studio by craftercms.
the class WorkflowServiceImpl method submitForApproval.
@SuppressWarnings("unchecked")
protected ResultTO submitForApproval(final String site, String submittedBy, final String request, final boolean delete) throws ServiceLayerException {
RequestContext requestContext = RequestContextBuilder.buildSubmitContext(site, submittedBy);
ResultTO result = new ResultTO();
try {
SimpleDateFormat format = new SimpleDateFormat(StudioConstants.DATE_PATTERN_WORKFLOW_WITH_TZ);
JSONObject requestObject = JSONObject.fromObject(request);
JSONArray items = requestObject.getJSONArray(JSON_KEY_ITEMS);
int length = items.size();
if (length > 0) {
for (int index = 0; index < length; index++) {
objectStateService.setSystemProcessing(site, items.optString(index), true);
}
}
boolean isNow = (requestObject.containsKey(JSON_KEY_SCHEDULE)) ? StringUtils.equalsIgnoreCase(requestObject.getString(JSON_KEY_SCHEDULE), JSON_KEY_IS_NOW) : false;
ZonedDateTime scheduledDate = null;
if (!isNow) {
scheduledDate = (requestObject.containsKey(JSON_KEY_SCHEDULED_DATE)) ? getScheduledDate(site, format, requestObject.getString(JSON_KEY_SCHEDULED_DATE)) : null;
}
boolean sendEmail = (requestObject.containsKey(JSON_KEY_SEND_EMAIL)) ? requestObject.getBoolean(JSON_KEY_SEND_EMAIL) : false;
String environment = (requestObject != null && requestObject.containsKey(JSON_KEY_ENVIRONMENT)) ? requestObject.getString(JSON_KEY_ENVIRONMENT) : null;
String submissionComment = (requestObject != null && requestObject.containsKey(JSON_KEY_SUBMISSION_COMMENT)) ? requestObject.getString(JSON_KEY_SUBMISSION_COMMENT) : null;
// TODO: check scheduled date to make sure it is not null when isNow
// = true and also it is not past
String schDate = null;
if (requestObject.containsKey(JSON_KEY_SCHEDULED_DATE)) {
schDate = requestObject.getString(JSON_KEY_SCHEDULED_DATE);
}
if (length > 0) {
List<DmDependencyTO> submittedItems = new ArrayList<DmDependencyTO>();
for (int index = 0; index < length; index++) {
String stringItem = items.optString(index);
DmDependencyTO submittedItem = getSubmittedItem(site, stringItem, format, schDate, null);
String user = submittedBy;
submittedItems.add(submittedItem);
if (delete) {
submittedItem.setSubmittedForDeletion(true);
}
}
submittedItems.addAll(addDependenciesForSubmitForApproval(site, submittedItems, format, schDate));
List<String> submittedPaths = new ArrayList<String>();
for (DmDependencyTO goLiveItem : submittedItems) {
submittedPaths.add(goLiveItem.getUri());
objectStateService.setSystemProcessing(site, goLiveItem.getUri(), true);
DependencyRules rule = new DependencyRules(site);
rule.setObjectStateService(objectStateService);
rule.setContentService(contentService);
Set<DmDependencyTO> depSet = rule.applySubmitRule(goLiveItem);
for (DmDependencyTO dep : depSet) {
submittedPaths.add(dep.getUri());
objectStateService.setSystemProcessing(site, dep.getUri(), true);
}
}
List<DmError> errors = submitToGoLive(submittedItems, scheduledDate, sendEmail, delete, requestContext, submissionComment, environment);
SiteFeed siteFeed = siteService.getSite(site);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_REQUEST_PUBLISH);
auditLog.setActorId(submittedBy);
auditLog.setSiteId(siteFeed.getId());
auditLog.setPrimaryTargetId(site);
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(site);
auditServiceInternal.insertAuditLog(auditLog);
result.setSuccess(true);
result.setStatus(200);
result.setMessage(notificationService.getNotificationMessage(site, NotificationMessageType.CompleteMessages, COMPLETE_SUBMIT_TO_GO_LIVE_MSG, Locale.ENGLISH));
for (String relativePath : submittedPaths) {
objectStateService.setSystemProcessing(site, relativePath, false);
}
}
} catch (Exception e) {
result.setSuccess(false);
result.setMessage(e.getMessage());
logger.error("Error while submitting content for approval.", e);
}
return result;
}
use of org.craftercms.studio.api.v1.service.workflow.context.RequestContext in project studio by craftercms.
the class WorkflowServiceImpl method submitToGoLive.
protected List<DmError> submitToGoLive(List<DmDependencyTO> submittedItems, ZonedDateTime scheduledDate, boolean sendEmail, boolean submitForDeletion, RequestContext requestContext, String submissionComment, String environment) throws ServiceLayerException {
List<DmError> errors = new ArrayList<DmError>();
String site = requestContext.getSite();
String submittedBy = requestContext.getUser();
for (DmDependencyTO submittedItem : submittedItems) {
try {
DependencyRules rule = new DependencyRules(site);
rule.setContentService(contentService);
rule.setObjectStateService(objectStateService);
submitThisAndReferredComponents(submittedItem, site, scheduledDate, sendEmail, submitForDeletion, submittedBy, rule, submissionComment, environment);
List<DmDependencyTO> children = submittedItem.getChildren();
if (children != null && !submitForDeletion) {
for (DmDependencyTO child : children) {
if (!child.isReference()) {
submitThisAndReferredComponents(child, site, scheduledDate, sendEmail, submitForDeletion, submittedBy, rule, submissionComment, environment);
}
}
}
} catch (ContentNotFoundException e) {
errors.add(new DmError(site, submittedItem.getUri(), e));
}
}
notificationService.notifyApprovesContentSubmission(site, null, getDeploymentPaths(submittedItems), submittedBy, scheduledDate, submitForDeletion, submissionComment, Locale.ENGLISH);
return errors;
}
use of org.craftercms.studio.api.v1.service.workflow.context.RequestContext 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;
}
Aggregations