gpt4 book ai didi

java - j_security_check 不可用

转载 作者:太空宇宙 更新时间:2023-11-04 08:27:20 25 4
gpt4 key购买 nike

我正在使用 spring 3.0,我试图让我的登录页面正常工作,但出现此错误

The requested resource (/myapp/j_spring_security_check) is not available.

我正在发布与安全有关的所有文件的内容。希望这足够了。如果需要我可以展示更多。

这是我的 web.xml

    <servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<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>*.html</url-pattern>
</filter-mapping>

我的登录页面:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>Login Page</title>
<style>
.errorblock {
color: #ff0000;
background-color: #ffEEEE;
border: 3px solid #ff0000;
padding: 8px;
margin: 16px;
}
</style>
</head>
<body onload='document.f.j_username.focus();'>
<h3>Login with Username and Password (Custom Page)</h3>

<c:if test="${not empty error}">
<div class="errorblock">
Your login attempt was not successful, try again.<br /> Caused :
${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
</div>
</c:if>

<form name='f' action="<c:url value='j_spring_security_check' />"
method='POST'>

<table>
<tr>
<td>User:</td>
<td><input type='text' name='j_username' value=''>
</td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='j_password' />
</td>
</tr>
<tr>
<td colspan='2'><input name="submit" type="submit"
value="submit" />
</td>
</tr>
<tr>
<td colspan='2'><input name="reset" type="reset" />
</td>
</tr>
</table>

</form>

和我的安全上下文

<beans:bean id="passwordEncoder"
class="org.springframework.security.authentication.encoding.ShaPasswordEncoder">
<beans:constructor-arg value="256" />
</beans:bean>

<beans:bean id="saltSource"
class="org.springframework.security.authentication.dao.ReflectionSaltSource">
<beans:property name="userPropertyToUse" value="id" />
</beans:bean>

<authentication-manager alias="authenticationManager">
<authentication-provider ref="authProvider" />
</authentication-manager>

<beans:bean id="authProvider"
class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<beans:property name="userDetailsService" ref="personService" />
<beans:property name="passwordEncoder" ref="passwordEncoder" />
<beans:property name="saltSource" ref="saltSource" />
<beans:property name="includeDetailsObject" value="true" />
</beans:bean>

<beans:bean id="authenticationProcessingFilterEntryPoint"
class="org.springframework.security.web.authentication.AuthenticationProcessingFilterEntryPoint">
<beans:property name="forceHttps" value="false" />
<beans:property name="loginFormUrl" value="/login.html" />
</beans:bean>
<http entry-point-ref="authenticationProcessingFilterEntryPoint" auto-config="true">
<intercept-url pattern="/**" access="ROLE_USER" />
<intercept-url pattern="/login.html" filters="none" />
<form-login login-page="/login.html" default-target-url="/welcome.html"
authentication-failure-url="/loginfailed.html" />
<logout logout-success-url="/logout" />
</http>

有人可以帮我解决这个问题吗?

最佳答案

.html 绝对是过滤器设置方式所必需的。正确的方法是将 web.xml 中的 url-pattern 声明为/*。

如果您打算将 url-pattern 保留为 *.html,那么可能值得考虑将 login-processing-url 属性添加到您的 form-login 元素中,这样,如果有人返回并修改了 web.xml,一切都不会因为这个怪癖而崩溃。

<form-login login-page="/login.html" default-target-url="/welcome.html"
authentication-failure-url="/loginfailed.html" login-processing-url="j_spring_security_check.html"/>

关于java - j_security_check 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8248590/

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