// Path: src/main/java/net/unicon/cas/addons/authentication/support/Assertions.java
// public final class Assertions {
// 
// 	/**
// 	 * Non-instantiable
// 	 */
// 	private Assertions() {
// 	}
// 
// 	/**
// 	 * Extracts an authenticated ${@link Principal} from a provided ${@link Assertion} instance.
// 	 * <p/>
// 	 * It is a caller's of this method responsibility to ensure that provided ${@link Assertion} instance is not null
// 	 * to avoid NPE at runtime.
// 	 *
// 	 * @param assertion instance to retrieve ${@link Principal} from
// 	 * @return Authenticated Principal
// 	 * @throws NullPointerException if provided Assertion is <i>null</i>
// 	 */
// 	public static Principal getAuthenticatedPrincipalFrom(Assertion assertion) {
// 		final List<Authentication> chain = assertion.getChainedAuthentications();
// 		final Principal principal = chain.get(chain.size() - 1).getPrincipal();
// 		return principal;
// 	}
// 
// 	/**
// 	 * Extracts a list of proxy ${@link Authentication}s MINUS the original authenticated ${@link Principal} f
// 	 * from a provided ${@link Assertion} instance.
// 	 * <p/>
// 	 * It is a caller's of this method responsibility to ensure that provided ${@link Assertion} instance is not null
// 	 * to avoid NPE at runtime.
// 	 *
// 	 * @param assertion instance to retrieve a list of proxy ${@link Authentication}s from
// 	 * @return A list of proxy authentications
// 	 * @throws NullPointerException if provided Assertion is <i>null</i>
// 	 */
// 	public static List<Authentication> getProxyAuthenticationsFrom(Assertion assertion) {
// 		final List<Authentication> chain = assertion.getChainedAuthentications();
// 		final List<Authentication> proxyAuthentications = chain.subList(0, chain.size()-1);
// 		return proxyAuthentications;
// 	}
// }
// 
// Path: src/main/java/net/unicon/cas/addons/serviceregistry/RegisteredServiceWithAttributes.java
// public interface RegisteredServiceWithAttributes extends RegisteredService {
// 
//     Map<String, Object> getExtraAttributes();
// 
// }
// 
// Path: src/main/java/net/unicon/cas/addons/serviceregistry/services/RegisteredServicesPolicies.java
// public interface RegisteredServicesPolicies {
// 
// 	/**
// 	 * Policy method governing WebSSO session initiation based on the provided configuration attributes of a given
// 	 * <code>RegisteredServiceWithAttributes</code>
// 	 *
// 	 * @param registeredService for which to determine whether to initiate an SSO session or not
// 	 * @return true if a provided service is eligible for an SSO session initiation, false otherwise
// 	 */
// 	boolean ssoSessionInitiating(RegisteredServiceWithAttributes registeredService);
// }


import net.unicon.cas.addons.authentication.support.Assertions;
import net.unicon.cas.addons.serviceregistry.RegisteredServiceWithAttributes;
import net.unicon.cas.addons.serviceregistry.services.RegisteredServicesPolicies;
import org.jasig.cas.CentralAuthenticationService;
import org.jasig.cas.authentication.principal.Service;
import org.jasig.cas.authentication.principal.WebApplicationService;
import org.jasig.cas.services.ServicesManager;
import org.jasig.cas.ticket.Ticket;
import org.jasig.cas.ticket.TicketGrantingTicket;
import org.jasig.cas.ticket.registry.TicketRegistry;
import org.jasig.cas.validation.Assertion;
import org.jasig.cas.web.ServiceValidateController;
import org.jasig.cas.web.support.ArgumentExtractor;
import org.jasig.cas.web.support.WebUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
		this.registeredServicesPolicies = registeredServicesPolicies;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		Assert.notNull(this.ticketRegistry, "ticketRegistry is required");
		Assert.notNull(this.cas, "cas is required");
		Assert.notNull(this.servicesManager, "servicesManager is required");
		Assert.notNull(this.argExtractor, "argExtractor is required");
		Assert.notNull(this.registeredServicesPolicies, "registeredServicesPolicies is required");
	}

	@Override
	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
		final WebApplicationService service = this.argExtractor.extractService(request);
		if (service == null) {
			return super.handleRequest(request, response);
		}
		Ticket st = this.ticketRegistry.getTicket(service.getArtifactId());
		if (st == null) {
			return super.handleRequest(request, response);
		}
		//Make the tgt available in ThreadLocal for access in "onSuccessfulValidation()"
		tgtHolder.set(st.getGrantingTicket());
		return super.handleRequest(request, response);
	}

	@Override
	protected void onSuccessfulValidation(String serviceTicketId, Assertion assertion) {
		try {
// Path: src/main/java/net/unicon/cas/addons/authentication/support/Assertions.java
// public final class Assertions {
// 
// 	/**
// 	 * Non-instantiable
// 	 */
// 	private Assertions() {
// 	}
// 
// 	/**
// 	 * Extracts an authenticated ${@link Principal} from a provided ${@link Assertion} instance.
// 	 * <p/>
// 	 * It is a caller's of this method responsibility to ensure that provided ${@link Assertion} instance is not null
// 	 * to avoid NPE at runtime.
// 	 *
// 	 * @param assertion instance to retrieve ${@link Principal} from
// 	 * @return Authenticated Principal
// 	 * @throws NullPointerException if provided Assertion is <i>null</i>
// 	 */
// 	public static Principal getAuthenticatedPrincipalFrom(Assertion assertion) {
// 		final List<Authentication> chain = assertion.getChainedAuthentications();
// 		final Principal principal = chain.get(chain.size() - 1).getPrincipal();
// 		return principal;
// 	}
// 
// 	/**
// 	 * Extracts a list of proxy ${@link Authentication}s MINUS the original authenticated ${@link Principal} f
// 	 * from a provided ${@link Assertion} instance.
// 	 * <p/>
// 	 * It is a caller's of this method responsibility to ensure that provided ${@link Assertion} instance is not null
// 	 * to avoid NPE at runtime.
// 	 *
// 	 * @param assertion instance to retrieve a list of proxy ${@link Authentication}s from
// 	 * @return A list of proxy authentications
// 	 * @throws NullPointerException if provided Assertion is <i>null</i>
// 	 */
// 	public static List<Authentication> getProxyAuthenticationsFrom(Assertion assertion) {
// 		final List<Authentication> chain = assertion.getChainedAuthentications();
// 		final List<Authentication> proxyAuthentications = chain.subList(0, chain.size()-1);
// 		return proxyAuthentications;
// 	}
// }
// 
// Path: src/main/java/net/unicon/cas/addons/serviceregistry/RegisteredServiceWithAttributes.java
// public interface RegisteredServiceWithAttributes extends RegisteredService {
// 
//     Map<String, Object> getExtraAttributes();
// 
// }
// 
// Path: src/main/java/net/unicon/cas/addons/serviceregistry/services/RegisteredServicesPolicies.java
// public interface RegisteredServicesPolicies {
// 
// 	/**
// 	 * Policy method governing WebSSO session initiation based on the provided configuration attributes of a given
// 	 * <code>RegisteredServiceWithAttributes</code>
// 	 *
// 	 * @param registeredService for which to determine whether to initiate an SSO session or not
// 	 * @return true if a provided service is eligible for an SSO session initiation, false otherwise
// 	 */
// 	boolean ssoSessionInitiating(RegisteredServiceWithAttributes registeredService);
// }


// Path: src/main/java/net/unicon/cas/addons/web/support/SsoDestroyingServiceValidateController.java
import net.unicon.cas.addons.authentication.support.Assertions;
import net.unicon.cas.addons.serviceregistry.RegisteredServiceWithAttributes;
import net.unicon.cas.addons.serviceregistry.services.RegisteredServicesPolicies;
import org.jasig.cas.CentralAuthenticationService;
import org.jasig.cas.authentication.principal.Service;
import org.jasig.cas.authentication.principal.WebApplicationService;
import org.jasig.cas.services.ServicesManager;
import org.jasig.cas.ticket.Ticket;
import org.jasig.cas.ticket.TicketGrantingTicket;
import org.jasig.cas.ticket.registry.TicketRegistry;
import org.jasig.cas.validation.Assertion;
import org.jasig.cas.web.ServiceValidateController;
import org.jasig.cas.web.support.ArgumentExtractor;
import org.jasig.cas.web.support.WebUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

		this.registeredServicesPolicies = registeredServicesPolicies;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		Assert.notNull(this.ticketRegistry, "ticketRegistry is required");
		Assert.notNull(this.cas, "cas is required");
		Assert.notNull(this.servicesManager, "servicesManager is required");
		Assert.notNull(this.argExtractor, "argExtractor is required");
		Assert.notNull(this.registeredServicesPolicies, "registeredServicesPolicies is required");
	}

	@Override
	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
		final WebApplicationService service = this.argExtractor.extractService(request);
		if (service == null) {
			return super.handleRequest(request, response);
		}
		Ticket st = this.ticketRegistry.getTicket(service.getArtifactId());
		if (st == null) {
			return super.handleRequest(request, response);
		}
		//Make the tgt available in ThreadLocal for access in "onSuccessfulValidation()"
		tgtHolder.set(st.getGrantingTicket());
		return super.handleRequest(request, response);
	}

	@Override
	protected void onSuccessfulValidation(String serviceTicketId, Assertion assertion) {
		try {
			RegisteredServiceWithAttributes registeredService =