Search in sources :

Example 1 with Authentication

use of org.craftercms.studio.impl.v2.service.security.Authentication in project studio by craftercms.

the class StudioAuthenticationTokenProcessingFilter method storeToken.

private void storeToken(String token) {
    RequestContext context = RequestContext.getCurrent();
    if (context != null) {
        HttpSession httpSession = context.getRequest().getSession();
        Authentication oldAuthentication = (Authentication) httpSession.getAttribute(HTTP_SESSION_ATTRIBUTE_AUTHENTICATION);
        Authentication newAuthentication = new Authentication(oldAuthentication.getUsername(), token, oldAuthentication.getAuthenticationType(), oldAuthentication.getSsoLogoutUrl());
        httpSession.setAttribute(HTTP_SESSION_ATTRIBUTE_AUTHENTICATION, newAuthentication);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) Authentication(org.craftercms.studio.impl.v2.service.security.Authentication) RequestContext(org.craftercms.commons.http.RequestContext)

Example 2 with Authentication

use of org.craftercms.studio.impl.v2.service.security.Authentication in project studio by craftercms.

the class SecurityServiceImpl method getAuthentication.

@Override
public Authentication getAuthentication() {
    Authentication auth = null;
    RequestContext context = RequestContext.getCurrent();
    if (context != null) {
        HttpSession httpSession = context.getRequest().getSession();
        auth = (Authentication) httpSession.getAttribute(HTTP_SESSION_ATTRIBUTE_AUTHENTICATION);
    }
    return auth;
}
Also used : Authentication(org.craftercms.studio.impl.v2.service.security.Authentication) HttpSession(javax.servlet.http.HttpSession) RequestContext(org.craftercms.commons.http.RequestContext)

Example 3 with Authentication

use of org.craftercms.studio.impl.v2.service.security.Authentication 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 Authentication

use of org.craftercms.studio.impl.v2.service.security.Authentication in project studio by craftercms.

the class SecurityServiceImpl method getCurrentToken.

@Override
public String getCurrentToken() {
    String ticket = 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) {
            ticket = auth.getToken();
        }
    } else {
        ticket = getJobOrEventTicket();
    }
    if (ticket == null) {
        ticket = "NOTICKET";
    }
    return ticket;
}
Also used : HttpSession(javax.servlet.http.HttpSession) Authentication(org.craftercms.studio.impl.v2.service.security.Authentication) RequestContext(org.craftercms.commons.http.RequestContext)

Aggregations

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