SEC-2187: Polish
Create private utf8UrlEncode method to improve readability
This commit is contained in:
parent
54c1c20c69
commit
e88800cd9b
|
@ -188,37 +188,31 @@ public class OpenIDAuthenticationFilter extends AbstractAuthenticationProcessing
|
||||||
* @return The <tt>return_to</tt> URL.
|
* @return The <tt>return_to</tt> URL.
|
||||||
*/
|
*/
|
||||||
protected String buildReturnToUrl(HttpServletRequest request) {
|
protected String buildReturnToUrl(HttpServletRequest request) {
|
||||||
try {
|
StringBuffer sb = request.getRequestURL();
|
||||||
StringBuffer sb = request.getRequestURL();
|
|
||||||
|
Iterator<String> iterator = returnToUrlParameters.iterator();
|
||||||
Iterator<String> iterator = returnToUrlParameters.iterator();
|
boolean isFirst = true;
|
||||||
boolean isFirst = true;
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
while (iterator.hasNext()) {
|
String name = iterator.next();
|
||||||
String name = iterator.next();
|
// Assume for simplicity that there is only one value
|
||||||
// Assume for simplicity that there is only one value
|
String value = request.getParameter(name);
|
||||||
String value = request.getParameter(name);
|
|
||||||
|
if (value == null) {
|
||||||
if (value == null) {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
if (isFirst) {
|
||||||
if (isFirst) {
|
sb.append("?");
|
||||||
sb.append("?");
|
isFirst = false;
|
||||||
isFirst = false;
|
}
|
||||||
}
|
sb.append(utf8UrlEncode(name)).append("=").append(utf8UrlEncode(value));
|
||||||
sb.append(URLEncoder.encode(name, "UTF-8")).append("=").append(URLEncoder.encode(value, "UTF-8"));
|
|
||||||
|
if (iterator.hasNext()) {
|
||||||
if (iterator.hasNext()) {
|
sb.append("&");
|
||||||
sb.append("&");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return sb.toString();
|
|
||||||
} catch(UnsupportedEncodingException e) {
|
|
||||||
Error err = new AssertionError("The Java platform guarantees UTF-8 support, but it seemingly is not present.");
|
|
||||||
err.initCause(e);
|
|
||||||
throw err;
|
|
||||||
}
|
}
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -276,4 +270,20 @@ public class OpenIDAuthenticationFilter extends AbstractAuthenticationProcessing
|
||||||
Assert.notNull(returnToUrlParameters, "returnToUrlParameters cannot be null");
|
Assert.notNull(returnToUrlParameters, "returnToUrlParameters cannot be null");
|
||||||
this.returnToUrlParameters = returnToUrlParameters;
|
this.returnToUrlParameters = returnToUrlParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs URL encoding with UTF-8
|
||||||
|
*
|
||||||
|
* @param value the value to URL encode
|
||||||
|
* @return the encoded value
|
||||||
|
*/
|
||||||
|
private String utf8UrlEncode(String value) {
|
||||||
|
try {
|
||||||
|
return URLEncoder.encode(value, "UTF-8");
|
||||||
|
} catch(UnsupportedEncodingException e) {
|
||||||
|
Error err = new AssertionError("The Java platform guarantees UTF-8 support, but it seemingly is not present.");
|
||||||
|
err.initCause(e);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue