【发布时间】:2015-05-29 09:38:54
【问题描述】:
在 tomcat-users.xml 中定义了用户和角色:
<user username="admin" password="admin" roles="user,admin,APP_ADMIN"/>
<role rolename="user"/>
<role rolename="APP_ADMIN"/>
<role rolename="admin"/>
应用安全性定义为:
<security-constraint>
<web-resource-collection>
<web-resource-name>Dynamic pages</web-resource-name>
<url-pattern>*.jsp</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>These are the roles who have access.</description>
<role-name>*</role-name>
</auth-constraint>
<user-data-constraint>
<description></description>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
但是当我以管理员身份登录应用程序时,它总是给我 HTTP 403 未授权。
我用 JSP 脚本检查了角色:
out.write(request.getUserPrincipal().toString());
然后打印出来:
用户用户名="admin",角色="user,admin,APP_ADMIN"
但是当我检查 isUserInRole:
out.write(request.isUserInRole("APP_ADMIN") ? "Yep" : "nope");
获取:
没有
Tomcat 版本是 7.0.55
【问题讨论】:
-
你也定义了角色吗?
-
嗨,是的,我将它们添加到问题中。
-
哎呀。你也配置了内存领域吗?
-
是的,也定义了一个,如果我输入错误,我也可以使用密码 admin-admin 登录,它不会让我登录,所以它看起来像是在加载 tomcat-users.xml跨度>
-
那我不太确定:(我建议你把你的
server.xml和tomcat-users.xml的相关部分也贴出来,也许别人会有什么。
标签: java jsp security tomcat jakarta-ee