I am doing spring webapp's integration, but the shiro can't load normally.
My Question is similar with the question org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code. However, it's solution is not for me.
In my web.xml the Shiro is configured like this:
<filter>
<filter-name>shiroFilter</>
<filter-calss>org.springframework.web.filter.DelegatingFilterProxy</>
<init-param>
<param-name>targetFilterLifecycle</>
<param-value>true</>
</>
</>
And my spring configuration applicationContext.xml is like this:
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="..."/>
<property name="sessionManager" ref="..."/>
</bean>
<bean id="shiroFilter" class="org.apache.shiro.spring.web.shiroFilterFactoryBean">
<property name="filters">
<map>
<entry key="ssl" value-ref="..."/>
<entry key="login" value-ref="..."/>
</map>
</>
<property name="securityManager" ref="securityManager"/>
<property .../>
</bean>
In the spring's Controller, I use the Shiro like this:
@RequestMapping(...)
public String login(){
...
Subject sb = SecurityUtils.getSubject();
if(sb.getPrincipal()!=null && sb.isAuthenticated()){
return "";
}
return "";
}
It can do well in my web app. However, when i do integration test with spring, problem coming. My test code like this:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextHirerchy({
load the previous applicationContext.xml
})
public class LoginIntegrationTest{
@Autowired WebApplicationContext wac;
MockMvc mockmvc;
@Before
public void setup(){
this. mockmvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void testLogin(){
this.mockmvc.perform("/login")
.andExpect(...);
}
}
And,the exception is :
org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.
It seems shiro didn't init right. Does anybody has the experience that integration test with Shiro, please tell me. Thank you very much.