Tomcat基本身份验证权限问题
我目前有一个通过 Tomcat 运行一些基本身份验证的 Web 服务。我可以正常弹出登录框,并且可以使用在 tomcat-users.xml 文件中定义的帐户登录。但是,当涉及到基于角色定义权限时,我遇到了一些问题。
目前,我有三个角色:经理、管理员和用户。我有一些方法只能由管理员角色访问。我可以作为我的经理/管理员/用户超级帐户登录,并看到一切都很好 - 但我也可以像普通用户一样做同样的事情。
这些方法的定义如下:
@Path("/Test")
@RolesAllowed("admin")
public class Test
{
@GET
@RolesAllowed("user")
public methodThatMyUsersCanAcess{}
@GET
@Path("/Secure")
@RolesAllowed("admin")
public methodThatOnlyAdminsCanAcess{}
}
我真的不确定“用户”角色如何能够访问第二种方法,但不知何故它仍然会发生。
I currently have a web service running some basic authentication through Tomcat. I get the login box to pop up fine, and I can log in with accounts I have defined in the tomcat-users.xml file. However, when it comes to defining permissions based on roles, I'm having some issues.
Currently, I have three roles: manager, admin, and user. I have a few methods which should be only accessible by, say, an admin role. I can log in as my manager/admin/user super account and see everything just fine- but I can do the same as a normal user as well.
The methods are defined like so:
@Path("/Test")
@RolesAllowed("admin")
public class Test
{
@GET
@RolesAllowed("user")
public methodThatMyUsersCanAcess{}
@GET
@Path("/Secure")
@RolesAllowed("admin")
public methodThatOnlyAdminsCanAcess{}
}
I'm really not sure how a 'user' role would be able to access the second method, but somehow it still happens.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过更多调查后,我发现由于 web.xml 文件的配置方式,使用
@RolesAllowed
在我的代码中没有执行任何操作。我决定转向通过 URI 路径设置身份验证。这是通过修改 web.xml 以允许用户子集访问单独的
标记下的每个路径来完成的。我在这里找到了最好的资源: http://www.coderanch.com/t/176095/java-Web-Component-SCWCD/certification/auth-constraint-confusion 在第二篇文章中。After some more investigation, I discovered that using
@RolesAllowed
was doing nothing in my code due to the way my web.xml file was configured. I decided to move in the direction of setting authentication by URI path. This is done through modifying the web.xml to allow a subset of users to access each path under separate<security-constraint>
tags. I found my best resource for this here: http://www.coderanch.com/t/176095/java-Web-Component-SCWCD/certification/auth-constraint-confusion in the second post.关键是在web.xml中配置
RolesAllowedResourceFilterFactory
,如下:The key point is to configure
RolesAllowedResourceFilterFactory
in web.xml, as below: