8
8
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
9
9
import org .springframework .security .config .annotation .web .configurers .AbstractHttpConfigurer ;
10
10
import org .springframework .security .config .http .SessionCreationPolicy ;
11
+ import org .springframework .security .oauth2 .jwt .JwtDecoder ;
12
+ import org .springframework .security .oauth2 .jwt .JwtDecoders ;
13
+ import org .springframework .security .oauth2 .server .resource .authentication .JwtAuthenticationConverter ;
11
14
import org .springframework .security .web .SecurityFilterChain ;
12
15
import org .springframework .security .web .authentication .logout .HeaderWriterLogoutHandler ;
13
16
import org .springframework .security .web .header .writers .ClearSiteDataHeaderWriter ;
@@ -53,15 +56,15 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
53
56
.sessionCreationPolicy (SessionCreationPolicy .ALWAYS )
54
57
.maximumSessions (10 )
55
58
)
56
-
59
+ /*
57
60
.oauth2Client(Customizer.withDefaults())
58
61
59
62
.oauth2Login((oauth2Login) -> oauth2Login
60
63
//.loginPage()
61
64
.loginProcessingUrl("/swagger-ui/index.html")
62
65
63
66
//.loginPage(this.loginPage)
64
- )
67
+ )*/
65
68
/*
66
69
.logout((logout) -> logout
67
70
.logoutUrl("/logout")
@@ -84,12 +87,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
84
87
.deleteCookies()
85
88
.permitAll()
86
89
)*/
87
- .formLogin (httpSecurityFormLoginConfigurer -> httpSecurityFormLoginConfigurer
88
- .loginPage ("/login" ).permitAll ()
89
- .defaultSuccessUrl ("/index" ))
90
- .logout (httpSecurityLogoutConfigurer -> httpSecurityLogoutConfigurer .permitAll ()
91
- .logoutRequestMatcher (new AntPathRequestMatcher ("/logout" ))
92
- .logoutSuccessUrl ("/login" ))
90
+
93
91
.headers (headers -> headers
94
92
.httpStrictTransportSecurity ((hsts ) -> hsts
95
93
.includeSubDomains (true )
@@ -99,6 +97,13 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
99
97
.addHeaderWriter (
100
98
new XFrameOptionsHeaderWriter (XFrameOptionsHeaderWriter .XFrameOptionsMode .DENY )
101
99
)
100
+ )
101
+ .oauth2ResourceServer (oauth2 -> oauth2
102
+ .jwt (jwt -> jwt
103
+ .jwkSetUri ("https://auth.coderic.org/.well-known/jwks.json" )
104
+ .jwtAuthenticationConverter (jwtAuthenticationConverter ()
105
+ )
106
+ )
102
107
)
103
108
.requiresChannel (
104
109
channel -> channel
@@ -120,4 +125,14 @@ public CorsConfigurationSource corsConfigurationSource() {
120
125
source .registerCorsConfiguration ("/**" , configuration ); // allow all paths
121
126
return source ;
122
127
}
128
+
129
+ private JwtAuthenticationConverter jwtAuthenticationConverter () {
130
+ JwtAuthenticationConverter converter = new JwtAuthenticationConverter ();
131
+ // Configura cómo deseas mapear los claims del token JWT a roles/autorizaciones
132
+ return converter ;
133
+ }
134
+ @ Bean
135
+ public JwtDecoder jwtDecoder () {
136
+ return JwtDecoders .fromIssuerLocation ("https://auth.coderic.org/" );
137
+ }
123
138
}
0 commit comments