allow extension points for JSON validation parsing. add filter and validator
This commit is contained in:
parent
1561da75ad
commit
1fc896c458
|
|
@ -52,7 +52,7 @@ public class Cas20ProxyTicketValidator extends Cas20ServiceTicketValidator {
|
|||
|
||||
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(
|
||||
|
|
@ -85,6 +85,10 @@ public class Cas20ProxyTicketValidator extends Cas20ServiceTicketValidator {
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,14 +78,14 @@ public class Cas20ServiceTicketValidator extends AbstractCasProtocolUrlBasedTick
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
@ -113,6 +113,18 @@ public class Cas20ServiceTicketValidator extends AbstractCasProtocolUrlBasedTick
|
|||
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:
|
||||
* <cas:attributes>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue