问题:JavaEE6 的实现在哪里?
我目前正在处理一个 JavaEE6 项目,我发现即使我已经根据文档配置了 web.xml 和 shiro.ini,Shiro 的注释也不能开箱即用。
这就是我所拥有的:
1.) 一个页面:
<h:form>
<h:commandLink action="#{userBean.action1()}" value="Action 1"></h:commandLink>
</h:form>
2.) 支持豆:
@Stateless
@Named
public class UserBean {
@Inject
private Logger log;
@RequiresAuthentication
public void action1() {
log.debug("action.1");
}
}
3.) web.xml
<listener>
<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
4.) shiro.ini
[main]
# listener = org.apache.shiro.config.event.LoggingBeanListener
shiro.loginUrl = /login.xhtml
[users]
# format: username = password, role1, role2, ..., roleN
root = secret,admin
guest = guest,guest
presidentskroob = 12345,president
darkhelmet = ludicrousspeed,darklord,schwartz
lonestarr = vespa,goodguy,schwartz
[roles]
# format: roleName = permission1, permission2, ..., permissionN
admin = *
schwartz = lightsaber:*
goodguy = winnebago:drive:eagle5
[urls]
# The /login.jsp is not restricted to authenticated users (otherwise no one could log in!), but
# the 'authc' filter must still be specified for it so it can process that url's
# login submissions. It is 'smart' enough to allow those requests through as specified by the
# shiro.loginUrl above.
/login.xhtml = authc
/logout = logout
/account/** = authc
/remoting/** = authc, roles[b2bClient], perms["remote:invoke:lan,wan"]
但是当我单击按钮时,它仍然执行操作。它应该抛出未经授权的异常吗?其他 shiro 注释也是如此。
请注意,如果我手动执行检查,它会起作用:
public void action1() {
Subject currentUser = SecurityUtils.getSubject();
AuthenticationToken token = new UsernamePasswordToken("guest", "guest");
currentUser.login(token);
log.debug("user." + currentUser);
if (currentUser.isAuthenticated()) {
log.debug("action.1");
} else {
log.debug("not authenticated");
}
}
谢谢,
czetsuya