11package gov .cms .qpp .conversion .api .config ;
22
3+ import org .springframework .beans .factory .annotation .Value ;
4+ import org .springframework .context .annotation .Bean ;
35import org .springframework .context .annotation .Configuration ;
46import org .springframework .security .config .annotation .method .configuration .EnableMethodSecurity ;
7+ import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
58import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
9+ import org .springframework .security .config .http .SessionCreationPolicy ;
10+ import org .springframework .security .web .SecurityFilterChain ;
11+ import org .springframework .security .web .authentication .www .BasicAuthenticationFilter ;
12+ import org .springframework .web .bind .annotation .CrossOrigin ;
13+
14+ import gov .cms .qpp .conversion .api .security .JwtAuthorizationFilter ;
15+
16+ import java .util .Set ;
617
718/**
819 * Web Security Configuration
920 */
1021@ Configuration
1122@ EnableWebSecurity
23+ @ CrossOrigin (origins ="*" )
1224@ EnableMethodSecurity (securedEnabled = true , jsr250Enabled = true )
13- public class SecurityConfig { }
25+ public class SecurityConfig {
26+
27+ private static final String PCF_WILDCARD = "/pcf/**" ;
28+
29+ @ Value ("${ORG_NAME:" + JwtAuthorizationFilter .DEFAULT_ORG_NAME + "}" )
30+ protected String orgName ;
31+
32+ @ Value ("${RTI_ORG_NAME:" + JwtAuthorizationFilter .DEFAULT_RTI_ORG + "}" )
33+ protected String rtiOrgName ;
34+
35+ @ Bean
36+ public SecurityFilterChain filterChain (HttpSecurity http ) throws Exception {
37+ http .securityMatcher (PCF_WILDCARD )
38+ .authorizeRequests ()
39+ .anyRequest ().authenticated ()
40+ .and ()
41+ .csrf (csrf -> csrf .disable ())
42+ .addFilterAt (new JwtAuthorizationFilter (Set .of (orgName , rtiOrgName )), BasicAuthenticationFilter .class )
43+ .sessionManagement (sm -> sm .sessionCreationPolicy (SessionCreationPolicy .STATELESS ))
44+ .headers (headers -> headers
45+ .contentSecurityPolicy (csp -> csp
46+ .policyDirectives ("script-src 'self'" )
47+ )
48+ );
49+
50+ return http .build ();
51+ }
52+ }
0 commit comments