/* Copyright 2006-2015 SpringSource.
 *
 * Licensed 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
 *
 *      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 grails.plugin.springsecurity.web.authentication;

import grails.plugin.springsecurity.SpringSecurityUtils;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.savedrequest.RequestCache;

/**
 * @author <a href='mailto:burt@burtbeckwith.com'>Burt Beckwith</a>
 */
public class AjaxAwareAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

	protected String ajaxSuccessUrl;
	protected RequestCache requestCache;

<<<<<<< HEAD
	/**
	 * Dependency injection for the Ajax success url, e.g. '/login/ajaxSuccess'
	 * @param url the url
	 */
	public void setAjaxSuccessUrl(final String url) {
		ajaxSuccessUrl = url;
=======
	@Override
	protected String determineTargetUrl(HttpServletRequest request, HttpServletResponse response) {
		return SpringSecurityUtils.isAjax(request) ? ajaxSuccessUrl : super.determineTargetUrl(request, response);
>>>>>>> master
	}

	@Override
	public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response,
			final Authentication authentication) throws ServletException, IOException {
		try {
            if (SpringSecurityUtils.isAjax(request)) {
                this.clearAuthenticationAttributes(request);
                this.logger.debug("Redirecting to Ajax Success Url: " + ajaxSuccessUrl);
                this.getRedirectStrategy().sendRedirect(request, response, ajaxSuccessUrl);
            } else {
                super.onAuthenticationSuccess(request, response, authentication);
            }
		}
		finally {
			// always remove the saved request
			requestCache.removeRequest(request, response);
		}
	}

	/**
	 * Dependency injection for the Ajax success url, e.g. '/login/ajaxSuccess'.
	 * @param url the url
	 */
	public void setAjaxSuccessUrl(final String url) {
		ajaxSuccessUrl = url;
	}

	@Override
	public void setRequestCache(RequestCache cache) {
		super.setRequestCache(cache);
		requestCache = cache;
	}
}

@@ -1359,450 +1359,8 @@
 e;%0A%0A
-%3C%3C%3C%3C%3C%3C%3C HEAD%0A%09/**%0A%09 * Dependency injection for the Ajax success url, e.g. '/login/ajaxSuccess'%0A%09 * @param url the url%0A%09 */%0A%09public void setAjaxSuccessUrl(final String url) %7B%0A%09%09ajaxSuccessUrl = url;%0A=======%0A%09@Override%0A%09protected String determineTargetUrl(HttpServletRequest request, HttpServletResponse response) %7B%0A%09%09return SpringSecurityUtils.isAjax(request) ? ajaxSuccessUrl : super.determineTargetUrl(request, response);%0A%3E%3E%3E%3E%3E%3E%3E master%0A%09%7D%0A%0A
 %09@Ov

Correct bad merge