Polish HttpSecurity

Code Style fixes
This commit is contained in:
Rob Winch 2017-08-29 20:34:20 -05:00
parent 51ad53f76a
commit 9f2ea90f0d

View File

@ -97,21 +97,21 @@ public class HttpSecurity {
} }
public HttpBasicBuilder httpBasic() { public HttpBasicBuilder httpBasic() {
if(httpBasic == null) { if(this.httpBasic == null) {
httpBasic = new HttpBasicBuilder(); this.httpBasic = new HttpBasicBuilder();
} }
return httpBasic; return this.httpBasic;
} }
public HeaderBuilder headers() { public HeaderBuilder headers() {
return headers; return this.headers;
} }
public AuthorizeExchangeBuilder authorizeExchange() { public AuthorizeExchangeBuilder authorizeExchange() {
if(authorizeExchangeBuilder == null) { if(this.authorizeExchangeBuilder == null) {
authorizeExchangeBuilder = new AuthorizeExchangeBuilder(); this.authorizeExchangeBuilder = new AuthorizeExchangeBuilder();
} }
return authorizeExchangeBuilder; return this.authorizeExchangeBuilder;
} }
public HttpSecurity authenticationManager(ReactiveAuthenticationManager manager) { public HttpSecurity authenticationManager(ReactiveAuthenticationManager manager) {
@ -121,24 +121,24 @@ public class HttpSecurity {
public SecurityWebFilterChain build() { public SecurityWebFilterChain build() {
List<WebFilter> filters = new ArrayList<>(); List<WebFilter> filters = new ArrayList<>();
if(headers != null) { if(this.headers != null) {
filters.add(headers.build()); filters.add(this.headers.build());
} }
SecurityContextRepositoryWebFilter securityContextRepositoryWebFilter = securityContextRepositoryWebFilter(); SecurityContextRepositoryWebFilter securityContextRepositoryWebFilter = securityContextRepositoryWebFilter();
if(securityContextRepositoryWebFilter != null) { if(securityContextRepositoryWebFilter != null) {
filters.add(securityContextRepositoryWebFilter); filters.add(securityContextRepositoryWebFilter);
} }
if(httpBasic != null) { if(this.httpBasic != null) {
httpBasic.authenticationManager(authenticationManager); this.httpBasic.authenticationManager(this.authenticationManager);
if(securityContextRepository != null) { if(this.securityContextRepository != null) {
httpBasic.securityContextRepository(securityContextRepository); this.httpBasic.securityContextRepository(this.securityContextRepository);
} }
filters.add(httpBasic.build()); filters.add(this.httpBasic.build());
} }
filters.add(new AuthenticationReactorContextFilter()); filters.add(new AuthenticationReactorContextFilter());
if(authorizeExchangeBuilder != null) { if(this.authorizeExchangeBuilder != null) {
filters.add(new ExceptionTranslationWebFilter()); filters.add(new ExceptionTranslationWebFilter());
filters.add(authorizeExchangeBuilder.build()); filters.add(this.authorizeExchangeBuilder.build());
} }
return new MatcherSecurityWebFilterChain(getSecurityMatcher(), filters); return new MatcherSecurityWebFilterChain(getSecurityMatcher(), filters);
} }
@ -152,13 +152,6 @@ public class HttpSecurity {
new SecurityContextRepositoryWebFilter(this.securityContextRepository); new SecurityContextRepositoryWebFilter(this.securityContextRepository);
} }
public class HttpBasicSpec extends HttpBasicBuilder {
public HttpSecurity disable() {
httpBasic = null;
return HttpSecurity.this;
}
}
private HttpSecurity() {} private HttpSecurity() {}
/** /**
@ -177,13 +170,13 @@ public class HttpSecurity {
@Override @Override
public Access anyExchange() { public Access anyExchange() {
Access result = super.anyExchange(); Access result = super.anyExchange();
anyExchangeRegistered = true; this.anyExchangeRegistered = true;
return result; return result;
} }
@Override @Override
protected Access registerMatcher(ServerWebExchangeMatcher matcher) { protected Access registerMatcher(ServerWebExchangeMatcher matcher) {
if(anyExchangeRegistered) { if(this.anyExchangeRegistered) {
throw new IllegalStateException("Cannot register " + matcher + " which would be unreachable because anyExchange() has already been registered."); throw new IllegalStateException("Cannot register " + matcher + " which would be unreachable because anyExchange() has already been registered.");
} }
if(this.matcher != null) { if(this.matcher != null) {
@ -195,9 +188,9 @@ public class HttpSecurity {
protected WebFilter build() { protected WebFilter build() {
if(this.matcher != null) { if(this.matcher != null) {
throw new IllegalStateException("The matcher " + matcher + " does not have an access rule defined"); throw new IllegalStateException("The matcher " + this.matcher + " does not have an access rule defined");
} }
return new AuthorizationWebFilter(managerBldr.build()); return new AuthorizationWebFilter(this.managerBldr.build());
} }
public final class Access { public final class Access {
@ -223,8 +216,10 @@ public class HttpSecurity {
} }
public AuthorizeExchangeBuilder access(ReactiveAuthorizationManager<AuthorizationContext> manager) { public AuthorizeExchangeBuilder access(ReactiveAuthorizationManager<AuthorizationContext> manager) {
managerBldr.add(new ServerWebExchangeMatcherEntry<>(matcher, manager)); AuthorizeExchangeBuilder.this.managerBldr
matcher = null; .add(new ServerWebExchangeMatcherEntry<>(
AuthorizeExchangeBuilder.this.matcher, manager));
AuthorizeExchangeBuilder.this.matcher = null;
return AuthorizeExchangeBuilder.this; return AuthorizeExchangeBuilder.this;
} }
} }
@ -255,13 +250,19 @@ public class HttpSecurity {
return HttpSecurity.this; return HttpSecurity.this;
} }
public HttpSecurity disable() {
HttpSecurity.this.httpBasic = null;
return HttpSecurity.this;
}
protected AuthenticationWebFilter build() { protected AuthenticationWebFilter build() {
AuthenticationWebFilter authenticationFilter = new AuthenticationWebFilter(authenticationManager); AuthenticationWebFilter authenticationFilter = new AuthenticationWebFilter(
authenticationFilter.setEntryPoint(entryPoint); this.authenticationManager);
authenticationFilter.setEntryPoint(this.entryPoint);
authenticationFilter.setAuthenticationConverter(new HttpBasicAuthenticationConverter()); authenticationFilter.setAuthenticationConverter(new HttpBasicAuthenticationConverter());
if(securityContextRepository != null) { if(this.securityContextRepository != null) {
DefaultAuthenticationSuccessHandler handler = new DefaultAuthenticationSuccessHandler(); DefaultAuthenticationSuccessHandler handler = new DefaultAuthenticationSuccessHandler();
handler.setSecurityContextRepository(securityContextRepository); handler.setSecurityContextRepository(this.securityContextRepository);
authenticationFilter.setAuthenticationSuccessHandler(handler); authenticationFilter.setAuthenticationSuccessHandler(handler);
} }
return authenticationFilter; return authenticationFilter;
@ -308,7 +309,7 @@ public class HttpSecurity {
} }
public HttpHeaderWriterWebFilter build() { public HttpHeaderWriterWebFilter build() {
HttpHeadersWriter writer = new CompositeHttpHeadersWriter(writers); HttpHeadersWriter writer = new CompositeHttpHeadersWriter(this.writers);
return new HttpHeaderWriterWebFilter(writer); return new HttpHeaderWriterWebFilter(writer);
} }
@ -318,7 +319,7 @@ public class HttpSecurity {
public class CacheSpec { public class CacheSpec {
public void disable() { public void disable() {
writers.remove(cacheControl); HeaderBuilder.this.writers.remove(HeaderBuilder.this.cacheControl);
} }
private CacheSpec() {} private CacheSpec() {}
@ -326,7 +327,7 @@ public class HttpSecurity {
public class ContentTypeOptionsSpec { public class ContentTypeOptionsSpec {
public void disable() { public void disable() {
writers.remove(contentTypeOptions); HeaderBuilder.this.writers.remove(HeaderBuilder.this.contentTypeOptions);
} }
private ContentTypeOptionsSpec() {} private ContentTypeOptionsSpec() {}
@ -334,10 +335,10 @@ public class HttpSecurity {
public class FrameOptionsSpec { public class FrameOptionsSpec {
public void mode(XFrameOptionsHttpHeadersWriter.Mode mode) { public void mode(XFrameOptionsHttpHeadersWriter.Mode mode) {
frameOptions.setMode(mode); HeaderBuilder.this.frameOptions.setMode(mode);
} }
public void disable() { public void disable() {
writers.remove(frameOptions); HeaderBuilder.this.writers.remove(HeaderBuilder.this.frameOptions);
} }
private FrameOptionsSpec() {} private FrameOptionsSpec() {}
@ -345,15 +346,15 @@ public class HttpSecurity {
public class HstsSpec { public class HstsSpec {
public void maxAge(Duration maxAge) { public void maxAge(Duration maxAge) {
hsts.setMaxAge(maxAge); HeaderBuilder.this.hsts.setMaxAge(maxAge);
} }
public void includeSubdomains(boolean includeSubDomains) { public void includeSubdomains(boolean includeSubDomains) {
hsts.setIncludeSubDomains(includeSubDomains); HeaderBuilder.this.hsts.setIncludeSubDomains(includeSubDomains);
} }
public void disable() { public void disable() {
writers.remove(hsts); HeaderBuilder.this.writers.remove(HeaderBuilder.this.hsts);
} }
private HstsSpec() {} private HstsSpec() {}
@ -361,7 +362,7 @@ public class HttpSecurity {
public class XssProtectionSpec { public class XssProtectionSpec {
public void disable() { public void disable() {
writers.remove(xss); HeaderBuilder.this.writers.remove(HeaderBuilder.this.xss);
} }
private XssProtectionSpec() {} private XssProtectionSpec() {}
@ -369,7 +370,8 @@ public class HttpSecurity {
private HeaderBuilder() { private HeaderBuilder() {
this.writers = new ArrayList<>( this.writers = new ArrayList<>(
Arrays.asList(cacheControl, contentTypeOptions, hsts, frameOptions, xss)); Arrays.asList(this.cacheControl, this.contentTypeOptions, this.hsts,
this.frameOptions, this.xss));
} }
} }
} }