2

My Java Web Application にユーザー アクセス レベルを設定しようとしていますが、tomcat-user.xml ファイルで宣言した正しいユーザー名とパスワードを入力しても機能しません。ログインエラーページに移動します。基本認証方法も正しいユーザー名とパスワードを受け入れません。

この tomcat-users.xml

<tomcat-users>
<!--
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary.
-->
<!--
  NOTE:  The sample user and role entries below are wrapped in a comment
  and thus are ignored when reading this file. Do not forget to remove
  <!.. ..> that surrounds them.
-->
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>

-->
<role rolename=”Admin”/>
<role rolename=”Member”/>
<role rolename=”Doctor”/>
<role rolename=”Guest”/>
<user username=”sirojan” password=”sirojan” roles=”Admin” />
<user username=”ram” password=”ram123” roles=”Member” />
<user username=”vithu” password=”newbie” roles=”Guest” />
</tomcat-users>

これは server.xml ファイルの一部です

<Realm className="org.apache.catalina.realm.LockOutRealm">


    <Realm className="org.apache.catalina.realm.MemoryRealm" /> 

        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
<!-- <Realm className="org.apache.catalina.realm.MemoryRealm" /> -->
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/><!--
-->      </Realm>

これは私の web.xml ファイルの一部です

<security-role> 
        <role-name>Admin</role-name> 
    </security-role>
    <security-role>
        <role-name>Member</role-name> 
    </security-role>
    <security-role>
        <role-name>Guest</role-name> 
    </security-role>
    <security-role>
        <role-name>Doctor</role-name> 
    </security-role>
    <login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/login2.jsp</form-login-page>
            <form-error-page>/loginerror.jsp</form-error-page>
        </form-login-config>
    </login-config>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>AdminTasks</web-resource-name>
            <url-pattern>/Department.jsp</url-pattern>

            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>Admin</role-name>
            <role-name>Member</role-name>
        </auth-constraint>

    </security-constraint>
    <error-page>
        <error-code>404</error-code>
        <location>/notFoundError.jsp</location>
    </error-page> 

</web-app>

私は何か間違っていましたか??。さらに必要な場合は、コメントしてください。その解決策を教えてください。

4

1 に答える 1

0

まず、既存の役割があなたのために働いているかどうかを確認してください。

そのためには、tomcat-users.xml のロールのコメントを外す必要があります

それらが機能していて、Tomcat コンソールにログインできる場合、問題は構文です。

それらが機能していない場合は、エラーページのドキュメントを参照して、何をしているのかを確認する必要があります。これは簡単で、毎回機能するためです。

于 2012-08-16T04:41:28.930 に答える