Search in sources :

Example 1 with CronJobContext

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();
        }
    }
}
Also used : CronJobContext(org.craftercms.studio.api.v1.job.CronJobContext)

Example 2 with CronJobContext

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());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CronJobContext(org.craftercms.studio.api.v1.job.CronJobContext) RequestContext(org.craftercms.commons.http.RequestContext)

Example 3 with CronJobContext

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;
}
Also used : HttpSession(javax.servlet.http.HttpSession) Authentication(org.craftercms.studio.impl.v2.service.security.Authentication) CronJobContext(org.craftercms.studio.api.v1.job.CronJobContext) RequestContext(org.craftercms.commons.http.RequestContext) RepositoryEventContext(org.craftercms.studio.api.v1.ebus.RepositoryEventContext)

Example 4 with CronJobContext

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;
}
Also used : CronJobContext(org.craftercms.studio.api.v1.job.CronJobContext) RepositoryEventContext(org.craftercms.studio.api.v1.ebus.RepositoryEventContext)

Aggregations

CronJobContext (org.craftercms.studio.api.v1.job.CronJobContext)4 RequestContext (org.craftercms.commons.http.RequestContext)2 RepositoryEventContext (org.craftercms.studio.api.v1.ebus.RepositoryEventContext)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 Authentication (org.craftercms.studio.impl.v2.service.security.Authentication)1