37
37
@ EnableWebSecurity
38
38
public class SecurityConfiguration {
39
39
40
- private final String loginPage ;
41
-
42
- public SecurityConfiguration (@ Value ("${app.login-page}" ) String loginPage ) {
43
- this .loginPage = loginPage ;
44
- }
45
-
40
+ @ Value ("${spring.security.oauth2.resourceserver.jwt.jwk-set-uri}" )
41
+ private String jwksUri ;
46
42
@ Bean
47
43
public SecurityFilterChain securityFilterChain (HttpSecurity http ) throws Exception {
48
44
49
45
http
50
46
.cors (AbstractHttpConfigurer ::disable )
51
- //.cors(cors -> cors.configurationSource(corsConfigurationSource()))
52
47
.authorizeHttpRequests ((authorize ) -> authorize
53
48
.requestMatchers (
54
49
"/" ,
@@ -67,38 +62,6 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
67
62
.sessionCreationPolicy (SessionCreationPolicy .ALWAYS )
68
63
.maximumSessions (10 )
69
64
)
70
- /*
71
- .oauth2Client(Customizer.withDefaults())
72
-
73
- .oauth2Login((oauth2Login) -> oauth2Login
74
- //.loginPage()
75
- .loginProcessingUrl("/swagger-ui/index.html")
76
-
77
- //.loginPage(this.loginPage)
78
- )*/
79
- /*
80
- .logout((logout) -> logout
81
- .logoutUrl("/logout")
82
- .logoutSuccessUrl("/")
83
- .invalidateHttpSession(true)
84
- .deleteCookies("JSESSIONID")
85
- .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler())
86
- .permitAll()
87
- )*/
88
- /*.logout(logout -> logout
89
- .addLogoutHandler(
90
- new HeaderWriterLogoutHandler(
91
- new ClearSiteDataHeaderWriter(
92
- ClearSiteDataHeaderWriter.Directive.CACHE,
93
- ClearSiteDataHeaderWriter.Directive.COOKIES
94
- )
95
- )
96
- )
97
- .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
98
- .deleteCookies()
99
- .permitAll()
100
- )*/
101
-
102
65
.headers (headers -> headers
103
66
.httpStrictTransportSecurity ((hsts ) -> hsts
104
67
.includeSubDomains (true )
@@ -109,10 +72,11 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
109
72
new XFrameOptionsHeaderWriter (XFrameOptionsHeaderWriter .XFrameOptionsMode .DENY )
110
73
)
111
74
)
75
+
112
76
.oauth2ResourceServer (oauth2 -> oauth2
113
77
.jwt (jwt -> jwt
114
78
.jwtAuthenticationConverter (jwtAuthenticationConverter ())
115
- .jwkSetUri ("https://auth.coderic.org/.well-known/jwks.json" )
79
+ .jwkSetUri (jwksUri )
116
80
)
117
81
)
118
82
.requiresChannel (
@@ -138,24 +102,6 @@ public CorsConfigurationSource corsConfigurationSource() {
138
102
139
103
private JwtAuthenticationConverter jwtAuthenticationConverter () {
140
104
JwtAuthenticationConverter converter = new JwtAuthenticationConverter ();
141
- // Configura cómo deseas mapear los claims del token JWT a roles/autorizaciones
142
105
return converter ;
143
106
}
144
- @ Bean
145
- public JwtDecoder jwtDecoder () throws IOException , JOSEException , ParseException {
146
- // URL del JWKS de Auth0
147
- String jwkSetUri = "https://auth.coderic.org/.well-known/jwks.json" ;
148
- JWKSet jwkSet = JWKSet .load (new URL (jwkSetUri ));
149
- JWK jwk = jwkSet .getKeys ().get (0 );
150
- RSAKey rsaKey = (RSAKey ) jwk ;
151
- RSAPublicKey publicKey = rsaKey .toRSAPublicKey ();
152
- return NimbusJwtDecoder .withPublicKey (publicKey ).build ();
153
- }
154
- /*
155
- @Bean
156
- public JwtDecoder jwtDecoder() {
157
- // URI del JWKS de Auth0
158
- String jwkSetUri = "https://auth.coderic.org/.well-known/jwks.json";
159
- return NimbusJwtDecoder.withJwkSetUri(jwkSetUri).build();
160
- }*/
161
107
}
0 commit comments