// Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 202143418251140727L;
// 
// 	/**
// 	 * 
// 	 */
// 	public ExchangeWebServicesRuntimeException() {
// 	}
// 
// 	/**
// 	 * @param message
// 	 */
// 	public ExchangeWebServicesRuntimeException(String message) {
// 		super(message);
// 	}
// 
// 	/**
// 	 * @param cause
// 	 */
// 	public ExchangeWebServicesRuntimeException(Throwable cause) {
// 		super(cause);
// 	}
// 
// 	/**
// 	 * @param message
// 	 * @param cause
// 	 */
// 	public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// }


import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ProtocolException;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.http.protocol.HttpContext;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;
	     *
	     * For our application, we want to follow the redirect for a 302 as long as it is to a safe location and
	     * have the redirect be a POST.
	     *
	     * This code is modified from http-components' http-client 4.2.5.  Since we only use POST the code for the
	     * other HTTP methods has been removed to simplify this method.
	     *
	     * @param request Http request
	     * @param response Http response
	     * @param context Http context
	     * @return Request to issue to the redirected location
	     * @throws ProtocolException protocol exception
	     */
	    @Override
	    public HttpUriRequest getRedirect(
	            final HttpRequest request,
	            final HttpResponse response,
	            final HttpContext context) throws ProtocolException {
	        URI uri = getLocationURI(request, response, context);
	        log.info("Following redirect to "+ uri.toString());
	        String method = request.getRequestLine().getMethod();
	        int status = response.getStatusLine().getStatusCode();

	        // Insure location is safe
	        if (matchesPatternSet(uri, unsafeUriPatterns)) {
	            log.warn("Not following to URI {} - matches a configured unsafe URI pattern "+ uri.toString());
	            throw new ExchangeWebServicesRuntimeException("Autodiscover redirected to unsafe URI " + uri.toString());
	        }

	        if (!matchesPatternSet(uri, uriRequirementPatterns) && uriRequirementPatterns.size() > 0) {
// Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 202143418251140727L;
// 
// 	/**
// 	 * 
// 	 */
// 	public ExchangeWebServicesRuntimeException() {
// 	}
// 
// 	/**
// 	 * @param message
// 	 */
// 	public ExchangeWebServicesRuntimeException(String message) {
// 		super(message);
// 	}
// 
// 	/**
// 	 * @param cause
// 	 */
// 	public ExchangeWebServicesRuntimeException(Throwable cause) {
// 		super(cause);
// 	}
// 
// 	/**
// 	 * @param message
// 	 * @param cause
// 	 */
// 	public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// }


// Path: src/main/java/com/microsoft/exchange/autodiscover/AutodiscoverRedirectStrategy.java
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ProtocolException;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.http.protocol.HttpContext;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;

	     *
	     * For our application, we want to follow the redirect for a 302 as long as it is to a safe location and
	     * have the redirect be a POST.
	     *
	     * This code is modified from http-components' http-client 4.2.5.  Since we only use POST the code for the
	     * other HTTP methods has been removed to simplify this method.
	     *
	     * @param request Http request
	     * @param response Http response
	     * @param context Http context
	     * @return Request to issue to the redirected location
	     * @throws ProtocolException protocol exception
	     */
	    @Override
	    public HttpUriRequest getRedirect(
	            final HttpRequest request,
	            final HttpResponse response,
	            final HttpContext context) throws ProtocolException {
	        URI uri = getLocationURI(request, response, context);
	        log.info("Following redirect to "+ uri.toString());
	        String method = request.getRequestLine().getMethod();
	        int status = response.getStatusLine().getStatusCode();

	        // Insure location is safe
	        if (matchesPatternSet(uri, unsafeUriPatterns)) {
	            log.warn("Not following to URI {} - matches a configured unsafe URI pattern "+ uri.toString());
	            throw new ExchangeWebServicesRuntimeException("Autodiscover redirected to unsafe URI " + uri.toString());
	        }

	        if (!matchesPatternSet(uri, uriRequirementPatterns) && uriRequirementPatterns.size() > 0) {
	            log.warn("Not following to URI {} - URI does not match a required URI pattern "+ uri.toString());