使用Ajax登录Spring安全性

 诚实的大丈夫_196 发布于 2023-02-11 12:39

我正在尝试使用Spring Security处理基于Ajax的登录系统并且它工作正常,直到我得到了我需要配置的另一个需求authentication-success-handler,因此一旦用户通过Spring安全性进行身份验证,我就可以进行一些后期处理.

之前我没有用于显示登录页面.我的登录部分是一个下拉列表,它是标题部分的一部分,对于整个应用程序是常见的.

这就是我尝试配置Spring安全性的方法













 
    

使用这些配置,当我点击具有正确凭据的登录按钮时,我收到HTTP 302错误

http://localhost:8080/shop/customer/logon.html 302 found

不确定我究竟做错了什么?

Ajax代码

 var data = $(this).serializeObject();
  $.ajax({
  'type': 'POST',
  'url': "",
   'contentType': 'application/json',
    'data': JSON.stringify(data),
     'dataType': 'json',
....
}}:

登录部分

 Authentication authenticationToken = new UsernamePasswordAuthenticationToken(customer.getUserName(), customer.getPassword());
   try {
       Authentication authentication = customerAuthenticationManager.authenticate(authenticationToken);
        SecurityContextHolder.getContext().setAuthentication(authentication);
        resp.setStatus(AjaxResponse.RESPONSE_STATUS_SUCCESS);
           } catch (AuthenticationException ex) {

            resp.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
   }

有什么投入?经过我所有的努力,我仍然得到302并且具有上述配置,甚至我的logon.html控制器也没有被调用.

我的主要问题是当我使用Spring安全性时


302来自logon.html甚至logon.html控制器没有被触发(放置调试器)

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有