feat: sercurity的配置文件新增加LogoutHandler的实现类 在LogoutFilter之前加入jwtAuthenticationTokenFilter
This commit is contained in:
parent
aab0ea4479
commit
093d6ee362
@ -1,6 +1,7 @@
|
|||||||
package com.cnbm.admin.config;
|
package com.cnbm.admin.config;
|
||||||
|
|
||||||
import com.cnbm.admin.filter.JwtAuthenticationTokenFilter;
|
import com.cnbm.admin.filter.JwtAuthenticationTokenFilter;
|
||||||
|
import com.cnbm.admin.handler.LogoutHandlerImpl;
|
||||||
import com.cnbm.admin.handler.LogoutSuccessHandlerImpl;
|
import com.cnbm.admin.handler.LogoutSuccessHandlerImpl;
|
||||||
import com.cnbm.admin.service.impl.UserDetailsServiceImpl;
|
import com.cnbm.admin.service.impl.UserDetailsServiceImpl;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -19,6 +20,8 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|||||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||||
import org.springframework.security.web.access.AccessDeniedHandler;
|
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
|
import org.springframework.security.web.authentication.logout.LogoutFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author weihongyang
|
* @Author weihongyang
|
||||||
* @Date 2022/6/8 1:51 PM
|
* @Date 2022/6/8 1:51 PM
|
||||||
@ -49,6 +52,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private LogoutSuccessHandlerImpl logoutSuccessHandler;
|
private LogoutSuccessHandlerImpl logoutSuccessHandler;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LogoutHandlerImpl logoutHandler;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
@ -72,12 +78,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.authenticated()
|
.authenticated()
|
||||||
// 退出登录,默认为/logout,这里修改接口地址为 /doLogout
|
// 退出登录,默认为/logout,这里修改接口地址为 /doLogout
|
||||||
.and().logout().logoutUrl("/doLogout")
|
.and().logout().logoutUrl("/doLogout")
|
||||||
|
.addLogoutHandler(logoutHandler)
|
||||||
// 设置退出登录成功处理程序,退出成功后返回JSON字符串
|
// 设置退出登录成功处理程序,退出成功后返回JSON字符串
|
||||||
.logoutSuccessHandler(logoutSuccessHandler);
|
.logoutSuccessHandler(logoutSuccessHandler);
|
||||||
|
|
||||||
//添加过滤器
|
//添加过滤器
|
||||||
http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
|
http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
|
||||||
|
http.addFilterBefore(jwtAuthenticationTokenFilter, LogoutFilter.class);
|
||||||
//配置异常处理器
|
//配置异常处理器
|
||||||
http.exceptionHandling()
|
http.exceptionHandling()
|
||||||
//配置认证失败处理器
|
//配置认证失败处理器
|
||||||
|
Loading…
Reference in New Issue
Block a user