【问题标题】:Tomcat j_security_check user IDTomcat j_security_check 用户 ID
【发布时间】:2013-03-24 12:02:40
【问题描述】:

Tomcat j_security_check 的快速问题...

任何人都知道如何在 user_role 表中将 'user_name' 更改为 'id',我更愿意这样做 通过匹配 ID 而不是用户名来验证

服务器.xml

<Realm  className="org.apache.catalina.realm.JDBCRealm"
        driverName="com.mysql.jdbc.Driver"
        connectionURL="jdbc:mysql://localhost/test"
        connectionName="root" connectionPassword="password"
        userTable="user" userNameCol="user_name" userCredCol="user_pass"
        userRoleTable="user_role_link" roleNameCol="role_id" />

表格

user
    id INT PK
    user_name PK
    user_pass
role
    id INT PK
    role_name
user_role
    user_id FK user_id to user.id
    role_id FK role_id to role.id

表格依旧:

<form method="post" action="j_security_check" name="loginForm">        
    <j:if test='${not empty param["failed"]}'>
        Invalid sign-in credentials<br/>
    </j:if>        
    <h:inputText id="j_username" autocomplete="off" />
    <br/>
    <h:inputSecret id="j_password" autocomplete="off"/>
    <br/>
    <h:commandButton type="reset" value="Clear"/>
    <h:commandButton type="submit" value="Login"/>          
</form>       

我已经让 role_id 工作,但使用 user_id 我只是得到一个

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'user_name' in 'where clause'

异常

提前致谢

KPS

【问题讨论】:

  • userNameCol="id"替换userNameCol="user_name"?
  • 我想过,但只是得到相同的 403 访问被拒绝和异常,但使用 'id' 而不是 user_name。

标签: java tomcat j-security-check


【解决方案1】:

tomcat j_security_check 无法做到这一点。如果username 是一个独特的字段,那么删除id 是更好的解决方案。但我建议你合并这两个表。您只能使用以下字段存储一张表:usernamepasswordrole。 (或者你可以添加id!)

我想这样,你的问题就解决了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 2021-09-11
    • 2010-11-30
    • 2014-08-15
    • 2015-02-13
    • 1970-01-01
    • 2012-06-05
    相关资源
    最近更新 更多