Skip to content
This repository was archived by the owner on Aug 10, 2021. It is now read-only.

Commit 54ea417

Browse files
committed
Merge branch '1.1.x'
2 parents 70dc0d5 + e5ce4f0 commit 54ea417

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>ee.ria.tara</groupId>
77
<artifactId>tara-server</artifactId>
88
<packaging>war</packaging>
9-
<version>1.1.3</version>
9+
<version>1.1.4</version>
1010

1111
<properties>
1212
<cas.version>5.1.9</cas.version>

src/main/java/ee/ria/sso/service/AbstractService.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.extern.slf4j.Slf4j;
66
import org.apache.commons.lang3.StringUtils;
77
import org.apereo.cas.authentication.principal.WebApplicationService;
8+
import org.apereo.cas.util.EncodingUtils;
89
import org.springframework.web.util.UriComponents;
910
import org.springframework.web.util.UriComponentsBuilder;
1011
import org.springframework.webflow.core.collection.SharedAttributeMap;
@@ -54,11 +55,13 @@ private String getServiceUrlFromFlowContext(RequestContext context) {
5455
private String getClientIdParameterValue(String serviceParameter) {
5556
try {
5657
UriComponents serviceUri = UriComponentsBuilder.fromUriString(serviceParameter).build();
57-
return serviceUri.getQueryParams().get("client_id").get(0);
58+
String clientId = serviceUri.getQueryParams().getFirst("client_id");
59+
if (clientId == null)
60+
throw new IllegalStateException("No client_id found among query parameters!");
61+
return clientId;
5862
} catch (Exception e) {
59-
log.error("Failed to get client_id from service parameter!", e);
60-
61-
return null;
63+
log.warn("Failed to get client_id from service parameter: " + e.getMessage());
64+
return EncodingUtils.urlEncode(serviceParameter);
6265
}
6366
}
6467

src/test/java/ee/ria/sso/service/AbstractServiceTest.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.springframework.webflow.test.MockParameterMap;
1313
import org.springframework.webflow.test.MockRequestContext;
1414

15+
import java.io.UnsupportedEncodingException;
16+
import java.net.URLEncoder;
1517
import java.util.HashMap;
1618
import java.util.Map;
1719

@@ -28,12 +30,22 @@ public void setUp() {
2830
}
2931

3032
@Test
31-
public void getServiceClientIdShouldReturnNullWhenMalformedServiceUrl() {
33+
public void getServiceClientIdShouldReturnServiceUrlWhenMalformedServiceUrl() {
3234
RequestContext requestContext = getMockRequestContext(new HashMap<>());
3335
((MockHttpServletRequest) requestContext.getExternalContext().getNativeRequest()).addParameter("service", "invalidUrl");
3436

3537
String clientId = abstractService.getServiceClientId(requestContext);
36-
Assert.assertEquals(null, clientId);
38+
Assert.assertEquals("invalidUrl", clientId);
39+
}
40+
41+
@Test
42+
public void getServiceClientIdShouldReturnServiceUrlWhenMalformedServiceUrl2() throws UnsupportedEncodingException {
43+
String serviceParameter = createStringFromRangeOfValues('\0', '\u007F');
44+
RequestContext requestContext = getMockRequestContext(new HashMap<>());
45+
((MockHttpServletRequest) requestContext.getExternalContext().getNativeRequest()).addParameter("service", serviceParameter);
46+
47+
String clientId = abstractService.getServiceClientId(requestContext);
48+
Assert.assertEquals(URLEncoder.encode(serviceParameter, "UTF-8"), clientId);
3749
}
3850

3951
@Test
@@ -77,4 +89,15 @@ private RequestContext getMockRequestContext(Map<String, String> parameters) {
7789
return context;
7890
}
7991

92+
private String createStringFromRangeOfValues(char min, char max) {
93+
final int length = (max - min) + 1;
94+
char[] values = new char[length];
95+
96+
for (int i = 0; i < length; ++i) {
97+
values[i] = (char) (min + i);
98+
}
99+
100+
return new String(values);
101+
}
102+
80103
}

0 commit comments

Comments
 (0)