Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring安全性无效登录处理_Java_Spring_Spring Mvc_Spring Security - Fatal编程技术网

Java Spring安全性无效登录处理

Java Spring安全性无效登录处理,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,我是Spring安全的新手,所以我尝试使用Spring MVC来处理无效登录,但最终导致页面未找到404 在我的security-context.xml中,我有一个AuthenticationProvider来处理所有的身份验证登录,因此基本上只是检查用户的帐户和密码,但出于某些原因,它一直说每当尝试登录无效时,都找不到身份验证失败url 但我有一个相应的控制器监听url模式来处理无效登录 @Controller public class LoginController { @Req

我是Spring安全的新手,所以我尝试使用Spring MVC来处理无效登录,但最终导致页面未找到404

在我的security-context.xml中,我有一个
AuthenticationProvider
来处理所有的身份验证登录,因此基本上只是检查用户的帐户和密码,但出于某些原因,它一直说每当尝试登录无效时,都找不到
身份验证失败url


但我有一个相应的控制器监听url模式来处理无效登录

@Controller
public class LoginController
{
    @RequestMapping(value = "/loginfailed", method = RequestMethod.GET)
    public String loginError(ModelMap model)
    {     
         model.addAttribute("error", "true");
         return "login";
    }
}
******更新******

在某些情况下,my
AuthenticationProvider
会验证用户,并在用户具有错误凭据时引发异常(我不知道这是否重要)

@Component
public class AuthenticationProvider{
    private User validateUser(String userName, String password)
    {
        try{
            //authenticate user's info
            .......
        }
        catch (UnauthorizedAccessException e)
        {
             throw new BadCredentialsException(e);
        }
    }
}
(作为评论的后续。)302 j_spring_security_check的状态和
BadCredentialsException
都是正确的。看起来你的控制器根本没有注册。您是否认为用
@Controller
注释bean不足以使其工作

您可以使用标准配置显式定义带注释的控制器bean 调度程序上下文中的Springbean定义。但是,
@Controller
原型还允许自动检测,与 Spring对检测组件类的通用支持 类路径和为它们自动注册bean定义

要启用此类带注释控制器的自动检测,请添加 组件扫描到您的配置。使用spring上下文 架构,如以下XML代码段所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.example"/>

    <!-- ... -->

</beans>

method=RequestMethod.GET
有效吗?不……我已经尝试了GET和POST。在我看来,这不是Spring的安全问题,而是MVC配置问题——对
/loginfailed
的简单POST/GET请求是否返回200状态?不,我从j_Spring_安全检查中得到302,然后是404未找到/loginfailed
<bean class="com.example.LoginController" />