package com.braintree.security.handler;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.RedirectStrategy;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static com.braintree.controllers.BraintreeaddonControllerConstants.PREPARATION_FOR_LINK_PAYPAL_ACCOUNT;

public class BraintreeConnectWithPayPalSecurityLayerSuccessHandler implements AuthenticationSuccessHandler {

    private RedirectStrategy redirectStrategy;

    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, PREPARATION_FOR_LINK_PAYPAL_ACCOUNT);
    }

    public void setRedirectStrategy(RedirectStrategy redirectStrategy) {
        this.redirectStrategy = redirectStrategy;
    }
}
