Versiones comparadas

Clave

  • Se ha añadido esta línea.
  • Se ha eliminado esta línea.
  • El formato se ha cambiado.

...

Bloque de código
languagejava
package es.um.atica.[APLICACION].config;
 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter;
import org.springframework.security.web.SecurityFilterChain;

import es.um.atica.fundewebjs.api.filters.FundeWebJSLoggingAuthorizationFilter;

@Configuration  @Configuration
public class SecurityConfig {

	@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
	 */
	@Bean
    public SecurityFilterChain filterChain(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();

		return http.build();
	}

}

...