簡體   English   中英

如何使用Jersey作為Rest客戶端連接Ambari以進行授權

[英]How to use Jersey as Rest client to connect Ambari for Authorization

我試圖使用Jersey使其他客戶端連接Ambari服務器。 但是,使用過濾器無法完成授權。

除了過濾器,還有其他授權方式嗎?

我嘗試的情況如下:

ClientConfig clientConfig =新的DefaultClientConfig();

        clientConfig.getFeatures().put(
                JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);

        Client client = Client.create(clientConfig);

        client.addFilter(new ClientFilter() {
            private ArrayList<Object> cookies;

            @Override
            public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
                if (cookies != null) {
                    request.getHeaders().put("Cookie", cookies);
                }
                ClientResponse response = getNext().handle(request);
                // copy cookies
                if (response.getCookies() != null) {
                    if (cookies == null) {
                        cookies = new ArrayList<Object>();
                    }
                    // A simple addAll just for illustration (should probably check for duplicates and expired cookies)
                    cookies.addAll(response.getCookies());
                }
                return response;
            }
        });

        String username = "admin";
        String password = "admin";

        WebResource webResource = client.resource("http://master.node.ibm.com:8080/api/v1/clusters");

        Form form = new Form();
        form.putSingle("Username", username);
        form.putSingle("Password", password);
        webResource.type("application/json").post(form);

        ClientResponse response = webResource.accept("application/json").type("application/json").get(ClientResponse.class);

您正在嘗試使用憑據發布表單-這不是您想要的。 對於標准的基本身份驗證(與curl -u username:password ),您應該

webResource.addFilter(new HTTPBasicAuthFilter(username, password));

暫無
暫無

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

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