Remove CookieServerCsrfTokenRepository builder methods

This is inconsistent with the rest of the code base.

Issue: gh-5083
This commit is contained in:
Rob Winch 2018-05-04 15:59:27 -05:00
parent 1eaecc12ec
commit 37b1136c0c
1 changed files with 6 additions and 66 deletions

View File

@ -25,6 +25,7 @@ import org.springframework.http.server.PathContainer;
import org.springframework.http.server.RequestPath; import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -57,7 +58,9 @@ public final class CookieServerCsrfTokenRepository implements ServerCsrfTokenRep
* {@link #setCookieHttpOnly(boolean)} set to false * {@link #setCookieHttpOnly(boolean)} set to false
*/ */
public static CookieServerCsrfTokenRepository withHttpOnlyFalse() { public static CookieServerCsrfTokenRepository withHttpOnlyFalse() {
return new CookieServerCsrfTokenRepository().withCookieHttpOnly(false); CookieServerCsrfTokenRepository result = new CookieServerCsrfTokenRepository();
result.setCookieHttpOnly(false);
return result;
} }
@Override @Override
@ -101,16 +104,6 @@ public final class CookieServerCsrfTokenRepository implements ServerCsrfTokenRep
this.cookieHttpOnly = cookieHttpOnly; this.cookieHttpOnly = cookieHttpOnly;
} }
/**
* Sets the HttpOnly attribute on the cookie containing the CSRF token
* @param cookieHttpOnly True to mark the cookie as http only. False otherwise.
* @return This instance
*/
public CookieServerCsrfTokenRepository withCookieHttpOnly(boolean cookieHttpOnly) {
setCookieHttpOnly(cookieHttpOnly);
return this;
}
/** /**
* Sets the cookie name * Sets the cookie name
* @param cookieName The cookie name * @param cookieName The cookie name
@ -120,16 +113,6 @@ public final class CookieServerCsrfTokenRepository implements ServerCsrfTokenRep
this.cookieName = cookieName; this.cookieName = cookieName;
} }
/**
* Sets the cookie name
* @param cookieName The cookie name
* @return This instance
*/
public CookieServerCsrfTokenRepository withCookieName(String cookieName) {
setCookieName(cookieName);
return this;
}
/** /**
* Sets the parameter name * Sets the parameter name
* @param parameterName The parameter name * @param parameterName The parameter name
@ -139,16 +122,6 @@ public final class CookieServerCsrfTokenRepository implements ServerCsrfTokenRep
this.parameterName = parameterName; this.parameterName = parameterName;
} }
/**
* Sets the parameter name
* @param parameterName The parameter name
* @return This instance
*/
public CookieServerCsrfTokenRepository withParameterName(String parameterName) {
setParameterName(parameterName);
return this;
}
/** /**
* Sets the header name * Sets the header name
* @param headerName The header name * @param headerName The header name
@ -159,16 +132,6 @@ public final class CookieServerCsrfTokenRepository implements ServerCsrfTokenRep
this.headerName = headerName; this.headerName = headerName;
} }
/**
* Sets the header name
* @param headerName The header name
* @return This instance
*/
public CookieServerCsrfTokenRepository withHeaderName(String headerName) {
setHeaderName(headerName);
return this;
}
/** /**
* Sets the cookie path * Sets the cookie path
* @param cookiePath The cookie path * @param cookiePath The cookie path
@ -178,16 +141,6 @@ public final class CookieServerCsrfTokenRepository implements ServerCsrfTokenRep
this.cookiePath = cookiePath; this.cookiePath = cookiePath;
} }
/**
* Sets the cookie path
* @param cookiePath The cookie path
* @return This instance
*/
public CookieServerCsrfTokenRepository withCookiePath(String cookiePath) {
setCookiePath(cookiePath);
return this;
}
/** /**
* Sets the cookie domain * Sets the cookie domain
* @param cookieDomain The cookie domain * @param cookieDomain The cookie domain
@ -197,15 +150,6 @@ public final class CookieServerCsrfTokenRepository implements ServerCsrfTokenRep
this.cookieDomain = cookieDomain; this.cookieDomain = cookieDomain;
} }
/**
* Sets the cookie domain
* @param cookieDomain The cookie domain
* @return This instance
*/
public CookieServerCsrfTokenRepository withCookieDomain(String cookieDomain) {
setCookieDomain(cookieDomain);
return this;
}
private CsrfToken createCsrfToken() { private CsrfToken createCsrfToken() {
return createCsrfToken(createNewToken()); return createCsrfToken(createNewToken());
@ -220,11 +164,7 @@ public final class CookieServerCsrfTokenRepository implements ServerCsrfTokenRep
} }
private String getRequestContext(ServerHttpRequest request) { private String getRequestContext(ServerHttpRequest request) {
return Optional.ofNullable(request) String contextPath = request.getPath().contextPath().value();
.map(ServerHttpRequest::getPath) return StringUtils.hasLength(contextPath) ? contextPath : "/";
.map(RequestPath::contextPath)
.map(PathContainer::value)
.filter(contextPath -> contextPath.length() > 0)
.orElse("/");
} }
} }