parent
ecaaa1e1c9
commit
2527aef900
|
|
@ -8,6 +8,8 @@ package org.jasig.cas.client.web.filter;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jasig.cas.client.util.CommonUtils;
|
||||
import org.jasig.cas.web.support.ArgumentExtractor;
|
||||
import org.jasig.cas.web.support.CasArgumentExtractor;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
|
|
@ -68,7 +70,9 @@ public abstract class AbstractCasFilter implements Filter {
|
|||
*/
|
||||
private boolean useSession = true;
|
||||
|
||||
private String artifactParameterName = "ticket";
|
||||
/** Instance of an ArgumentExtractor to retrieve arguments based on supported protocol. Default is the CAS 2 protocol. */
|
||||
private ArgumentExtractor argumentExtractor = new CasArgumentExtractor();
|
||||
|
||||
|
||||
protected AbstractCasFilter(final String service, final boolean isServerName) {
|
||||
CommonUtils.assertNotNull(service, "service must be set");
|
||||
|
|
@ -122,7 +126,7 @@ public abstract class AbstractCasFilter implements Filter {
|
|||
|
||||
if (CommonUtils.isNotBlank(request.getQueryString())) {
|
||||
final int location = request.getQueryString().indexOf(
|
||||
this.artifactParameterName + "=");
|
||||
this.argumentExtractor.getArtifactParameterName() + "=");
|
||||
|
||||
if (location == 0) {
|
||||
final String returnValue = response.encodeURL(buffer
|
||||
|
|
@ -139,7 +143,7 @@ public abstract class AbstractCasFilter implements Filter {
|
|||
buffer.append(request.getQueryString());
|
||||
} else if (location > 0) {
|
||||
final int actualLocation = request.getQueryString()
|
||||
.indexOf("&" + this.artifactParameterName + "=");
|
||||
.indexOf("&" + this.argumentExtractor.getArtifactParameterName() + "=");
|
||||
|
||||
if (actualLocation == -1) {
|
||||
buffer.append(request.getQueryString());
|
||||
|
|
@ -166,17 +170,13 @@ public abstract class AbstractCasFilter implements Filter {
|
|||
this.useSession = useSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defaults to "ticket" based on the CAS 2 Specification. Other examples include SAML artifacts which are defined as
|
||||
* "SAMLart"
|
||||
*
|
||||
* @param artifactName
|
||||
*/
|
||||
public final void setArtifactParameterName(final String artifactName) {
|
||||
this.artifactParameterName = artifactName;
|
||||
|
||||
protected ArgumentExtractor getArgumentExtractor() {
|
||||
return this.argumentExtractor;
|
||||
}
|
||||
|
||||
protected final String getArtifactParameterName() {
|
||||
return this.artifactParameterName;
|
||||
public void setArgumentExtractor(final ArgumentExtractor argumentExtractor) {
|
||||
CommonUtils.assertNotNull(argumentExtractor, "argumentExtractor cannot be null.");
|
||||
this.argumentExtractor = argumentExtractor;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,11 +41,6 @@ public final class AuthenticationFilter extends AbstractCasFilter {
|
|||
*/
|
||||
private boolean gateway = false;
|
||||
|
||||
/**
|
||||
* Defines the parameter to look for when attempting to construct the login url.
|
||||
*/
|
||||
private String serviceParameterName = "service";
|
||||
|
||||
public AuthenticationFilter(final String serverName, final boolean isServerName, String casServerLoginUrl) {
|
||||
super(serverName, isServerName);
|
||||
CommonUtils.assertNotNull(casServerLoginUrl,
|
||||
|
|
@ -57,7 +52,7 @@ public final class AuthenticationFilter extends AbstractCasFilter {
|
|||
final HttpServletResponse response, final FilterChain filterChain)
|
||||
throws IOException, ServletException {
|
||||
final HttpSession session = request.getSession(isUseSession());
|
||||
final String ticket = request.getParameter(getArtifactParameterName());
|
||||
final String ticket = request.getParameter(getArgumentExtractor().getArtifactParameterName());
|
||||
final Assertion assertion = session != null ? (Assertion) session
|
||||
.getAttribute(CONST_ASSERTION) : null;
|
||||
final boolean wasGatewayed = session != null
|
||||
|
|
@ -71,7 +66,7 @@ public final class AuthenticationFilter extends AbstractCasFilter {
|
|||
}
|
||||
|
||||
final String serviceUrl = constructServiceUrl(request, response);
|
||||
final String urlToRedirectTo = this.casServerLoginUrl + "?" + this.serviceParameterName + "="
|
||||
final String urlToRedirectTo = this.casServerLoginUrl + "?" + getArgumentExtractor().getServiceParameterName() + "="
|
||||
+ URLEncoder.encode(serviceUrl, "UTF-8")
|
||||
+ (this.renew ? "&renew=true" : "")
|
||||
+ (this.gateway ? "&gateway=true" : "");
|
||||
|
|
@ -99,14 +94,4 @@ public final class AuthenticationFilter extends AbstractCasFilter {
|
|||
public void setGateway(final boolean gateway) {
|
||||
this.gateway = gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defaults to "service" due to the CAS 2.0 specification. Other options
|
||||
* include the SAML specifications's TARGET attribute.
|
||||
*
|
||||
* @param serviceParameterName
|
||||
*/
|
||||
public void setServiceParameterName(final String serviceParameterName) {
|
||||
this.serviceParameterName = serviceParameterName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public final class TicketValidationFilter extends AbstractCasFilter {
|
|||
protected void doFilterInternal(final HttpServletRequest request,
|
||||
final HttpServletResponse response, final FilterChain filterChain)
|
||||
throws IOException, ServletException {
|
||||
final String ticket = request.getParameter(getArtifactParameterName());
|
||||
final String ticket = request.getParameter(getArgumentExtractor().getArtifactParameterName());
|
||||
|
||||
if (CommonUtils.isNotBlank(ticket)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
|
|
@ -116,7 +116,6 @@ public final class TicketValidationFilter extends AbstractCasFilter {
|
|||
this.redirectAfterValidation = redirectAfterValidation;
|
||||
}
|
||||
|
||||
|
||||
public void setExceptionOnValidationFailure(final boolean exceptionOnValidationFailure) {
|
||||
this.exceptionOnValidationFailure = exceptionOnValidationFailure;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public final class ThreadLocalAwareCasServiceFilter extends AbstractCasFilter {
|
|||
final HttpServletResponse response, final FilterChain filterChain)
|
||||
throws IOException, ServletException {
|
||||
final boolean hasTicket = CommonUtils.isNotBlank(request
|
||||
.getParameter(getArtifactParameterName()));
|
||||
.getParameter(getArgumentExtractor().getArtifactParameterName()));
|
||||
try {
|
||||
if (hasTicket) {
|
||||
final Service service = new SimpleService(constructServiceUrl(
|
||||
|
|
|
|||
Loading…
Reference in New Issue