Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Commit 9b6f85a

Browse files
authored
Merge pull request #1248 from stormpath/1241_cors_fix_for_angular
1241 - Fixing CORS issue for Angular
2 parents eacf2e0 + f387b83 commit 9b6f85a

File tree

7 files changed

+27
-6
lines changed

7 files changed

+27
-6
lines changed

extensions/servlet/src/main/resources/com/stormpath/sdk/servlet/config/web.stormpath.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,5 +354,6 @@ stormpath.web.assets.css.enabled = true
354354
stormpath.web.cors.enabled = true
355355
#Comma separated list of allowed origins
356356
stormpath.web.cors.allowed.originUris =
357-
stormpath.web.cors.allowed.headers = Content-Type,Accept,X-Requested-With,remember-me
357+
stormpath.web.cors.allowed.headers = Content-Type,Accept,X-Requested-With,remember-me,authorization,x-stormpath-agent
358358
stormpath.web.cors.allowed.methods = POST,GET,OPTIONS,DELETE,PUT
359+
stormpath.web.cors.allow.credentials = true

extensions/servlet/src/test/groovy/com/stormpath/sdk/servlet/config/SpecConfigVersusWebPropertiesTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class SpecConfigVersusWebPropertiesTest {
8585
specProperties.containsKey(k) ? null : k
8686
}
8787

88-
def expected_diff_size = 82
88+
def expected_diff_size = 83
8989

9090
if (diff.size != expected_diff_size) {
9191
println "It looks like a property was added or removed from the Framework Spec or web.stormpath.properties."

extensions/spring/boot/stormpath-spring-security-webmvc-spring-boot-starter/src/main/java/com/stormpath/spring/boot/autoconfigure/StormpathWebSecurityAutoConfiguration.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,13 @@ public AuthenticationEntryPoint stormpathAuthenticationEntryPoint() {
150150
/**
151151
* @since 1.3.0
152152
*/
153+
/*
154+
* We cannot add @ConditionalOnMissingBean here.
155+
* When using the spring boot starter parent, it has a CorsConfigurationSource that would prevent this bean from being used.
156+
* Fix for: https://github.com/stormpath/stormpath-sdk-java/issues/1241
157+
*/
153158
@Bean
154-
@ConditionalOnMissingBean
159+
@Override
155160
public CorsConfigurationSource corsConfigurationSource() {
156161
return super.corsConfigurationSource();
157162
}

extensions/spring/boot/stormpath-webmvc-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,13 +1018,19 @@
10181018
"name": "stormpath.web.cors.allowed.headers",
10191019
"type": "java.lang.String",
10201020
"description": "Comma separated list of allowed headers for a CORS request.",
1021-
"defaultValue": "Content-Type,Accept,X-Requested-With,remember-me"
1021+
"defaultValue": "Content-Type,Accept,X-Requested-With,remember-me,authorization,x-stormpath-agent"
10221022
},
10231023
{
10241024
"name": "stormpath.web.cors.allowed.methods",
10251025
"type": "java.lang.String",
10261026
"description": "Comma separated list of allowed methods for a CORS request.",
10271027
"defaultValue": "POST,GET,OPTIONS,DELETE,PUT"
1028+
},
1029+
{
1030+
"name": "stormpath.web.cors.allow.credentials",
1031+
"type": "java.lang.Boolean",
1032+
"description": "Whether user credentials are supported.",
1033+
"defaultValue": true
10281034
}
10291035
]
10301036
}

extensions/spring/stormpath-spring-security-webmvc/src/main/java/com/stormpath/spring/config/AbstractStormpathWebSecurityConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,15 @@ public abstract class AbstractStormpathWebSecurityConfiguration {
129129
@Value("#{ @environment['stormpath.web.cors.allowed.originUris'] }")
130130
protected String corsAllowedOrigins;
131131

132-
@Value("#{ @environment['stormpath.web.cors.allowed.headers'] ?: 'Content-Type,Accept,X-Requested-With,remember-me' }")
132+
@Value("#{ @environment['stormpath.web.cors.allowed.headers'] ?: 'Content-Type,Accept,X-Requested-With,remember-me,authorization,x-stormpath-agent' }")
133133
protected String corsAllowedHeaders;
134134

135135
@Value("#{ @environment['stormpath.web.cors.allowed.methods'] ?: 'POST,GET,OPTIONS,DELETE,PUT' }")
136136
protected String corsAllowedMethods;
137137

138+
@Value("#{ @environment['stormpath.web.cors.allow.credentials'] ?: true }")
139+
protected boolean corsAllowCredentials;
140+
138141
@Value("#{ @environment['stormpath.web.stormpathFilter.enabled'] ?: true }")
139142
protected boolean stormpathFilterEnabled;
140143

@@ -279,6 +282,7 @@ public CorsConfigurationSource corsConfigurationSource() {
279282
configuration.setAllowedOrigins(Strings.split(corsAllowedOrigins) != null ? Arrays.asList(Strings.split(corsAllowedOrigins)) : Collections.<String>emptyList());
280283
configuration.setAllowedHeaders(Strings.split(corsAllowedHeaders) != null ? Arrays.asList(Strings.split(corsAllowedHeaders)) : Collections.<String>emptyList());
281284
configuration.setAllowedMethods(Strings.split(corsAllowedMethods) != null ? Arrays.asList(Strings.split(corsAllowedMethods)) : Collections.<String>emptyList());
285+
configuration.setAllowCredentials(corsAllowCredentials); // fix for https://github.com/stormpath/stormpath-sdk-java/issues/1241
282286
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
283287
source.registerCorsConfiguration("/**", configuration);
284288
return source;

extensions/spring/stormpath-spring-security-webmvc/src/main/java/com/stormpath/spring/config/StormpathWebSecurityConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public AuthenticationEntryPoint stormpathAuthenticationEntryPoint() {
119119
* @since 1.3.0
120120
*/
121121
@Bean
122+
@Override
122123
public CorsConfigurationSource corsConfigurationSource() {
123124
return super.corsConfigurationSource();
124125
}

extensions/spring/stormpath-spring-webmvc/src/main/java/com/stormpath/spring/config/AbstractStormpathWebMvcConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,15 @@ public abstract class AbstractStormpathWebMvcConfiguration {
406406
@Value("#{ @environment['stormpath.web.cors.allowed.originUris'] }")
407407
protected String corsAllowedOrigins;
408408

409-
@Value("#{ @environment['stormpath.web.cors.allowed.headers'] ?: 'Content-Type,Accept,X-Requested-With,remember-me' }")
409+
@Value("#{ @environment['stormpath.web.cors.allowed.headers'] ?: 'Content-Type,Accept,X-Requested-With,remember-me,authorization,x-stormpath-agent' }")
410410
protected String corsAllowedHeaders;
411411

412412
@Value("#{ @environment['stormpath.web.cors.allowed.methods'] ?: 'POST,GET,OPTIONS,DELETE,PUT' }")
413413
protected String corsAllowedMethods;
414414

415+
@Value("#{ @environment['stormpath.web.cors.allow.credentials'] ?: true }")
416+
protected boolean corsAllowCredentials;
417+
415418
@Autowired(required = false)
416419
protected PathMatcher pathMatcher;
417420

@@ -1530,6 +1533,7 @@ public Filter newCorsFilter() {
15301533
config.setAllowedOrigins(stormpathCorsAllowedOrigins());
15311534
config.setAllowedHeaders(stormpathCorsAllowedHeaders());
15321535
config.setAllowedMethods(stormpathCorsAllowedMethods());
1536+
config.setAllowCredentials(corsAllowCredentials);
15331537
source.registerCorsConfiguration("/**", config);
15341538
return new CorsFilter(source);
15351539
}

0 commit comments

Comments
 (0)