improved utility to allow for arbitrary parameters to be passed at login
This commit is contained in:
Scott Battaglia 2009-07-29 12:26:17 +00:00
parent bddd8f0622
commit 9b1ba497e3
2 changed files with 17 additions and 1 deletions

View File

@ -138,7 +138,7 @@ public final class CommonUtils {
*/
public static final String constructRedirectUrl(final String casServerLoginUrl, final String serviceParameterName, final String serviceUrl, final boolean renew, final boolean gateway) {
try {
return casServerLoginUrl + "?" + serviceParameterName + "="
return casServerLoginUrl + (casServerLoginUrl.indexOf("?") != -1 ? "&" : "?") + serviceParameterName + "="
+ URLEncoder.encode(serviceUrl, "UTF-8")
+ (renew ? "&renew=true" : "")
+ (gateway ? "&gateway=true" : "");

View File

@ -19,6 +19,22 @@ import java.util.Collection;
*/
public final class CommonUtilsTests extends TestCase {
public void testRedirectUrlWithParam() {
final String loginUrl = "http://localhost:8080/login?myName=foo";
final String fullyConstructedUrl = CommonUtils.constructRedirectUrl(loginUrl, "foo", "foo", false, false);
int count = 0;
final char[] chars = fullyConstructedUrl.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (chars[i] == '?') {
count ++;
}
}
assertEquals(1, count);
}
public void testAssertNotNull() {
final String CONST_MESSAGE = "test";
CommonUtils.assertNotNull(new Object(), CONST_MESSAGE);