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;
}
Aggregations