【问题标题】:j-security-check tomcat security check is ok but jsp 403 errorj-security-check tomcat安全检查没问题但是jsp 403错误
【发布时间】:2013-05-26 19:23:10
【问题描述】:

tomcat7: 服务器.xml

<Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- 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 
            className="org.apache.catalina.realm.JDBCRealm"
            debug="99"
            driverName="oracle.jdbc.driver.OracleDriver" 
            connectionURL="jdbc:oracle:thin:@localhost:1521:orcl"
            connectionName="usertemp"
         connectionPassword="usertemp"
         userTable="users" 
         userNameCol="username" 
         userCredCol="password"
         userRoleTable="user_roles" 
         roleNameCol="rolename" />
      </Realm>

tomcat-users.xml:

<tomcat-users>

  <role rolename="manager"/>
  <user username="user1" password="password" roles="manager"/>
</tomcat-users>

web.xml:

<web-app>
    <security-constraint>
      <display-name>Example Security Constraint</display-name>
      <web-resource-collection>
         <web-resource-name>Protected Area</web-resource-name>
         <url-pattern>/protected/*</url-pattern>
         <url-pattern>/1/*</url-pattern>
       <http-method>DELETE</http-method>
         <http-method>GET</http-method>
         <http-method>POST</http-method>
       <http-method>PUT</http-method>
      </web-resource-collection>
      <auth-constraint>
           <role-name>manager</role-name>
      </auth-constraint>
      <user-data-constraint><transport-guarantee>NONE</transport-guarantee></user-data-constraint>
    </security-constraint>


    <!-- Default login configuration uses form-based authentication -->
    <login-config>
      <auth-method>FORM</auth-method>
      <realm-name>Example Form-Based Authentication Area</realm-name>
      <form-login-config>
        <form-login-page>/login.jsp</form-login-page>
        <form-error-page>/error.jsp</form-error-page>
      </form-login-config>
    </login-config>
    <security-role>
        <description> An administrator </description>
        <role-name>manager</role-name>
    </security-role>
</web-app>

1) 当我在 ie 中输入 url[http://localhost:8080/security-form-based/protected/index.jsp] 时, 2)返回登录,然后转发到login.jsp,输入用户名和密码, 3)但返回错误页面,我无法访问 index.jsp :

HTTP 状态 403 - 对所请求资源的访问被拒绝

所以,我不知道为什么?谁能帮我 ?谢谢。

【问题讨论】:

  • 嗨,Cody Guldner:我想问一下为什么我输入了正确的用户名和密码,tomcat已经从oracle验证ok,但是我无法访问index.jsp,所以你能理解吗我?我按照这个例子:onjava.com/pub/a/onjava/2002/06/12/form.html

标签: tomcat j-security-check


【解决方案1】:

你已经配置了JDBCRealm,但是附上了tomcat-users.xml的例子,用于注释掉UserDatabaseRealm。您的JDBCRealm 没有为您的用户返回角色manager 的问题(可能)。 一定要切换到UserDatabaseRealm

【讨论】:

  • 嗨,迈克尔,谢谢,我会检查它,但是我如何检查这个 tomcat 是否从 oracle 获得角色?
  • 先切换:) 根据你的配置'roleNameCol="rolename"
  • Michael:我刚刚解决了,你是对的,tomcat 没有从 db 获取角色,所以我检查我的 oracle 表 col 并添加主键,更新用户表 col 'password'-&gt;'pass',然后尝试它,终于成功了。3Q
猜你喜欢
  • 1970-01-01
  • 2018-12-10
  • 2021-09-08
  • 2013-10-28
  • 2013-02-23
  • 1970-01-01
  • 2012-04-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多