Skip to content

Commit

Permalink
allow extension points for JSON validation parsing. add filter and va…
Browse files Browse the repository at this point in the history
…lidator
  • Loading branch information
SavvasMisaghMoayyed committed May 17, 2017
1 parent 4cb1eb4 commit c00627c
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected String getUrlSuffix() {

protected void customParseResponse(final String response, final Assertion assertion)
throws TicketValidationException {
final List<String> proxies = XmlUtils.getTextForElements(response, "proxy");
final List<String> proxies = parseProxiesFromResponse(response);

if (proxies == null) {
throw new InvalidProxyChainTicketValidationException(
Expand Down Expand Up @@ -85,6 +85,10 @@ protected void customParseResponse(final String response, final Assertion assert
throw new InvalidProxyChainTicketValidationException("Invalid proxy chain: " + proxies.toString());
}

protected List<String> parseProxiesFromResponse(final String response) {
return XmlUtils.getTextForElements(response, "proxy");
}

public final void setAcceptAnyProxy(final boolean acceptAnyProxy) {
this.acceptAnyProxy = acceptAnyProxy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ protected String getUrlSuffix() {
}

protected final Assertion parseResponseFromServer(final String response) throws TicketValidationException {
final String error = XmlUtils.getTextForElement(response, "authenticationFailure");
final String error = parseAuthenticationFailureFromResponse(response);

if (CommonUtils.isNotBlank(error)) {
throw new TicketValidationException(error);
}

final String principal = XmlUtils.getTextForElement(response, "user");
final String proxyGrantingTicketIou = XmlUtils.getTextForElement(response, "proxyGrantingTicket");
final String principal = parsePrincipalFromResponse(response);
final String proxyGrantingTicketIou = parseProxyGrantingTicketFromResponse(response);

final String proxyGrantingTicket;
if (CommonUtils.isBlank(proxyGrantingTicketIou) || this.proxyGrantingTicketStorage == null) {
Expand Down Expand Up @@ -113,6 +113,18 @@ protected final Assertion parseResponseFromServer(final String response) throws
return assertion;
}

protected String parseProxyGrantingTicketFromResponse(final String response) {
return XmlUtils.getTextForElement(response, "proxyGrantingTicket");
}

protected String parsePrincipalFromResponse(final String response) {
return XmlUtils.getTextForElement(response, "user");
}

protected String parseAuthenticationFailureFromResponse(final String response) {
return XmlUtils.getTextForElement(response, "authenticationFailure");
}

/**
* Default attribute parsing of attributes that look like the following:
* &lt;cas:attributes&gt;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to Jasig under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Jasig licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at the following location:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jasig.cas.client.validation;

/**
* Creates either a Cas30JsonServiceTicketValidator to validate tickets.
*
* @author Misagh Moayyed
*/
public class Cas30JsonProxyReceivingTicketValidationFilter extends Cas30ProxyReceivingTicketValidationFilter {

public Cas30JsonProxyReceivingTicketValidationFilter() {
super();
this.defaultServiceTicketValidatorClass = Cas30JsonServiceTicketValidator.class;
this.defaultProxyTicketValidatorClass = Cas30JsonServiceTicketValidator.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.jasig.cas.client.validation;

import java.util.List;
import java.util.Map;

/**
* This is {@link Cas30JsonServiceTicketValidator}.
*
* @author Misagh Moayyed
*/
public class Cas30JsonServiceTicketValidator extends Cas30ProxyTicketValidator {
public Cas30JsonServiceTicketValidator(final String casServerUrlPrefix) {
super(casServerUrlPrefix);
getCustomParameters().put("format", "JSON");
}

@Override
protected List<String> parseProxiesFromResponse(final String response) {
return super.parseProxiesFromResponse(response);
}

@Override
protected String parseProxyGrantingTicketFromResponse(final String response) {
return super.parseProxyGrantingTicketFromResponse(response);
}

@Override
protected String parsePrincipalFromResponse(final String response) {
return super.parsePrincipalFromResponse(response);
}

@Override
protected String parseAuthenticationFailureFromResponse(final String response) {
return super.parseAuthenticationFailureFromResponse(response);
}

@Override
protected Map<String, Object> extractCustomAttributes(final String xml) {
return super.extractCustomAttributes(xml);
}
}

0 comments on commit c00627c

Please sign in to comment.