我正在尝试通过Java从我们的jenkins安装程序中获取工作信息。 我们的jenkins实例使用gitlab身份验证插件。
我的Java代码如下:
public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException {
HttpRequest request = HttpRequest.newBuilder(new URI(URL))
.GET()
.build();
HttpResponse<String> response = HttpClient.newBuilder()
.authenticator(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
USERNAME,
PASSWORD.toCharArray());
}})
.build()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
结果如下:
You are authenticated as: anonymous
Groups that you are in:
Permission you need to have (but didn't): hudson.model.Hudson.Read
... which is implied by: hudson.security.Permission.GenericRead
... which is implied by: hudson.model.Hudson.Administer
-->
我同时使用了所用帐户的密码进行了尝试,并在gitlab中创建了一个我试图使用其代替密码的个人访问令牌。这两个选项都返回上面看到的相同结果。
如何在这种情况下正确验证身份?