问题:
设置好web.xml 中security-constraint 后,登陆后老是提示403

<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app version=”3.1″ xmlns=”http://xmlns.jcp.org/xml/ns/javaee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd”>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<security-constraint>
<display-name>需要登陆</display-name>
<web-resource-collection>
<web-resource-name>all</web-resource-name>
<description/>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>管管</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>file</realm-name>
</login-config>
<security-role>
<description/>
<role-name>管管</role-name>
</security-role>
</web-app>

 

 

解决:
在glassfish-web.xml 中增加security-role-mapping,如:

<?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>管管</role-name>
<group-name>管管</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>

发表评论

电子邮件地址不会被公开。