Search in sources :

Example 1 with GraniteContext

use of org.granite.context.GraniteContext in project collect by openforis.

the class SessionManager method invalidateSession.

public void invalidateSession() {
    try {
        releaseRecord();
    } catch (RecordUnlockedException e) {
    // do nothing
    }
    GraniteContext graniteContext = GraniteContext.getCurrentInstance();
    if (graniteContext != null && graniteContext instanceof HttpGraniteContext) {
        HttpGraniteContext httpGraniteContext = (HttpGraniteContext) graniteContext;
        HttpServletRequest request = httpGraniteContext.getRequest();
        HttpSession session = request.getSession();
        session.invalidate();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) GraniteContext(org.granite.context.GraniteContext) HttpGraniteContext(org.granite.messaging.webapp.HttpGraniteContext) HttpSession(javax.servlet.http.HttpSession) RecordUnlockedException(org.openforis.collect.persistence.RecordUnlockedException) HttpGraniteContext(org.granite.messaging.webapp.HttpGraniteContext)

Example 2 with GraniteContext

use of org.granite.context.GraniteContext in project collect by openforis.

the class SessionManager method getSessionAttribute.

private Object getSessionAttribute(String attributeName) {
    Object result = null;
    // try to get session attribute from GraniteDS context
    GraniteContext graniteContext = GraniteContext.getCurrentInstance();
    if (graniteContext != null) {
        result = graniteContext.getSessionMap().get(attributeName);
    } else {
        // try to get session attribute from current request context holder session
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (requestAttributes != null) {
            HttpSession session = requestAttributes.getRequest().getSession();
            result = session.getAttribute(attributeName);
        }
    }
    return result;
}
Also used : GraniteContext(org.granite.context.GraniteContext) HttpGraniteContext(org.granite.messaging.webapp.HttpGraniteContext) HttpSession(javax.servlet.http.HttpSession) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Aggregations

HttpSession (javax.servlet.http.HttpSession)2 GraniteContext (org.granite.context.GraniteContext)2 HttpGraniteContext (org.granite.messaging.webapp.HttpGraniteContext)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 RecordUnlockedException (org.openforis.collect.persistence.RecordUnlockedException)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1