spring-security 自定义登录页面Spring Security

ckx4rj1h  于 2022-11-11  发布在  Spring
关注(0)|答案(2)|浏览(157)

嗨,我是spring security的新手,我正在尝试为多个登录页面实现多个身份验证管理器。但是我被卡住了,因为我无法创建自定义的登录页面。这是我的Security.xml

<http auto-config='true' use-expressions="true" authentication-manager-ref="customAuthenticationManager1" >

<intercept-url pattern="/**" access="isAuthenticated()" />
<form-login
login-page='/Admin_Login.jsp'
login-processing-url="/j_spring_security_check.action"
default-target-url="/home.jsp"
always-use-default-target="true"/>
<logout logout-success-url="/login.html" />

<logout />
</http>

我的登录页面如下:-

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ADMIN LOGIN</title>
</head>
<body>
<form action="/j_spring_security_check" method="POST">
<label for="username">User Name:</label>
<input id="username" name="j_username" type="text"/>
<label for="password">Password:</label>
<input id="password" name="j_password" type="password"/>
<input type="submit" value="Log In"/>
</form>
</body>
</html>

但是当我尝试登录时,它没有进入身份验证管理器。
HTTP状态404 - /j_spring_security_check错误。所以有人可以告诉我哪里出错了。

kwvwclae

kwvwclae1#

在web.xml中设置了spring安全过滤器了吗?

<filter>
  <filter-name>springSecurityFilterChain</filter-name>
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
  <filter-name>springSecurityFilterChain</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>
</filter-mapping>
fafcakar

fafcakar2#

有两个选项

选项1:

<form-login>标记中删除login-processing-url属性,因为默认URL为 /j_spring_security_check

选项2:

login-processing-url="/j_spring_security_check.action"更改为login-processing-url="/j_spring_security_check"

相关问题