...
| Bloque de código | ||
|---|---|---|
| ||
package es.um.atica.[APLICACION].config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; import es.um.atica.fundewebjs.api.filters.FundeWebJSLoggingAuthorizationFilter; @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Value( "${server.scopes}" ) private String[] serverScopes; @Value( "${app.server.path}" ) private String apiPath; @Bean public FundeWebJSLoggingAuthorizationFilter loggingFilterBean() { return new FundeWebJSLoggingAuthorizationFilter(); } /** * Proveedor de gestion de acceoss */ @Override protected void configure( HttpSecurity http ) throws Exception { http.requestMatchers().antMatchers( "/public/**" ).and().requestMatchers().antMatchers( apiPath + "/**" ).and() .sessionManagement().sessionCreationPolicy( SessionCreationPolicy.STATELESS ) // configuro politica de sesion sin estado .and().cors() // Aniado configuracion CORS por defecto .and().csrf().disable().authorizeRequests().mvcMatchers( apiPath + "/public/**" ).permitAll() .mvcMatchers( apiPath + "/**" ).hasAnyAuthority( serverScopes ).anyRequest().authenticated().and() .addFilterAfter( loggingFilterBean(), BearerTokenAuthenticationFilter.class ) .oauth2ResourceServer().jwt(); } } |
...