I don't know if this is the best practice. But for now I solved it that way:
public class AuthStatus {
public RestAccess rest_access;
public static class RestAccess {
public long access_key;
}
}
@ClientHeaderParam(name = "Content-Type", value = "application/json")
@ClientHeaderParam(name = "Accept", value = "application/json")
@ClientHeaderParam(name = "Authorization", value = "{lookupAuth}")
public interface HttpBinService {
@POST
@Path("/rest_access")
AuthStatus getAuthenticatedUser(String body);
default String lookupAuth() {
return "Basic " + Base64.getEncoder().encodeToString("user:passwd".getBytes());
}
}
public class CheckRequestFilter implements ClientRequestFilter {
private static final Logger LOG = Logger.getLogger(CheckRequestFilter.class);
private static final String HTTP_BIN_URL = "http://{myID}:8050/caisd-rest/";
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
try {
HttpBinService service = RestClientBuilder.newBuilder().baseUri(new URI(HTTP_BIN_URL)).build(HttpBinService.class);
StringBuilder json = new StringBuilder();
json.append("{");
json.append("\"rest_access\":\"\"");
json.append("}");
AuthStatus auth = service.getAuthenticatedUser(json.toString());
requestContext.getHeaders().add("X-AccessKey", auth.rest_access.access_key);
} catch (Exception e) {
LOG.error(e);
}
}
}
@Path("/caisd-rest")
@RegisterRestClient
@RegisterProvider(value = CheckRequestFilter.class)
@ClientHeaderParam(name = "Content-Type", value = "application/json")
@ClientHeaderParam(name = "Accept", value = "application/json")
public interface RdmService {
@POST
@Path("/chg")
MyObjetct create(String jsonBody);