gpt4 book ai didi

java - JDBC 领域表单例份验证

转载 作者:行者123 更新时间:2023-11-29 20:59:47 25 4
gpt4 key购买 nike

我尝试使用 JDBC 领域表单例份验证来设置应用程序的安全性,但它不起作用。当我尝试登录页面时,只是重新加载,我没有收到错误,日志中没有任何内容。

这是 web.xml

<error-page>
<error-code>403</error-code>
<location>/faces/views/errors/403.xhtml</location>
</error-page>

<login-config>
<auth-method>FORM</auth-method>
<realm-name>jdbcRealm</realm-name>
<form-login-config>
<form-login-page>/faces/views/account/login.xhtml</form-login-page>
<form-error-page>/faces/views/account/loginerror.xhtml</form-error-page>
</form-login-config>
</login-config>

<security-constraint>
<web-resource-collection>
<web-resource-name>Admin user</web-resource-name>
<url-pattern>/faces/views/admin/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>

<security-constraint>
<web-resource-collection>
<web-resource-name>Admin user</web-resource-name>
<url-pattern>/faces/views/users/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
<role-name>guest</role-name>
</auth-constraint>
</security-constraint>

这是 glassfish-web.xml

<security-role-mapping>
<role-name>admin</role-name>
<group-name>admin</group-name>
</security-role-mapping>

<security-role-mapping>
<role-name>guest</role-name>
<group-name>guest</group-name>
</security-role-mapping>

表格

  <form method="POST" action="j_security_check">
Username: <input type="text" name="j_username" />
Password: <input type="password" name="j_password" />


<input type="submit" value="Login" />
<input type="reset" value="Reset" />
</form>
  1. JAAS 上下文:jdbcRealm
  2. JNDI:jdbc/kyrspr
  3. 用户表:USER
  4. 用户名列:NAME
  5. 密码列:PASSWORD
  6. 组表:USERS_GROUP
  7. 群组名称列:GROUP_NAME
  8. 密码加密算法:MD5

和数据库表

CREATE TABLE user (
ADDRESS VARCHAR(255),
EMAIL VARCHAR(255),
IMAGE VARCHAR(255),
NAME VARCHAR(255) PRIMARY KEY NOT NULL,
PASSWORD VARCHAR(255),
RATING DOUBLE,
SPECIALLITY_ID BIGINT(20) ); CREATE UNIQUE INDEX user_NAME_uindex ON user (NAME);


CREATE TABLE users_group
(
USER_ID VARCHAR(255),
GROUP_NAME VARCHAR(15) NOT NULL,
group_id BIGINT(20) PRIMARY KEY NOT NULL,
CONSTRAINT users_group_user_NAME_fk FOREIGN KEY (USER_ID) REFERENCES user (NAME)
);
CREATE UNIQUE INDEX users_group_group_id_uindex ON users_group (group_id);
CREATE INDEX users_group_user_NAME_fk ON users_group (USER_ID);

最佳答案

但是你有领域本身吗?尝试做类似的事情(此示例适用于 GF + mysql)

$ 导出 $DB_USER=my_user

$ 导出 $DB_PASSWORD=my_password

$ $GLASSFISH_HOME/bin/asadmin create-auth-realm --classname com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm --property db-user=$DB_USER:db-password=$DB_PASSWORD: jaas-context=jdbcRealm:password-column=密码:datasource-jndi=jdbc/myds:group-table=users:user-table=users:group-name-column=用户名:digest-algorithm=none:用户名-列=用户名myRealm

有关详细信息,请查看 asadmin create-auth-realm 文档。

关于java - JDBC 领域表单例份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37332468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com