// Path: src/main/java/com/pugnascotia/reactdemo/config/ajax/AjaxAuthenticationSuccessHandler.java
// @Component
// public class AjaxAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
// 
// 	private final ObjectMapper mapper;
// 
// 	@Inject
// 	public AjaxAuthenticationSuccessHandler(ObjectMapper mapper) {
// 		this.mapper = mapper;
// 	}
// 
// 	@Override
// 	public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
// 		response.setStatus(HttpServletResponse.SC_OK);
// 		Cookies.setSecurityTokens(request, response);
// 
// 		ServletOutputStream outputStream = response.getOutputStream();
// 
// 		mapper.writeValue(outputStream, State.getAuthState(request));
// 
// 		outputStream.close();
// 	}
// }
// 
// Path: src/main/java/com/pugnascotia/reactdemo/config/ajax/AjaxAuthenticationFailureHandler.java
// @Component
// public class AjaxAuthenticationFailureHandler implements AuthenticationFailureHandler {
// 
// 	/** Send a 401 Unauthorized if authentication failed */
// 
// 	@Override
// 	public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
// 		response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication failed");
// 	}
// }
// 
// Path: src/main/java/com/pugnascotia/reactdemo/config/ajax/AjaxLogoutSuccessHandler.java
// @Component
// public class AjaxLogoutSuccessHandler implements LogoutSuccessHandler {
// 
// 	/**
// 	 * On a successful AJAX logout, send a redirect to /api/account. The response body
// 	 * won't contain anything particularly useful, but the response headers will contain
// 	 * the latest session and security (CSRF) tokens, meaning that subsequent POST requests
// 	 * can work.
// 	 */
// 	@Override
// 	public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
// 		response.sendRedirect("/api/account");
// 	}
// }


import javax.inject.Inject;
import com.pugnascotia.reactdemo.config.ajax.AjaxAuthenticationSuccessHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.csrf.CsrfFilter;
import org.springframework.security.web.csrf.CsrfTokenRepository;
import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository;
import com.pugnascotia.reactdemo.config.ajax.AjaxAuthenticationFailureHandler;
import com.pugnascotia.reactdemo.config.ajax.AjaxLogoutSuccessHandler;
package com.pugnascotia.reactdemo.config;



@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

	@Inject
	private AjaxAuthenticationSuccessHandler authSuccessHandler;

	@Inject
	private AjaxAuthenticationFailureHandler authFailureHandler;

	@Inject
// Path: src/main/java/com/pugnascotia/reactdemo/config/ajax/AjaxAuthenticationSuccessHandler.java
// @Component
// public class AjaxAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
// 
// 	private final ObjectMapper mapper;
// 
// 	@Inject
// 	public AjaxAuthenticationSuccessHandler(ObjectMapper mapper) {
// 		this.mapper = mapper;
// 	}
// 
// 	@Override
// 	public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
// 		response.setStatus(HttpServletResponse.SC_OK);
// 		Cookies.setSecurityTokens(request, response);
// 
// 		ServletOutputStream outputStream = response.getOutputStream();
// 
// 		mapper.writeValue(outputStream, State.getAuthState(request));
// 
// 		outputStream.close();
// 	}
// }
// 
// Path: src/main/java/com/pugnascotia/reactdemo/config/ajax/AjaxAuthenticationFailureHandler.java
// @Component
// public class AjaxAuthenticationFailureHandler implements AuthenticationFailureHandler {
// 
// 	/** Send a 401 Unauthorized if authentication failed */
// 
// 	@Override
// 	public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
// 		response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication failed");
// 	}
// }
// 
// Path: src/main/java/com/pugnascotia/reactdemo/config/ajax/AjaxLogoutSuccessHandler.java
// @Component
// public class AjaxLogoutSuccessHandler implements LogoutSuccessHandler {
// 
// 	/**
// 	 * On a successful AJAX logout, send a redirect to /api/account. The response body
// 	 * won't contain anything particularly useful, but the response headers will contain
// 	 * the latest session and security (CSRF) tokens, meaning that subsequent POST requests
// 	 * can work.
// 	 */
// 	@Override
// 	public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
// 		response.sendRedirect("/api/account");
// 	}
// }


// Path: src/main/java/com/pugnascotia/reactdemo/config/SecurityConfig.java
import javax.inject.Inject;
import com.pugnascotia.reactdemo.config.ajax.AjaxAuthenticationSuccessHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.csrf.CsrfFilter;
import org.springframework.security.web.csrf.CsrfTokenRepository;
import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository;
import com.pugnascotia.reactdemo.config.ajax.AjaxAuthenticationFailureHandler;
import com.pugnascotia.reactdemo.config.ajax.AjaxLogoutSuccessHandler;

package com.pugnascotia.reactdemo.config;



@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

	@Inject
	private AjaxAuthenticationSuccessHandler authSuccessHandler;

	@Inject
	private AjaxAuthenticationFailureHandler authFailureHandler;

	@Inject
	private AjaxLogoutSuccessHandler logoutSuccessHandler;