0
我在Shiro中使用Spring,在我的Spring項目中,我有一個通過sitemesh顯示裝飾頁面的裝飾控制器。裝飾頁面添加到每個頁面導航鏈接上,例如登錄和註銷。在Spring裝飾控制器中不能使用Shiro的主題
我想登錄和註銷根據是否有人或不實際登錄出現,所以我這樣做是這樣的方式:
@Controller
public class DecoratorController extends AbstractController{
@Override
@RequestMapping(value = "/decorator.htm")
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
ModelAndView model = new ModelAndView("DecoratorPage");
Subject currentUser = SecurityUtils.getSubject();
if (currentUser.isAuthenticated())
model.addObject("login", "display: none;");
else
model.addObject("logout", "display: none;");
return model;
}
}
sitemesh.xml:
<sitemesh>
<mapping path="/*.htm" decorator="/decorator.htm"/>
</sitemesh>
然而,這會導致錯誤:
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.
爲什麼我不能在這裏使用Shiro,但是我可以在其他控制器中使用它?