File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
src/main/java/com/pj/keycloak/security Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 16
16
import org .springframework .security .core .session .SessionRegistryImpl ;
17
17
import org .springframework .security .web .authentication .session .RegisterSessionAuthenticationStrategy ;
18
18
import org .springframework .security .web .authentication .session .SessionAuthenticationStrategy ;
19
+ import org .springframework .web .cors .CorsConfiguration ;
20
+ import org .springframework .web .cors .CorsConfigurationSource ;
21
+ import org .springframework .web .cors .UrlBasedCorsConfigurationSource ;
22
+
23
+ import java .util .Collections ;
19
24
20
25
@ Configuration
21
26
@ EnableWebSecurity
@@ -54,5 +59,30 @@ protected void configure(HttpSecurity http) throws Exception
54
59
.hasAnyRole (Roles .ADMIN )
55
60
.anyRequest ()
56
61
.permitAll ();
62
+
63
+ http .cors ();
57
64
}
65
+ //Cors filter to accept incoming requests
66
+ @ Bean
67
+ CorsConfigurationSource corsConfigurationSource ()
68
+ {
69
+ CorsConfiguration configuration = new CorsConfiguration ();
70
+ configuration .applyPermitDefaultValues ();
71
+ configuration .setAllowedMethods (Collections .singletonList ("*" ));
72
+ configuration .setAllowCredentials (true );
73
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource ();
74
+ source .registerCorsConfiguration ("/**" , configuration );
75
+ return source ;
76
+ }
77
+
78
+ /* public WebMvcConfigurer corsConfigurer()
79
+ {
80
+ return new WebMvcConfigurer() {
81
+ @Override
82
+ public void addCorsMappings(CorsRegistry registry)
83
+ {
84
+ registry.addMapping("/api/*").allowedOrigins("http://localhost:4200");
85
+ }
86
+ };
87
+ }*/
58
88
}
You can’t perform that action at this time.
0 commit comments