springboot +vue3.0 退出登录

vue+springboot+oauth2认证退出时会后端会检测到认证信息再次认证登录。
在这里记录一下如何实现退出跳转到登录页,这里使用的比较简单的方法
1、在UAA认证微服务中控制层增加增加 ManagerProjectAOP.java
2、在前段点击退出时跳转到code获取页面

package com.lxfamn.im.security.uaa.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;

@Component
@Aspect
@Order(4)
public class ManagerProjectAOP {

    /**
    * 清除authorize用户信息
     * 切入点,切入oauth2.0中的授权码授权的方法
     */
    @Pointcut("execution(* org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint.authorize(..))  ")

    public void check() {
    }

    /**
     * 前置通知,
     * 主要作用是,子系统前后端分离时,退出并不能正确的清除SSO的login的用户信息,因为它是存在服务器上的,前端无法清除,用后端清除但因为是前后端分离,
     * 注销并不能正确携带request给服务器来清空用户登录信息,所以会出现,注销登录再次访问authorize授权接口会默认使用cookie导致登录成功跳过登录页面
     * 功能:切入authorize接口,在使用authorize获取code之前,做一次清除用户信息的操作,使得每次获取code都是未登录状态
     * @param
     * @return Object
     * @throws Throwable
     */
    @Before(("check()"))
    public void beforeMethod(JoinPoint joinPoint) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        //清除用户信息
        request.getSession().invalidate();
    }
}

转载请注明出处:

转载自http://lxfamn.cn/blog

未经允许不得转载:lxfamn » springboot +vue3.0 退出登录

赞 (0) 打赏

置顶推荐

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏