|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2002-2016 the original author or authors.
|
|
|
+ * Copyright 2002-2018 the original author or authors.
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -13,8 +13,23 @@
|
|
|
* See the License for the specific language governing permissions and
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
+
|
|
|
package org.springframework.security.config.web.server;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.io.StringWriter;
|
|
|
+import java.security.interfaces.RSAPublicKey;
|
|
|
+import java.time.Duration;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
+
|
|
|
import org.springframework.beans.BeansException;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.core.Ordered;
|
|
@@ -40,11 +55,11 @@ import org.springframework.security.oauth2.client.registration.ClientRegistratio
|
|
|
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
|
|
|
import org.springframework.security.oauth2.client.userinfo.DefaultReactiveOAuth2UserService;
|
|
|
import org.springframework.security.oauth2.client.userinfo.ReactiveOAuth2UserService;
|
|
|
-import org.springframework.security.oauth2.client.web.server.OAuth2AuthorizationRequestRedirectWebFilter;
|
|
|
import org.springframework.security.oauth2.client.web.server.AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository;
|
|
|
-import org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository;
|
|
|
-import org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizationCodeAuthenticationTokenConverter;
|
|
|
import org.springframework.security.oauth2.client.web.server.OAuth2AuthorizationCodeGrantWebFilter;
|
|
|
+import org.springframework.security.oauth2.client.web.server.OAuth2AuthorizationRequestRedirectWebFilter;
|
|
|
+import org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizationCodeAuthenticationTokenConverter;
|
|
|
+import org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository;
|
|
|
import org.springframework.security.oauth2.client.web.server.authentication.OAuth2LoginAuthenticationWebFilter;
|
|
|
import org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder;
|
|
|
import org.springframework.security.oauth2.jwt.ReactiveJwtDecoder;
|
|
@@ -84,6 +99,7 @@ import org.springframework.security.web.server.csrf.ServerCsrfTokenRepository;
|
|
|
import org.springframework.security.web.server.header.CacheControlServerHttpHeadersWriter;
|
|
|
import org.springframework.security.web.server.header.CompositeServerHttpHeadersWriter;
|
|
|
import org.springframework.security.web.server.header.ContentTypeOptionsServerHttpHeadersWriter;
|
|
|
+import org.springframework.security.web.server.header.FeaturePolicyServerHttpHeadersWriter;
|
|
|
import org.springframework.security.web.server.header.HttpHeaderWriterWebFilter;
|
|
|
import org.springframework.security.web.server.header.ServerHttpHeadersWriter;
|
|
|
import org.springframework.security.web.server.header.StrictTransportSecurityServerHttpHeadersWriter;
|
|
@@ -109,23 +125,9 @@ import org.springframework.web.cors.reactive.DefaultCorsProcessor;
|
|
|
import org.springframework.web.server.ServerWebExchange;
|
|
|
import org.springframework.web.server.WebFilter;
|
|
|
import org.springframework.web.server.WebFilterChain;
|
|
|
-import reactor.core.publisher.Mono;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.PrintWriter;
|
|
|
-import java.io.StringWriter;
|
|
|
-import java.security.interfaces.RSAPublicKey;
|
|
|
-import java.time.Duration;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
import static org.springframework.security.web.server.DelegatingServerAuthenticationEntryPoint.DelegateEntry;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* A {@link ServerHttpSecurity} is similar to Spring Security's {@code HttpSecurity} but for WebFlux.
|
|
|
* It allows configuring web based security for specific http requests. By default it will be applied
|
|
@@ -178,6 +180,7 @@ import static org.springframework.security.web.server.DelegatingServerAuthentica
|
|
|
* }
|
|
|
*
|
|
|
* @author Rob Winch
|
|
|
+ * @author Vedran Pavic
|
|
|
* @since 5.0
|
|
|
*/
|
|
|
public class ServerHttpSecurity {
|
|
@@ -1659,6 +1662,8 @@ public class ServerHttpSecurity {
|
|
|
|
|
|
private XXssProtectionServerHttpHeadersWriter xss = new XXssProtectionServerHttpHeadersWriter();
|
|
|
|
|
|
+ private FeaturePolicyServerHttpHeadersWriter featurePolicy = new FeaturePolicyServerHttpHeadersWriter();
|
|
|
+
|
|
|
/**
|
|
|
* Allows method chaining to continue configuring the {@link ServerHttpSecurity}
|
|
|
* @return the {@link ServerHttpSecurity} to continue configuring
|
|
@@ -1722,6 +1727,15 @@ public class ServerHttpSecurity {
|
|
|
return new XssProtectionSpec();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Configures {@code Feature-Policy} response header.
|
|
|
+ * @param policyDirectives the policy directive(s)
|
|
|
+ * @return the {@link FeaturePolicySpec} to configure
|
|
|
+ */
|
|
|
+ public FeaturePolicySpec featurePolicy(String policyDirectives) {
|
|
|
+ return new FeaturePolicySpec(policyDirectives);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Configures cache control headers
|
|
|
* @see #cache()
|
|
@@ -1854,11 +1868,35 @@ public class ServerHttpSecurity {
|
|
|
private XssProtectionSpec() {}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Configures {@code Feature-Policy} response header.
|
|
|
+ *
|
|
|
+ * @see #featurePolicy(String)
|
|
|
+ * @since 5.1
|
|
|
+ */
|
|
|
+ public class FeaturePolicySpec {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Allows method chaining to continue configuring the
|
|
|
+ * {@link ServerHttpSecurity}.
|
|
|
+ * @return the {@link HeaderSpec} to continue configuring
|
|
|
+ */
|
|
|
+ public HeaderSpec and() {
|
|
|
+ return HeaderSpec.this;
|
|
|
+ }
|
|
|
+
|
|
|
+ private FeaturePolicySpec(String policyDirectives) {
|
|
|
+ HeaderSpec.this.featurePolicy.setPolicyDirectives(policyDirectives);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private HeaderSpec() {
|
|
|
this.writers = new ArrayList<>(
|
|
|
- Arrays.asList(this.cacheControl, this.contentTypeOptions, this.hsts,
|
|
|
- this.frameOptions, this.xss));
|
|
|
+ Arrays.asList(this.cacheControl, this.contentTypeOptions, this.hsts,
|
|
|
+ this.frameOptions, this.xss, this.featurePolicy));
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|