package pwc.taxtech.atms;
import java.util.Arrays;
import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.test.util.ReflectionTestUtils;
import pwc.taxtech.atms.security.JwtAuthenticationProvider;
import pwc.taxtech.atms.security.JwtAuthenticationToken;
import pwc.taxtech.atms.security.JwtUtil;
public abstract class CommonTestUtils {
public static void initTestAuth() {
Authentication request = new JwtAuthenticationToken("xxxx");
JwtAuthenticationProvider jwtAuthenticationProvider = new JwtAuthenticationProvider();
JwtUtil jwtutil = new JwtUtil();
jwtutil.setJwtBase64Secret("testkey");
jwtutil.setJwtPowerToken("xxxx");
ReflectionTestUtils.setField(jwtAuthenticationProvider, "jwtUtil", jwtutil);
ProviderManager providerManager = new ProviderManager(Arrays.asList(jwtAuthenticationProvider));
Authentication authenticaiton = providerManager.authenticate(request);
SecurityContextHolder.getContext().setAuthentication(authenticaiton);
}
}