j-security-check tomcat安全检查正常,但jsp 403错误

j-security-check tomcat安全检查正常,但jsp 403错误,tomcat,j-security-check,Tomcat,J Security Check,tomcat7: server.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

tomcat7: server.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/*
删除
得到
邮递
放
经理
没有一个
形式
基于表单的身份验证区域示例
/login.jsp
/error.jsp
管理员
经理
1) 当我输入url[
http://localhost:8080/security-ie中基于表单的/protected/index.jsp
], 2) 返回到login,然后forword到login.jsp,输入用户名和密码, 3) 但是返回错误页面,我无法访问index.jsp:

HTTP状态403-已拒绝访问请求的资源


所以,我不知道为什么?有人能帮我吗?谢谢。

您已经配置了
JDBCRealm
,但附上了tomcat-users.xml示例,该示例用于注释掉的
UserDatabaseRealm
。您的
jdbcream
没有为您的用户返回角色
manager
,这可能是一个问题。
为了确保切换到
UserDatabaseRealm

嗨,科迪·古德纳:我想问一下为什么我输入了正确的用户名和密码,tomcat已经从oracle验证了ok,但是我不能访问index.jsp,所以你能理解我吗?我举个例子:嗨,Michael,谢谢,我会检查它,但是我如何检查tomcat是否从oracle获取角色?首先切换:)根据您的配置Michael:我刚刚解决了这个问题,您是对的,tomcat没有从db获取角色,所以我检查我的oracle表列并添加主键,更新用户表列
'password'->'pass'
,然后重试,终于成功了