簡體   English   中英

通過Java在Jenkins上進行用戶身份驗證

[英]User Authentication on Jenkins through java

我正在使用jenkins並直接訪問url。

例如。 http://jenkins.local:8080/job/path_to_file/config.xml

它曾經給我一個xml輸出。

不是jenkins具有用戶登錄功能。 因此,訪問相同的URL使我進入登錄頁面。 如何在Jenkins上進行用戶身份驗證?

我檢查了api,但沒有任何暗示。

您可以使用以下方法:

public InputStream processPostRequest(String requestUrl) {

    DefaultHttpClient client = null;

    client = createHttpClient("admin", "pas");

    HttpEntity entity = null;

    BasicHttpContext context = null;
    context = createHttpContext();

    client.addRequestInterceptor(new HttpRequestInterceptor(), 0);
    HttpGet get = new HttpGet(requestUrl);

    try {

        // Execute your request with the given context
        HttpResponse response = client.execute(get, context);
        entity = response.getEntity();

    } catch (IOException e) {
        e.printStackTrace();
    }

    return entity..getContent();
}

其中requestUrl是url + config.xml。 HttpRequestInterceptor是一個接口,因此您必須創建自己的擴展它的類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM