Spring Security: Unterschied zwischen den Versionen

Aus Tutorials
Zur Navigation springen Zur Suche springen
(Die Seite wurde neu angelegt: „ Zurück zu Spring“)
 
Zeile 1: Zeile 1:
{{note|Noch in Bearbeitung}}




== CORS (Cross Over Resource Sharing) ==
<pre>
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
  ...
  @Override
  protected void configure(final HttpSecurity http) throws Exception {   
    http.cors() /* CORS filter must be enabled */
      .and()
      ...
  }
  ...
  @Bean
  CorsConfigurationSource corsConfigurationSource() {
    CorsConfiguration configuration = new CorsConfiguration();
    configuration.setAllowCredentials(true);
    configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type"));
    configuration.setAllowedOrigins(Arrays.asList("http://localhost:4200"));
    configuration.setAllowedMethods(Arrays.asList("GET","POST"));
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", configuration);
    return source;
  }
  ...
}
</pre>




Zurück zu [[Spring#Spring Security|Spring]]
Zurück zu [[Spring#Spring Security|Spring]]

Version vom 23. Oktober 2018, 10:46 Uhr

Noch in Bearbeitung


CORS (Cross Over Resource Sharing)

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
  ...
  @Override
  protected void configure(final HttpSecurity http) throws Exception {    
    http.cors() /* CORS filter must be enabled */
      .and()
      ...
  }

  ...

  @Bean
  CorsConfigurationSource corsConfigurationSource() {
    CorsConfiguration configuration = new CorsConfiguration();
    configuration.setAllowCredentials(true);
    configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type"));
    configuration.setAllowedOrigins(Arrays.asList("http://localhost:4200"));
    configuration.setAllowedMethods(Arrays.asList("GET","POST"));
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", configuration);
    return source;
  }
  ...
}


Zurück zu Spring