gpt4 book ai didi

java - 基于 JDBCRealm FORM 的身份验证不重定向到登录页面

转载 作者:行者123 更新时间:2023-11-28 22:33:42 25 4
gpt4 key购买 nike

我正在尝试在 index.jsp 页面中应用身份验证,但是当我尝试加载此页面时,没有被重定向到 login2.xhtml 页面。我在 chrome 窗口上得到了这个。

this is realm tag from servlet.xml

这是在server.xml中添加的realm标签

<Realm className="org.apache.catalina.realm.JDBCRealm"

driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
connectionURL="jdbc:sqlserver://DESKTOP-ND3EINK\SQLEXPRESS;databaseName=HRSystem;user=ram;password=ram"

userTable="HR.users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="HR.user_roles" roleNameCol="role_name"/>

我在tomcat-users.xml中添加了用户

 <role rolename="tomcat"/> 
<role rolename="HRPersonnel"/>

<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="r@r.com" password="111111" roles="HRPersonnel"/>

而 web.xml 是:

<security-constraint>

<display-name>SecurityConstraint</display-name>

<web-resource-collection>
<web-resource-name>foo bar</web-resource-name>
<url-pattern>/index.jsp</url-pattern>
<!--
<http-method>GET</http-method>
<http-method>PUT</http-method>
<http-method>POST</http-method>
<http-method>DELETE</http-method> -->

</web-resource-collection>

<auth-constraint>
<role-name>HRPersonnel</role-name>
</auth-constraint>

<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>

</security-constraint>


<login-config>
<auth-method> FORM</auth-method>
<realm-name>org.apache.catalina.realm.JDBCRealm</realm-name>
<form-login-config>
<form-login-page>/login2.xhtml</form-login-page>
<form-error-page>/error.xhtml</form-error-page>
</form-login-config>
</login-config>

这些是数据库中的表

create table HR.users(
name varchar(50),
user_name varchar(50) primary key,
user_pass varchar(50) not null,
phone varchar (14),
address varchar(100),
)

create table HR.user_roles (
user_name varchar(50) not null foreign key references HR.users(user_name),
role_name varchar(50) not null CHECK (role_name = 'Applicant' OR role_name = 'Manager' OR role_name = 'SME' or role_name = 'HRPersonnel')

primary key (user_name, role_name)
);

Catalina.log 有 1 个警告但没有错误。

22-Apr-2017 19:00:21.929 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [C:\Program Files\Java\apache-tomcat-9.0.0.M13\bin\com.microsoft.sqlserver.jdbc.SQLServerDriver], exists: [false], isDirectory: [false], canRead: [false]

最佳答案

我不知道为什么

<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>

不工作,我将 CONFIDENTIAL 更改为 NONE,它开始工作。

关于java - 基于 JDBCRealm FORM 的身份验证不重定向到登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43560051/

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