I think this is a similar question to one that was previously asked, but the OP didn’t follow up, so it was never fully resolved (see: http://shiro-user.582556.n2.nabble.com/WebEnvironment-is-not-seted-when-using-with-spring-td7579424.html <http://shiro-user.582556.n2.nabble.com/WebEnvironment-is-not-seted-when-using-with-spring-td7579424.html> ). Anyway: here’s the situation: I have a webapp that uses Shiro with Spring and Atmosphere (a websocket API). I’m needing to rationalize the configuration so that I’m using Spring XML for configuration, and the whole of Spring/Shiro works fine. What doesn’t work is Shiro access through Atmosphere servlets, which don’t get access to the authentication web environment. This is because I can’t set a WebEnvironment which works nicely with Spring. (The whole thing did work with .ini configuration, but the two injection systems were not playing nice). I shouldn't really need to, according to this (from http://shiro-user.582556.n2.nabble.com/Article-What-s-new-in-Apache-Shiro-1-2-td7369658.html#a7370076 <http://shiro-user.582556.n2.nabble.com/Article-What-s-new-in-Apache-Shiro-1-2-td7369658.html#a7370076> ) It should be noted that Spring environments don't have/need an Environment/WebEnvironment concept as the 'environment' is essentially the Spring ApplicationContext - you can just interact with the ApplicationContext directly if ever needed. So as I said, Spring is fine. The problem is only with the Atmosphere interception, which is reporting as follows: Jun 26, 2015 11:12:24 AM org.atmosphere.interceptor.ShiroInterceptor inspectINFO: Shiro Web Environment : No WebEnvironment found: no EnvironmentLoaderListener registered?Jun 26, 2015 11:12:24 AM ca.uhnresearch.pughlab.tracker.sockets.TrackerSocketHandler onReadyINFO: Browser 3bb382e9-7030-48b2-b9cc-111099cbd7a7 connectedJun 26, 2015 11:12:24 AM ca.uhnresearch.pughlab.tracker.sockets.SocketEventService registerAtmosphereResourceINFO: Registering AtmosphereResource: 3bb382e9-7030-48b2-b9cc-111099cbd7a7Jun 26, 2015 11:12:24 AM ca.uhnresearch.pughlab.tracker.sockets.TrackerSocketHandler onReadySEVERE: No subject principal available And if I try to add the org.apache.shiro.web.env.EnvironmentLoaderListener, it then complains loudly because there isn’t a .ini file. Atmosphere is also being configured nicely by Spring, but it seems there really is a need for a WebEnvironment, because org.atmosphere.interceptor.ShiroInterceptor is expecting one. The likely fragment of code in Atmosphere is (at: https://github.com/Atmosphere/atmosphere/blob/master/modules/cpr/src/main/java/org/atmosphere/interceptor/ShiroInterceptor.java#L51 <https://github.com/Atmosphere/atmosphere/blob/master/modules/cpr/src/main/java/org/atmosphere/interceptor/ShiroInterceptor.java#L51> ): WebEnvironment env = WebUtils.getRequiredWebEnvironment(r.getAtmosphereConfig().getServletContext());currentUser = new WebSubject.Builder(env.getSecurityManager(), r.getRequest(), r.getResponse()).buildWebSubject(); So this is being accessed from the ServletContext. The question is, then, how do I get Shiro to configure to add a web environment to the servlet context when using Spring configuration? To answer the question: yes, I have the shiroFilter set up, both in the web.xml and properly configured in Spring. And for all web requests, it works just fine: the issue is only a factor for the Atmosphere ShiroInterceptor, which is set through an annotation (not by Spring, sadly). Any help gratefully received, and all the code is at: https://github.com/pughlab/tracker <https://github.com/pughlab/tracker> All the best Stuart
-- View this message in context: http://shiro-user.582556.n2.nabble.com/Getting-a-WebEnvironment-set-through-Spring-config-tp7580594.html Sent from the Shiro User mailing list archive at Nabble.com.
