2

フォームベースの認証を試していますが、ログイン ページに正しいユーザー/パスワードを入力した後、なぜではなくエラー ページにリダイレクトされるのかわかりませんでしindex.jspた。

入力すると:

http://localhost:8080/<context>/secure/index.jsp

ログインページを取得します。ただし、ユーザー/パスワード (manager/manager) を入力すると、error.html代わりにindex.jsp.

Web.XML:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>FormBasedAuthentication</display-name>
<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.html</form-login-page>
        <form-error-page>/error.html</form-error-page>
    </form-login-config>
</login-config>
<security-role>
    <role-name>role1</role-name>
</security-role>    
<security-constraint>
    <web-resource-collection>
        <web-resource-name>SecurePages</web-resource-name>
        <description>Security constraint for JSP resources</description>
        <url-pattern>/secure/*</url-pattern>
        <http-method>POST</http-method>
        <http-method>GET</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>role1</role-name>
    </auth-constraint>
    <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>

TOMCAT-USER.XML:

<tomcat-users>
   <role rolename="manager-gui"/>
   <role rolename="manager-script"/>
   <role rolename="manager-status"/>
   <role rolename="manager-jmx"/>
   <role rolename="role1"/>
   <user username="manager" password="manager" roles="role1"/>
</tomcat-users>
4

3 に答える 3

2

Tomcat 構成のサーバーの場所は、「ワークスペース メタデータを使用する」ではなく「Tomcat インストールを使用する」である必要があります。

于 2013-09-30T16:03:30.277 に答える
2

要素に (の代わりに)を含める必要がありauth-constraintます。を使用すると指定. このユーザーまたはロールは、 内の web.xml で定義する必要があります。security-constraintuser-data-constraintauth-constraintweb-resource-collectionsecurity-role tag

最終的な web.xml コンテンツは次のようになります。

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID"
         version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>FormBasedAuthentication</display-name>
    <login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/login.jsp</form-login-page>
            <form-error-page>/error.html</form-error-page>
        </form-login-config>
    </login-config>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>SecurePages</web-resource-name>
            <description>Security constraint for resources in the secure directory</description>
            <url-pattern>/secure/*</url-pattern>
            <http-method>POST</http-method>
            <http-method>GET</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>admin</role-name>
        </auth-constraint>
    </security-constraint>
    <security-role>
        <role-name>admin</role-name>
    </security-role>
</web-app>
于 2013-09-24T19:38:24.513 に答える