From 0c0f61aa0d259b2db1351e9462600085048d328a Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:31:31 +0000 Subject: [PATCH] fix remmeber me (#2184) * fix remmeber me * remove uselss comment * Update translation files (#2185) Signed-off-by: GitHub Action Co-authored-by: GitHub Action --------- Signed-off-by: GitHub Action Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: GitHub Action --- .../SPDF/config/security/SecurityConfiguration.java | 10 +++++++--- .../SPDF/repository/JPATokenRepositoryImpl.java | 11 +++++++---- .../SPDF/repository/PersistentLoginRepository.java | 4 +++- src/main/resources/messages_cs_CZ.properties | 2 +- src/main/resources/messages_da_DK.properties | 2 +- src/main/resources/messages_pt_PT.properties | 4 ++-- src/main/resources/messages_ru_RU.properties | 2 +- src/main/resources/templates/login.html | 4 ++-- 8 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java b/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java index 8156e8d6..1b7d37d6 100644 --- a/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java +++ b/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java @@ -156,10 +156,14 @@ public class SecurityConfiguration { http.rememberMe( rememberMeConfigurer -> rememberMeConfigurer // Use the configurator directly - .key("uniqueAndSecret") .tokenRepository(persistentTokenRepository()) - .tokenValiditySeconds(1209600) // 2 weeks - ); + .tokenValiditySeconds(14 * 24 * 60 * 60) // 14 days + .userDetailsService( + userDetailsService) // Your existing UserDetailsService + .useSecureCookie(true) // Enable secure cookie + .rememberMeParameter("remember-me") // Form parameter name + .rememberMeCookieName("remember-me") // Cookie name + .alwaysRemember(false)); http.authorizeHttpRequests( authz -> authz.requestMatchers( diff --git a/src/main/java/stirling/software/SPDF/repository/JPATokenRepositoryImpl.java b/src/main/java/stirling/software/SPDF/repository/JPATokenRepositoryImpl.java index a901d3c3..7b2e58ff 100644 --- a/src/main/java/stirling/software/SPDF/repository/JPATokenRepositoryImpl.java +++ b/src/main/java/stirling/software/SPDF/repository/JPATokenRepositoryImpl.java @@ -5,6 +5,7 @@ import java.util.Date; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken; import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository; +import org.springframework.transaction.annotation.Transactional; import stirling.software.SPDF.model.PersistentLogin; @@ -13,6 +14,7 @@ public class JPATokenRepositoryImpl implements PersistentTokenRepository { @Autowired private PersistentLoginRepository persistentLoginRepository; @Override + @Transactional public void createNewToken(PersistentRememberMeToken token) { PersistentLogin newToken = new PersistentLogin(); newToken.setSeries(token.getSeries()); @@ -23,6 +25,7 @@ public class JPATokenRepositoryImpl implements PersistentTokenRepository { } @Override + @Transactional public void updateToken(String series, String tokenValue, Date lastUsed) { PersistentLogin existingToken = persistentLoginRepository.findById(series).orElse(null); if (existingToken != null) { @@ -43,11 +46,11 @@ public class JPATokenRepositoryImpl implements PersistentTokenRepository { } @Override + @Transactional public void removeUserTokens(String username) { - for (PersistentLogin token : persistentLoginRepository.findAll()) { - if (token.getUsername().equals(username)) { - persistentLoginRepository.delete(token); - } + try { + persistentLoginRepository.deleteByUsername(username); + } catch (Exception e) { } } } diff --git a/src/main/java/stirling/software/SPDF/repository/PersistentLoginRepository.java b/src/main/java/stirling/software/SPDF/repository/PersistentLoginRepository.java index 92d7bb81..e8ef19ce 100644 --- a/src/main/java/stirling/software/SPDF/repository/PersistentLoginRepository.java +++ b/src/main/java/stirling/software/SPDF/repository/PersistentLoginRepository.java @@ -6,4 +6,6 @@ import org.springframework.stereotype.Repository; import stirling.software.SPDF.model.PersistentLogin; @Repository -public interface PersistentLoginRepository extends JpaRepository {} +public interface PersistentLoginRepository extends JpaRepository { + void deleteByUsername(String username); +} diff --git a/src/main/resources/messages_cs_CZ.properties b/src/main/resources/messages_cs_CZ.properties index 12750f0b..d8282674 100644 --- a/src/main/resources/messages_cs_CZ.properties +++ b/src/main/resources/messages_cs_CZ.properties @@ -527,7 +527,7 @@ replace-color.selectText.8=Zlutý text na černém pozadí replace-color.selectText.9=Zelený text na černém pozadí replace-color.selectText.10=Vyberte barvu textu replace-color.selectText.11=Vyberte barvu pozadí -replace-color.submit= Nahradit +replace-color.submit=Nahradit diff --git a/src/main/resources/messages_da_DK.properties b/src/main/resources/messages_da_DK.properties index ec6ea838..48ad3a9b 100644 --- a/src/main/resources/messages_da_DK.properties +++ b/src/main/resources/messages_da_DK.properties @@ -119,7 +119,7 @@ pipelineOptions.validateButton=Validér enterpriseEdition.button=Opgrader til Pro enterpriseEdition.warning=Denne funktion er kun tilgængelig for Pro-brugere. enterpriseEdition.yamlAdvert=Stirling PDF Pro understøtter YAML-konfigurationsfiler og andre SSO-funktioner. -enterpriseEdition.ssoAdvert= søger du flere funktioner til brugerstyring? Prøv Stirling PDF Pro +enterpriseEdition.ssoAdvert=søger du flere funktioner til brugerstyring? Prøv Stirling PDF Pro ################# diff --git a/src/main/resources/messages_pt_PT.properties b/src/main/resources/messages_pt_PT.properties index ac505f7e..2bf6a5dd 100644 --- a/src/main/resources/messages_pt_PT.properties +++ b/src/main/resources/messages_pt_PT.properties @@ -97,7 +97,7 @@ pipeline.configureButton=Configurar pipeline.defaultOption=Personalizar pipeline.submitButton=Submeter pipeline.help=Pipeline Help -pipeline.scanHelp= Ajuda ao Escaneamento de Pastas +pipeline.scanHelp=Ajuda ao Escaneamento de Pastas pipeline.deletePrompt=Tem a certeza que quer eliminar o pipeline? ###################### @@ -191,7 +191,7 @@ account.changePassword=Alterar a Senha account.confirmNewPassword=Confirmar Nova Senha account.signOut=Sair do Sistema account.yourApiKey=Sua Chave API -account.syncTitle= sincronizar definições do navegador com a conta +account.syncTitle=sincronizar definições do navegador com a conta account.settingsCompare=Comparação das Definições: account.property=Propriedade account.webBrowserSettings=Configurações do Navegador Web diff --git a/src/main/resources/messages_ru_RU.properties b/src/main/resources/messages_ru_RU.properties index 637f231c..2773d066 100644 --- a/src/main/resources/messages_ru_RU.properties +++ b/src/main/resources/messages_ru_RU.properties @@ -359,7 +359,7 @@ PDFToHTML.tags=web content,browser friendly home.PDFToXML.title=PDF в XML home.PDFToXML.desc=Преобразование PDF в формат XML -PDFToXML.tags= extraksi data,структурированный контент,interop,преобразование,конвертация +PDFToXML.tags=extraksi data,структурированный контент,interop,преобразование,конвертация home.ScannerImageSplit.title=Обнаружение/разделение отсканированных фотографий home.ScannerImageSplit.desc=Разделяет несколько фотографий из фото/PDF diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html index 9bc07c24..56485aea 100644 --- a/src/main/resources/templates/login.html +++ b/src/main/resources/templates/login.html @@ -90,8 +90,8 @@
- - + +