新增注销接口

This commit is contained in:
ShouChen 2022-03-02 00:11:47 +08:00
parent 1aa4607fe3
commit efe4570a5b
2 changed files with 14 additions and 1 deletions

View File

@ -27,7 +27,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.authorizeRequests()
.anyRequest().permitAll()
.and().formLogin().loginPage("/").permitAll()
.and().logout().logoutSuccessUrl("/").permitAll()
.and()
.addFilterAt(authenticationProcessingFilter, UsernamePasswordAuthenticationFilter.class)
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

View File

@ -1,10 +1,16 @@
package icu.mmmc.InventoryProMax.controller;
import icu.mmmc.InventoryProMax.vo.ResultStatus;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.security.PermitAll;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
/**
* 主页
@ -19,4 +25,12 @@ public class IndexController {
public ModelAndView userLogin() {
return new ModelAndView("/login.html");
}
@PermitAll
@ResponseBody
@PostMapping(value = "/logout")
public ResultStatus logout(HttpServletResponse response) {
response.addCookie(new Cookie(HttpHeaders.AUTHORIZATION, null));
return new ResultStatus(true, "/");
}
}