Search in sources :

Example 1 with WebEnvironment

use of org.apache.shiro.web.env.WebEnvironment in project atmosphere by Atmosphere.

the class ShiroInterceptor method inspect.

@Override
public Action inspect(AtmosphereResource r) {
    if (Utils.webSocketMessage(r))
        return Action.CONTINUE;
    if (r.getRequest().localAttributes().containsKey(FrameworkConfig.SECURITY_SUBJECT) == false) {
        try {
            Subject currentUser = null;
            if (r.transport().equals(TRANSPORT.WEBSOCKET)) {
                WebEnvironment env = WebUtils.getRequiredWebEnvironment(r.getAtmosphereConfig().getServletContext());
                currentUser = new WebSubject.Builder(env.getSecurityManager(), r.getRequest(), r.getResponse()).buildWebSubject();
            } else {
                currentUser = SecurityUtils.getSubject();
            }
            if (currentUser != null) {
                r.getRequest().setAttribute(FrameworkConfig.SECURITY_SUBJECT, currentUser);
            }
        } catch (UnavailableSecurityManagerException ex) {
            logger.info("Shiro Web Security : {}", ex.getMessage());
        } catch (java.lang.IllegalStateException ex) {
            logger.info("Shiro Web Environment : {}", ex.getMessage());
        }
    }
    return Action.CONTINUE;
}
Also used : WebEnvironment(org.apache.shiro.web.env.WebEnvironment) UnavailableSecurityManagerException(org.apache.shiro.UnavailableSecurityManagerException) WebSubject(org.apache.shiro.web.subject.WebSubject) Subject(org.apache.shiro.subject.Subject)

Aggregations

UnavailableSecurityManagerException (org.apache.shiro.UnavailableSecurityManagerException)1 Subject (org.apache.shiro.subject.Subject)1 WebEnvironment (org.apache.shiro.web.env.WebEnvironment)1 WebSubject (org.apache.shiro.web.subject.WebSubject)1