мне кажется ты уходишь от нашей структуры, напомню тебе еще раз ее
допиши AuthClient
.
├── AuthClient.java
├── AuthConfiguration.java
├── AuthExeption.java
├── AuthService.java
├── CertificateLoader.java
└── CookieHolder.java
public class AuthClient {
public String authorize() {
KeyStore keyStore = CertificateLoader.load();
//TODO
Response response = (Response) RestAssured
.given()
//.config()
.get(AuthConfiguration.AUTH_URL);
String cookie = response.headers().toString();
if (cookie == null) {
throw new AuthExeption("Cookie is null", null);
}
return cookie;
}
}
public class AuthService {
private final AuthClient authClient = new AuthClient();
private final CookieHolder holder = new CookieHolder();
public String getCookie() {
if (holder.isEmpty()) {
synchronized (this) {
if (holder.isEmpty()) {
holder.set(authClient.authorize());
}
}
}
return holder.get();
}
public void refresh() {
holder.set(authClient.authorize());
}
}
public class CertificateLoader {
private CertificateLoader () {}
public static KeyStore load() {
try(InputStream is = Files.newInputStream(
Paths.get(AuthConfiguration.CERTIFICATE_PATH))) {
KeyStore keyStore = KeyStore.getInstance("PKS12");
keyStore.load(is, AuthConfiguration.CERTIFICATE_PASSWORD.toCharArray());
return keyStore;
} catch (Exception e) {
throw new AuthExeption("Не могу загрузить сертификат, ошибка: ", e);
}
}
}
public class CookieHolder {
private volatile String cookie;
public String get() {
return cookie;
}
public void set(String cookie) {
this.cookie = cookie;
}
public boolean isEmpty() {
return cookie == null || cookie.isBlank();
}
public void clear() {
cookie = null;
}
}