gpt4 book ai didi

glassfish-3 - 尝试访问已实现的登录页面时,来自 glassfish 3 的 HTTP 状态 403 错误

转载 作者:行者123 更新时间:2023-12-04 02:40:31 26 4
gpt4 key购买 nike

我使用我发现的关于 Java EE6 和 GlassFish3 使用 netbeans 的一个很好的指南创建了一个登录页面。
部署项目后,当我尝试访问登录页面时,我从 GlassFish3 服务器收到“HTTP 状态 403 - 对请求的资源的访问已被拒绝”。

我使用的网址是:http://localhost:9999/simplewebapp/admin/admin.jsp
该指南说我应该自动重定向到我创建的登录页面。

相反,我收到了上述错误。
查看 glassfish3 日志,当我输入上述 url 时,我得到了这两行。

信息:JACC 策略提供者:权限检查失败:上下文(“simplewebapp/simplewebapp”),权限(“(javax.security.jacc.WebUserDataPermission/admin/login.jsp GET)”)
信息:JACC 策略提供者:权限检查失败:上下文(“simplewebapp/simplewebapp”),权限(“(javax.security.jacc.WebUserDataPermission/admin/login.jsp GET:CONFIDENTIAL)”)

更多细节:

网页.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<security-constraint>
<display-name>Admin Pages</display-name>
<web-resource-collection>
<web-resource-name>Administrative Pages</web-resource-name>
<description/>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>admin</description>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>file</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/loginerror.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>Administrators</description>
<role-name>admin</role-name>
</security-role>
<security-role>
<description>Users</description>
<role-name>user</role-name>
</security-role>
</web-app>

glassfish-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<security-role-mapping>
<role-name>admin</role-name>
<group-name>appadmin</group-name>
</security-role-mapping>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>

我在这里做错了什么?
谢谢你。

最佳答案

问题解决了。我必须在 glassfish-web.xml 中添加主体名称,在 web.xml 中添加角色名称。
正确的文件:

web-xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<security-constraint>
<display-name>Admin Pages</display-name>
<web-resource-collection>
<web-resource-name>Administrative Pages</web-resource-name>
<description/>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>admin</description>
<role-name>AdminRole</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>file</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/loginerror.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>Administrators</description>
<role-name>AdminRole</role-name>
</security-role>
<security-role>
<description>Users</description>
<role-name>UserRole</role-name>
</security-role>
</web-app>

glassfish-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<security-role-mapping>
<role-name>AdminRole</role-name>
<principal-name>admin</principal-name>
<group-name>appadmin</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>UserRole</role-name>
<principal-name>user</principal-name>
<group-name>appuser</group-name>
</security-role-mapping>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>

关于glassfish-3 - 尝试访问已实现的登录页面时,来自 glassfish 3 的 HTTP 状态 403 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9353827/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com