0

Java サーブレットと JSP を独学しようとしていますが、Tomcat 7 と Postgres 9.1 での認証に問題があります。

エラーはないようです (Tomcat はログ ファイルに JAVA エラーをスローしていません)。ユーザー名とパスワードがpostgres内のテーブルスペースの内容とほとんど一致しません。

コードに余分なログを導入して、何がクエリされ、何が返され、なぜ不一致があるのか​​を確認する方法はありますか? これは確かにトラブルシューティングの取り組みに役立ちます。

参考までに、context.xml (META_INF)、web.xml (WEB_INF)、およびログイン html を添付します)

私はあなたの助けに感謝します

<?xml version="1.0" encoding="UTF-8"?>

<web-app 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_2_5.xsd"
     version="2.5">

    <!-- Define two security roles -->
    <security-role>
        <description>customer service testers</description>
        <role-name>testing</role-name>
    </security-role>
    <security-role>
        <description>system developers</description>
        <role-name>developer</role-name>
    </security-role>

    <!-- Restrict access to all files in the /admin folder -->
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Protected Area</web-resource-name>
            <url-pattern>/admin/*</url-pattern>
        </web-resource-collection>
        <!-- Authorize the programmer and service roles -->
        <auth-constraint>
            <role-name>developer</role-name>
            <role-name>testing</role-name>
        </auth-constraint>
    </security-constraint>

    <!-- Use form-based authentication -->
    <!--<login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/admin/login.html</form-login-page>
            <form-error-page>/admin/login_error.html</form-error-page>
        </form-login-config>
    </login-config>
    --> 

    <!-- Use basic authentication -->

    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>Admin Login</realm-name>
    </login-config>


     <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>



<?xml version="1.0" encoding="UTF-8"?>
<Context path="/AUTHExample">
    <Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
          driverName="org.postgresql.Driver"
          connectionURL="jdbc:postgresql://localhost:5432/mydb"
          connectionName="postgres" connectionPassword="postgres"
          userTable="userpass" userNameCol="user" userCredCol="passwd"
          userRoleTable="userrole" roleNameCol="rolename" 
          />

</Context>




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>Learning to Authenticate</title>
</head>

<body>
<h1>Admin Login Form</h1>
<p>Please enter your username and password to continue.</p>
<table cellspacing="5" border="0">
  <form action="j_security_check" method="get">
    <tr>
        <td align="right">Username</td>
        <td><input type="text" name="j_username"></td>
    </tr>
    <tr>
        <td align="right">Password</td>
        <td><input type="password" name="j_password"></td>
    </tr>
    <tr>
      <td><input type="submit" value="Login"></td>
    </tr>
  </form>
</table>
</body>
</html>
4

1 に答える 1

0

さて、私は自分の問題を解決し、これがどのくらいの頻度で発生するかを考えて、将来遭遇した人のために答えようと思いました.

上記の問題は、ユーザー/パスワード テーブルとロール名テーブルのユーザー名の列名が異なることが原因でした。SQL は、ユーザーではなく「ユーザー」を割り当てていました。

ロールが web.xml で適切に定義されていない場合、ユーザー名とパスワードが正しいときに 403 エラーが表示されることに注意してください。

それが助けになったことを願っています

ありがとうございました

于 2013-04-14T06:17:34.843 に答える