mirror of
https://github.com/AJMicke/KickerELO.git
synced 2026-03-11 13:31:02 +01:00
Add remember me function
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package org.kickerelo.kickerelo.config;
|
package org.kickerelo.kickerelo.config;
|
||||||
|
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Base64;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
@@ -10,14 +12,25 @@ import com.vaadin.flow.spring.security.VaadinWebSecurity;
|
|||||||
@Configuration
|
@Configuration
|
||||||
class SecurityConfiguration extends VaadinWebSecurity {
|
class SecurityConfiguration extends VaadinWebSecurity {
|
||||||
|
|
||||||
|
private static String rememberMeSecret = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
|
if (rememberMeSecret == null) rememberMeSecret = generateSecret();
|
||||||
|
|
||||||
http.authorizeHttpRequests(auth -> auth
|
http.authorizeHttpRequests(auth -> auth
|
||||||
.requestMatchers("/app/admin/**", "/app/admin", "/app/app/admin/**", "/app/app/admin").hasAuthority("Kicker Admin")
|
.requestMatchers("/app/admin/**", "/app/admin", "/app/app/admin/**", "/app/app/admin").hasAuthority("Kicker Admin")
|
||||||
.anyRequest().permitAll()
|
.anyRequest().permitAll())
|
||||||
)
|
.rememberMe(rememberMe -> rememberMe.key(rememberMeSecret))
|
||||||
.oauth2Login(org.springframework.security.config.Customizer.withDefaults())
|
.oauth2Login(org.springframework.security.config.Customizer.withDefaults())
|
||||||
.logout(logout -> logout.logoutSuccessUrl("/"))
|
.logout(logout -> logout.logoutSuccessUrl("/"))
|
||||||
.csrf(csrf -> csrf.disable());
|
.csrf(csrf -> csrf.disable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String generateSecret() {
|
||||||
|
SecureRandom random = new SecureRandom();
|
||||||
|
byte[] bytes = new byte[24];
|
||||||
|
random.nextBytes(bytes);
|
||||||
|
return Base64.getEncoder().encodeToString(bytes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user