Spring Security简单实现自定义退出功能

1.前端页面写法

<a href="javascript:;" onclick="logoutBackground()">退出</a>

2.js

/**
 * 退出后台
 */
function logoutBackground() {
    $.get("/admin/logout", function (msg) {
        if (msg === "true") {
            window.location.href = "/userlogin";//自定义静态页面路径
        } else {
            alert("退出异常!");
        }
    });
}

3.security配置

 //登出操作
.logout().logoutUrl("/admin/logout")
.logoutSuccessHandler((request, response, authentication) -> {
  PrintWriter writer = response.getWriter();
  writer.write("true");
  writer.close();
            }).permitAll()

原文地址:https://www.cnblogs.com/pengwenfeng/p/9902732.html

时间: 2024-08-03 09:48:11

Spring Security简单实现自定义退出功能的相关文章

Spring Security笔记:自定义Login/Logout Filter、AuthenticationProvider、AuthenticationToken

在前面的学习中,配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Security文档的说明: ------------------ auto-config Automatically registers a login form, BASIC authentication, logout services. If set to "true", all of thes

【Spring Security 四】自定义页面

在前面例子中,登陆页面都是用的Spring Security自己提供的,这明显不符合实际开发场景,同时也没有退出和注销按钮,因此在每次测试的时候都要通过关闭浏览器来注销达到清除session的效果. 一 .自定义页面 login.jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE

spring security实现限制登录次数功能

本节是在基于注解方式进行的,后面的例子都会基于注解形式,不再实现XML配置形式,毕竟注解才是趋势嘛! 关键在于实现自定义的UserDetailsService和AuthenticationProvider 项目结构如下: 查看spring security的源代码可以发现默认security已经定义的user中的一些变量,鉴于此创建users表如下: CREATE TABLE users ( username VARCHAR(45) NOT NULL, password VARCHAR(45)

Spring Security 3.1 自定义 authentication provider

前言 在使用Spring Security的时候,遇到一个比较特殊的情况,需要根据用户名.邮箱等多个条件去验证用户或者使用第三方的验证服务来进行用户名和密码的判断,这样SS(Spring Security,一下简称SS)内置的authentication provider和user detail service就不能用了,花了一些时间去寻找其他的办法. 前置条件 Spring MVC 结构的Web项目 Spring Security 使用第三方的Service验证用户名密码(并非数据库或者Ope

Spring Security(十):3. What’s New in Spring Security 4.2 (新功能)

Among other things, Spring Security 4.2 brings early support for Spring Framework 5. You can find the change logs for 4.2.0.M1, 4.2.0.RC1, 4.2.0.RELEASE which closes over 80 issues. The overwhelming majority of these features were contributed by the

Spring Security简单的登陆验证授权

Spring Security的介绍就省略了,直接记录一下登陆验证授权的过程. Spring Security的几个重要词 1.SecurityContextHolder:是安全上下文容器,可以在此得知操作的用户是谁,该用户是否已经被认证,他拥有哪些角色权限-这些都被保存在SecurityContextHolder中. Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

重构Spring Security实现图形验证码的功能

不单要写完功能,而是要把它变的可以配置,供其他的应用可以使用优化要点 验证码的基本参数可配置(宽/高/验证码数字的长度/验证码的有效时间等) 验证码的拦截接口可配置(url地址) 验证码的生成逻辑可配置(更复杂的验证码生成逻辑) 1.验证码的基本参数可配置 在调用方 调用验证码的时候,没有做任何配置,则使用默认的验证码生成规则,如果有则覆盖掉默认配置.默认配置 //生成二维码默认配置 public class ImageCodeProperties { private int width = 6

Spring Security实现图形验证码的功能

一.生成图片验证码的步骤1.根据随机数生成数字2.将随机数存到Session中3.将生成的图片写到接口的响应中 public class ImageCode { private BufferedImage image;//展示的图片 private String code;//生成的随机数,Session private LocalDateTime expireTime;//过期时间 public BufferedImage getImage() { return image; } public

Spring Security(4):自定义配置

接着上节的讲,在添加了@EnableWebSecurity注解后,如果需要自定义一些配置,则需要和继承WebSecurityConfigurerAdapter后,覆盖某些方法. 我们来看一下WebSecurityConfigurerAdapter中哪些方法可以重写,需要重写. (1)WebSecurity 默认是一个空方法,一般也不会再重写. public void configure(WebSecurity web) throws Exception { } (2)HttpSecurity 默