diff --git a/src/main/java/icu/mmmc/InventoryProMax/configuration/WebSecurityConfig.java b/src/main/java/icu/mmmc/InventoryProMax/configuration/WebSecurityConfig.java index b471770..a7beb90 100644 --- a/src/main/java/icu/mmmc/InventoryProMax/configuration/WebSecurityConfig.java +++ b/src/main/java/icu/mmmc/InventoryProMax/configuration/WebSecurityConfig.java @@ -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); diff --git a/src/main/java/icu/mmmc/InventoryProMax/controller/IndexController.java b/src/main/java/icu/mmmc/InventoryProMax/controller/IndexController.java index d55c8fd..2dfeab4 100644 --- a/src/main/java/icu/mmmc/InventoryProMax/controller/IndexController.java +++ b/src/main/java/icu/mmmc/InventoryProMax/controller/IndexController.java @@ -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, "/"); + } }