Skip to content

Commit 8718cc3

Browse files
committed
NOJIRA tag for 3.1.8
1 parent e787067 commit 8718cc3

18 files changed

Lines changed: 354 additions & 231 deletions

cas-client-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33
<parent>
44
<groupId>org.jasig.cas</groupId>
5-
<version>3.1.5</version>
5+
<version>3.1.8</version>
66
<artifactId>cas-client</artifactId>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>

cas-client-core/src/main/java/org/jasig/cas/client/authentication/AuthenticationFilter.java

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,38 +87,43 @@ public final void doFilter(final ServletRequest servletRequest, final ServletRes
8787
final HttpServletRequest request = (HttpServletRequest) servletRequest;
8888
final HttpServletResponse response = (HttpServletResponse) servletResponse;
8989
final HttpSession session = request.getSession(false);
90-
final String ticket = request.getParameter(getArtifactParameterName());
9190
final String serviceUrl = constructServiceUrl(request, response);
92-
final Assertion assertion = session != null ? (Assertion) session
93-
.getAttribute(CONST_CAS_ASSERTION) : null;
94-
final boolean wasGatewayed = this.gatewayStorage.hasGatewayedAlready(request, serviceUrl);
91+
final Assertion assertion = session != null ? (Assertion) session.getAttribute(CONST_CAS_ASSERTION) : null;
9592

96-
if (CommonUtils.isBlank(ticket) && assertion == null && !wasGatewayed) {
97-
final String modifiedServiceUrl;
98-
99-
log.debug("no ticket and no assertion found");
100-
if (this.gateway) {
101-
log.debug("setting gateway attribute in session");
102-
modifiedServiceUrl = this.gatewayStorage.storeGatewayInformation(request, serviceUrl);
103-
} else {
104-
modifiedServiceUrl = serviceUrl;
105-
}
106-
107-
if (log.isDebugEnabled()) {
108-
log.debug("Constructed service url: " + modifiedServiceUrl);
109-
}
110-
111-
final String urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casServerLoginUrl, getServiceParameterName(), modifiedServiceUrl, this.renew, this.gateway);
93+
if (assertion != null) {
94+
filterChain.doFilter(request, response);
95+
return;
96+
}
11297

113-
if (log.isDebugEnabled()) {
114-
log.debug("redirecting to \"" + urlToRedirectTo + "\"");
115-
}
98+
final String ticket = CommonUtils.safeGetParameter(request,getArtifactParameterName());
99+
final boolean wasGatewayed = this.gatewayStorage.hasGatewayedAlready(request, serviceUrl);
116100

117-
response.sendRedirect(urlToRedirectTo);
101+
if (CommonUtils.isNotBlank(ticket) || wasGatewayed) {
102+
filterChain.doFilter(request, response);
118103
return;
119104
}
120105

121-
filterChain.doFilter(request, response);
106+
final String modifiedServiceUrl;
107+
108+
log.debug("no ticket and no assertion found");
109+
if (this.gateway) {
110+
log.debug("setting gateway attribute in session");
111+
modifiedServiceUrl = this.gatewayStorage.storeGatewayInformation(request, serviceUrl);
112+
} else {
113+
modifiedServiceUrl = serviceUrl;
114+
}
115+
116+
if (log.isDebugEnabled()) {
117+
log.debug("Constructed service url: " + modifiedServiceUrl);
118+
}
119+
120+
final String urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casServerLoginUrl, getServiceParameterName(), modifiedServiceUrl, this.renew, this.gateway);
121+
122+
if (log.isDebugEnabled()) {
123+
log.debug("redirecting to \"" + urlToRedirectTo + "\"");
124+
}
125+
126+
response.sendRedirect(urlToRedirectTo);
122127
}
123128

124129
public final void setRenew(final boolean renew) {

cas-client-core/src/main/java/org/jasig/cas/client/session/SingleSignOutFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void doFilter(final ServletRequest servletRequest, final ServletResponse
5757
final HttpServletRequest request = (HttpServletRequest) servletRequest;
5858

5959
if ("POST".equals(request.getMethod())) {
60-
final String logoutRequest = request.getParameter("logoutRequest");
60+
final String logoutRequest = CommonUtils.safeGetParameter(request, "logoutRequest");
6161

6262
if (CommonUtils.isNotBlank(logoutRequest)) {
6363

@@ -87,7 +87,7 @@ public void doFilter(final ServletRequest servletRequest, final ServletResponse
8787
}
8888
}
8989
} else {
90-
final String artifact = request.getParameter(this.artifactParameterName);
90+
final String artifact = CommonUtils.safeGetParameter(request, this.artifactParameterName);
9191
final HttpSession session = request.getSession();
9292

9393
if (log.isDebugEnabled() && session != null) {

cas-client-core/src/main/java/org/jasig/cas/client/util/AbstractConfigurationFilter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ protected final String getPropertyFromInitParams(final FilterConfig filterConfig
3838
final String value = filterConfig.getInitParameter(propertyName);
3939

4040
if (CommonUtils.isNotBlank(value)) {
41+
log.info("Property [" + propertyName + "] loaded from FilterConfig.getInitParameter with value [" + value + "]");
4142
return value;
4243
}
4344

4445
final String value2 = filterConfig.getServletContext().getInitParameter(propertyName);
4546

4647
if (CommonUtils.isNotBlank(value2)) {
48+
log.info("Property [" + propertyName + "] loaded from ServletContext.getInitParameter with value [" + value2 + "]");
4749
return value2;
4850
}
4951
InitialContext context = null;
@@ -59,15 +61,18 @@ protected final String getPropertyFromInitParams(final FilterConfig filterConfig
5961
final String value3 = loadFromContext(context, "java:comp/env/cas/" + shortName + "/" + propertyName);
6062

6163
if (CommonUtils.isNotBlank(value3)) {
64+
log.info("Property [" + propertyName + "] loaded from JNDI Filter Specific Property with value [" + value3 + "]");
6265
return value3;
6366
}
6467

6568
final String value4 = loadFromContext(context, "java:comp/env/cas/" + propertyName);
6669

6770
if (CommonUtils.isNotBlank(value4)) {
71+
log.info("Property [" + propertyName + "] loaded from JNDI with value [" + value3 + "]");
6872
return value4;
6973
}
7074

75+
log.info("Property [" + propertyName + "] not found. Using default value [" + defaultValue + "]");
7176
return defaultValue;
7277
}
7378

@@ -79,7 +84,6 @@ protected final String loadFromContext(final InitialContext context, final Strin
7984
try {
8085
return (String) context.lookup(path);
8186
} catch (final NamingException e) {
82-
log.warn("No value found in context for: '" + path + "'; Returning null.");
8387
return null;
8488
}
8589
}

cas-client-core/src/main/java/org/jasig/cas/client/util/CommonUtils.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import javax.servlet.http.HttpServletRequest;
1313
import javax.servlet.http.HttpServletResponse;
14+
import javax.servlet.ServletRequest;
1415

1516
import java.io.IOException;
1617
import java.io.UnsupportedEncodingException;
@@ -138,7 +139,7 @@ public static boolean isNotBlank(final String string) {
138139
*/
139140
public static final String constructRedirectUrl(final String casServerLoginUrl, final String serviceParameterName, final String serviceUrl, final boolean renew, final boolean gateway) {
140141
try {
141-
return casServerLoginUrl + "?" + serviceParameterName + "="
142+
return casServerLoginUrl + (casServerLoginUrl.indexOf("?") != -1 ? "&" : "?") + serviceParameterName + "="
142143
+ URLEncoder.encode(serviceUrl, "UTF-8")
143144
+ (renew ? "&renew=true" : "")
144145
+ (gateway ? "&gateway=true" : "");
@@ -147,7 +148,7 @@ public static final String constructRedirectUrl(final String casServerLoginUrl,
147148
}
148149
}
149150

150-
public static final void readAndRespondToProxyReceptorRequest(final HttpServletRequest request, final HttpServletResponse response, final ProxyGrantingTicketStorage proxyGrantingTicketStorage) throws IOException {
151+
public static void readAndRespondToProxyReceptorRequest(final HttpServletRequest request, final HttpServletResponse response, final ProxyGrantingTicketStorage proxyGrantingTicketStorage) throws IOException {
151152
final String proxyGrantingTicketIou = request
152153
.getParameter(PARAM_PROXY_GRANTING_TICKET_IOU);
153154

@@ -182,7 +183,7 @@ public static final void readAndRespondToProxyReceptorRequest(final HttpServletR
182183
* @param response the HttpServletResponse
183184
* @return the service url to use.
184185
*/
185-
public static final String constructServiceUrl(final HttpServletRequest request,
186+
public static String constructServiceUrl(final HttpServletRequest request,
186187
final HttpServletResponse response, final String service, final String serverName, final String artifactParameterName, final boolean encode) {
187188
if (CommonUtils.isNotBlank(service)) {
188189
return encode ? response.encodeURL(service) : service;
@@ -236,4 +237,24 @@ public static final String constructServiceUrl(final HttpServletRequest request,
236237
return returnValue;
237238
}
238239

240+
/**
241+
* Safe method for retrieving a parameter from the request without disrupting the reader UNLESS the parameter
242+
* actually exists in the query string.
243+
* <p>
244+
* Note, this does not work for POST Requests for "logoutRequest". It works for all other CAS POST requests because the
245+
* parameter is ALWAYS in the GET request.
246+
* <p>
247+
* If we see the "logoutRequest" parameter we MUST treat it as if calling the standard request.getParameter.
248+
*
249+
* @param request the request to check.
250+
* @param parameter the parameter to look for.
251+
* @return the value of the parameter.
252+
*/
253+
public static String safeGetParameter(final HttpServletRequest request, final String parameter) {
254+
if ("POST".equals(request.getMethod()) && "logoutRequest".equals(parameter)) {
255+
LOG.warn("safeGetParameter called on a POST HttpServletRequest for LogoutRequest. Cannot complete check safely. Reverting to standard behavior for this Parameter");
256+
return request.getParameter(parameter);
257+
}
258+
return request.getQueryString() == null || request.getQueryString().indexOf(parameter) == -1 ? null : request.getParameter(parameter);
259+
}
239260
}

cas-client-core/src/main/java/org/jasig/cas/client/util/DelegatingFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import javax.servlet.ServletException;
1515
import javax.servlet.ServletRequest;
1616
import javax.servlet.ServletResponse;
17+
import javax.servlet.http.HttpServletRequest;
1718
import java.io.IOException;
1819
import java.util.Iterator;
1920
import java.util.Map;
@@ -89,8 +90,7 @@ public void doFilter(final ServletRequest request,
8990
final ServletResponse response, final FilterChain filterChain)
9091
throws IOException, ServletException {
9192

92-
final String parameter = request
93-
.getParameter(this.requestParameterName);
93+
final String parameter = CommonUtils.safeGetParameter((HttpServletRequest) request, this.requestParameterName);
9494

9595
if (CommonUtils.isNotEmpty(parameter)) {
9696
for (final Iterator iter = this.delegators.keySet().iterator(); iter

cas-client-core/src/main/java/org/jasig/cas/client/validation/AbstractTicketValidationFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public final void doFilter(final ServletRequest servletRequest, final ServletRes
121121

122122
final HttpServletRequest request = (HttpServletRequest) servletRequest;
123123
final HttpServletResponse response = (HttpServletResponse) servletResponse;
124-
final String ticket = request.getParameter(getArtifactParameterName());
124+
final String ticket = CommonUtils.safeGetParameter(request, getArtifactParameterName());
125125

126126
if (CommonUtils.isNotBlank(ticket)) {
127127
if (log.isDebugEnabled()) {

cas-client-core/src/main/java/org/jasig/cas/client/validation/Cas20ProxyReceivingTicketValidationFilter.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected final TicketValidator getTicketValidator(final FilterConfig filterConf
9191
if (CommonUtils.isNotBlank(allowAnyProxy) || CommonUtils.isNotBlank(allowedProxyChains)) {
9292
final Cas20ProxyTicketValidator v = new Cas20ProxyTicketValidator(casServerUrlPrefix);
9393
v.setAcceptAnyProxy(parseBoolean(allowAnyProxy));
94-
v.setAllowedProxyChains(new ProxyList(constructListOfProxies(allowedProxyChains)));
94+
v.setAllowedProxyChains(createProxyList(allowedProxyChains));
9595
validator = v;
9696
} else {
9797
validator = new Cas20ServiceTicketValidator(casServerUrlPrefix);
@@ -117,17 +117,15 @@ protected final TicketValidator getTicketValidator(final FilterConfig filterConf
117117
return validator;
118118
}
119119

120-
protected final List constructListOfProxies(final String proxies) {
120+
protected final ProxyList createProxyList(final String proxies) {
121121
if (CommonUtils.isBlank(proxies)) {
122-
return new ArrayList();
122+
return new ProxyList();
123123
}
124124

125-
final String[] splitProxies = proxies.split("\n");
126-
final List items = Arrays.asList(splitProxies);
127125
final ProxyListEditor editor = new ProxyListEditor();
128-
editor.setValue(items);
129-
return (List) editor.getValue();
130-
}
126+
editor.setAsText(proxies);
127+
return (ProxyList) editor.getValue();
128+
}
131129

132130
public void destroy() {
133131
super.destroy();
@@ -166,4 +164,8 @@ public void setTimer(final Timer timer) {
166164
public void setTimerTask(final TimerTask timerTask) {
167165
this.timerTask = timerTask;
168166
}
167+
168+
public void setMillisBetweenCleanUps(final int millisBetweenCleanUps) {
169+
this.millisBetweenCleanUps = millisBetweenCleanUps;
170+
}
169171
}

cas-client-core/src/main/java/org/jasig/cas/client/validation/ProxyList.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
package org.jasig.cas.client.validation;
77

8+
import org.jasig.cas.client.util.CommonUtils;
9+
810
import java.util.ArrayList;
911
import java.util.List;
1012
import java.util.Iterator;
@@ -22,6 +24,13 @@ public final class ProxyList {
2224
private final List proxyChains;
2325

2426
public ProxyList(final List proxyChains) {
27+
CommonUtils.assertNotNull(proxyChains, "List of proxy chains cannot be null.");
28+
29+
// Assert that all entries in the list are String[]
30+
for (final Iterator iter = proxyChains.iterator(); iter.hasNext();) {
31+
CommonUtils.assertTrue(iter.next() instanceof String[], "Proxy chains must contain String[] items exclusively.");
32+
}
33+
2534
this.proxyChains = proxyChains;
2635
}
2736

cas-client-core/src/main/java/org/jasig/cas/client/validation/Saml11TicketValidator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.net.HttpURLConnection;
1414
import java.net.URL;
1515
import java.util.*;
16+
import java.text.DateFormat;
17+
import java.text.SimpleDateFormat;
1618

1719
/**
1820
* TicketValidator that can understand validating a SAML artifact. This includes the SOAP request/response.
@@ -158,8 +160,14 @@ private List getValuesFrom(final SAMLAttribute attribute) {
158160
return list;
159161
}
160162

163+
private static String getFormattedDateAndTime(final Date date) {
164+
final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
165+
return dateFormat.format(date);
166+
}
167+
168+
161169
protected String retrieveResponseFromServer(final URL validationUrl, final String ticket) {
162-
final String MESSAGE_TO_SEND = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/><SOAP-ENV:Body><samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" MajorVersion=\"1\" MinorVersion=\"1\" RequestID=\"_192.168.16.51.1024506224022\" IssueInstant=\"2002-06-19T17:03:44.022Z\">"
170+
final String MESSAGE_TO_SEND = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/><SOAP-ENV:Body><samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" MajorVersion=\"1\" MinorVersion=\"1\" RequestID=\"" + UUID.randomUUID().toString() + "\" IssueInstant=\"" + getFormattedDateAndTime(new Date()) + "\">"
163171
+ "<samlp:AssertionArtifact>" + ticket
164172
+ "</samlp:AssertionArtifact></samlp:Request></SOAP-ENV:Body></SOAP-ENV:Envelope>";
165173

0 commit comments

Comments
 (0)