aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/config')
-rw-r--r--src/main/java/com/juick/config/SecurityConfig.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main/java/com/juick/config/SecurityConfig.java b/src/main/java/com/juick/config/SecurityConfig.java
index c557ab4e6..030cdcc21 100644
--- a/src/main/java/com/juick/config/SecurityConfig.java
+++ b/src/main/java/com/juick/config/SecurityConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2023, Juick
+ * Copyright (C) 2008-2024, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -19,7 +19,6 @@ package com.juick.config;
import com.juick.ActivityPubManager;
import com.juick.KeystoreManager;
-import com.juick.service.ActivityPubService;
import com.juick.service.UserService;
import com.juick.service.security.HTTPSignatureAuthenticationFilter;
import com.juick.service.security.HashParamAuthenticationFilter;
@@ -42,6 +41,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
+import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.oauth2.jwt.JwtDecoder;
import org.springframework.security.oauth2.server.authorization.client.JdbcRegisteredClientRepository;
@@ -268,6 +268,16 @@ public class SecurityConfig {
.invalidateHttpSession(true)
.clearAuthentication(true)
.logoutSuccessUrl("/login")
+ .addLogoutHandler((request, response, authentication) -> {
+ var auth = SecurityContextHolder.getContext().getAuthentication();
+ if (auth != null) {
+ var principal = auth.getPrincipal();
+ if (principal instanceof JuickUser) {
+ var user = ((JuickUser) principal).getUser();
+ userService.logout(user.getUid());
+ }
+ }
+ })
.deleteCookies("hash", COOKIE_NAME))
.formLogin(form -> form.loginPage("/login")
.usernameParameter("username")