Search in sources :

Example 1 with RepositoryEventContext

use of org.craftercms.studio.api.v1.ebus.RepositoryEventContext 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 2 with RepositoryEventContext

use of org.craftercms.studio.api.v1.ebus.RepositoryEventContext 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

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