How can you authenticate using the Jersey Client against a JAAS enabled web-server?

前端 未结 5 981
攒了一身酷
攒了一身酷 2020-12-28 09:39

I have the following scenario:

Server: Jetty (with configured JAAS)

Client: Jersey invoked via JUnit (via Maven)

I have JAAS set up in the web server

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-28 10:10

    Autorization for JAAS:

        String URL_DATA = "http://localhost:9080/foo/auth.html";
        Client client = Client.create();
    
        String username = "me";
        String password = "me";
    
        client.addFilter(new HTTPBasicAuthFilter(username, password));
    
        // Get the protected web page:
        WebResource webResource = client.resource(URL_DATA);
        String response = webResource.get(String.class);
        System.out.println(response);
    

提交回复
热议问题