use of org.craftercms.studio.api.v1.job.CronJobContext in project studio by craftercms.
the class RebuildRepositoryMetadata method execute.
public void execute(String site) {
if (taskLock.tryLock()) {
try {
logger.debug("Starting Rebuild Repository Metadata Task.");
String ticket = securityService.getCurrentToken();
CronJobContext securityContext = new CronJobContext(ticket, securityService.getCurrentUser());
RebuildRepositoryMetadataTask task = new RebuildRepositoryMetadataTask(securityContext, site);
taskExecutor.execute(task);
} finally {
taskLock.unlock();
}
}
}
use of org.craftercms.studio.api.v1.job.CronJobContext 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.job.CronJobContext in project studio by craftercms.
the class SecurityServiceImpl method getCurrentUser.
@Override
public String getCurrentUser() {
String username = null;
RequestContext context = RequestContext.getCurrent();
if (context != null) {
HttpSession httpSession = context.getRequest().getSession();
Authentication auth = (Authentication) httpSession.getAttribute(HTTP_SESSION_ATTRIBUTE_AUTHENTICATION);
if (auth != null) {
username = auth.getUsername();
}
} else {
CronJobContext cronJobContext = CronJobContext.getCurrent();
if (cronJobContext != null) {
username = cronJobContext.getCurrentUser();
} else {
RepositoryEventContext repositoryEventContext = RepositoryEventContext.getCurrent();
if (repositoryEventContext != null) {
username = repositoryEventContext.getCurrentUser();
}
}
}
return username;
}
use of org.craftercms.studio.api.v1.job.CronJobContext in project studio by craftercms.
the class SecurityServiceImpl method getJobOrEventTicket.
protected String getJobOrEventTicket() {
String ticket = null;
CronJobContext cronJobContext = CronJobContext.getCurrent();
if (cronJobContext != null) {
ticket = cronJobContext.getAuthenticationToken();
} else {
RepositoryEventContext repositoryEventContext = RepositoryEventContext.getCurrent();
if (repositoryEventContext != null) {
ticket = repositoryEventContext.getAuthenticationToken();
}
}
return ticket;
}
Aggregations