4 changed files with 160 additions and 187 deletions
@ -1,128 +0,0 @@
@@ -1,128 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2017 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.config.web.server; |
||||
|
||||
import org.springframework.security.web.server.header.CacheControlHttpHeadersWriter; |
||||
import org.springframework.security.web.server.header.CompositeHttpHeadersWriter; |
||||
import org.springframework.security.web.server.header.ContentTypeOptionsHttpHeadersWriter; |
||||
import org.springframework.security.web.server.header.HttpHeaderWriterWebFilter; |
||||
import org.springframework.security.web.server.header.HttpHeadersWriter; |
||||
import org.springframework.security.web.server.header.StrictTransportSecurityHttpHeadersWriter; |
||||
import org.springframework.security.web.server.header.XFrameOptionsHttpHeadersWriter; |
||||
import org.springframework.security.web.server.header.XXssProtectionHttpHeadersWriter; |
||||
|
||||
import java.time.Duration; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Rob Winch |
||||
* @since 5.0 |
||||
*/ |
||||
public class HeaderBuilder { |
||||
private final List<HttpHeadersWriter> writers; |
||||
|
||||
private CacheControlHttpHeadersWriter cacheControl = new CacheControlHttpHeadersWriter(); |
||||
|
||||
private ContentTypeOptionsHttpHeadersWriter contentTypeOptions = new ContentTypeOptionsHttpHeadersWriter(); |
||||
|
||||
private StrictTransportSecurityHttpHeadersWriter hsts = new StrictTransportSecurityHttpHeadersWriter(); |
||||
|
||||
private XFrameOptionsHttpHeadersWriter frameOptions = new XFrameOptionsHttpHeadersWriter(); |
||||
|
||||
private XXssProtectionHttpHeadersWriter xss = new XXssProtectionHttpHeadersWriter(); |
||||
|
||||
public HeaderBuilder() { |
||||
this.writers = new ArrayList<>(Arrays.asList(cacheControl, contentTypeOptions, hsts, frameOptions, xss)); |
||||
} |
||||
|
||||
public CacheSpec cache() { |
||||
return new CacheSpec(); |
||||
} |
||||
|
||||
public ContentTypeOptionsSpec contentTypeOptions() { |
||||
return new ContentTypeOptionsSpec(); |
||||
} |
||||
|
||||
public FrameOptionsSpec frameOptions() { |
||||
return new FrameOptionsSpec(); |
||||
} |
||||
|
||||
public HstsSpec hsts() { |
||||
return new HstsSpec(); |
||||
} |
||||
|
||||
public HttpHeaderWriterWebFilter build() { |
||||
HttpHeadersWriter writer = new CompositeHttpHeadersWriter(writers); |
||||
return new HttpHeaderWriterWebFilter(writer); |
||||
} |
||||
|
||||
public XssProtectionSpec xssProtection() { |
||||
return new XssProtectionSpec(); |
||||
} |
||||
|
||||
public class CacheSpec { |
||||
public void disable() { |
||||
writers.remove(cacheControl); |
||||
} |
||||
|
||||
private CacheSpec() {} |
||||
} |
||||
|
||||
public class ContentTypeOptionsSpec { |
||||
public void disable() { |
||||
writers.remove(contentTypeOptions); |
||||
} |
||||
|
||||
private ContentTypeOptionsSpec() {} |
||||
} |
||||
|
||||
public class FrameOptionsSpec { |
||||
public void mode(XFrameOptionsHttpHeadersWriter.Mode mode) { |
||||
frameOptions.setMode(mode); |
||||
} |
||||
public void disable() { |
||||
writers.remove(frameOptions); |
||||
} |
||||
|
||||
private FrameOptionsSpec() {} |
||||
} |
||||
|
||||
public class HstsSpec { |
||||
public void maxAge(Duration maxAge) { |
||||
hsts.setMaxAge(maxAge); |
||||
} |
||||
|
||||
public void includeSubdomains(boolean includeSubDomains) { |
||||
hsts.setIncludeSubDomains(includeSubDomains); |
||||
} |
||||
|
||||
public void disable() { |
||||
writers.remove(hsts); |
||||
} |
||||
|
||||
private HstsSpec() {} |
||||
} |
||||
|
||||
public class XssProtectionSpec { |
||||
public void disable() { |
||||
writers.remove(xss); |
||||
} |
||||
|
||||
private XssProtectionSpec() {} |
||||
} |
||||
} |
||||
@ -1,58 +0,0 @@
@@ -1,58 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2016 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.config.web.server; |
||||
|
||||
import org.springframework.security.authentication.ReactiveAuthenticationManager; |
||||
import org.springframework.security.web.server.AuthenticationEntryPoint; |
||||
import org.springframework.security.web.server.authentication.AuthenticationWebFilter; |
||||
import org.springframework.security.web.server.HttpBasicAuthenticationConverter; |
||||
import org.springframework.security.web.server.authentication.DefaultAuthenticationSuccessHandler; |
||||
import org.springframework.security.web.server.authentication.www.HttpBasicAuthenticationEntryPoint; |
||||
import org.springframework.security.web.server.context.SecurityContextRepository; |
||||
|
||||
/** |
||||
* @author Rob Winch |
||||
* @since 5.0 |
||||
*/ |
||||
public class HttpBasicBuilder { |
||||
private ReactiveAuthenticationManager authenticationManager; |
||||
|
||||
private SecurityContextRepository securityContextRepository; |
||||
|
||||
private AuthenticationEntryPoint entryPoint = new HttpBasicAuthenticationEntryPoint(); |
||||
|
||||
public HttpBasicBuilder authenticationManager(ReactiveAuthenticationManager authenticationManager) { |
||||
this.authenticationManager = authenticationManager; |
||||
return this; |
||||
} |
||||
|
||||
public HttpBasicBuilder securityContextRepository(SecurityContextRepository securityContextRepository) { |
||||
this.securityContextRepository = securityContextRepository; |
||||
return this; |
||||
} |
||||
|
||||
public AuthenticationWebFilter build() { |
||||
AuthenticationWebFilter authenticationFilter = new AuthenticationWebFilter(authenticationManager); |
||||
authenticationFilter.setEntryPoint(entryPoint); |
||||
authenticationFilter.setAuthenticationConverter(new HttpBasicAuthenticationConverter()); |
||||
if(securityContextRepository != null) { |
||||
DefaultAuthenticationSuccessHandler handler = new DefaultAuthenticationSuccessHandler(); |
||||
handler.setSecurityContextRepository(securityContextRepository); |
||||
authenticationFilter.setAuthenticationSuccessHandler(handler); |
||||
} |
||||
return authenticationFilter; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue