Well, Iโd just want to add my class just because in the future some kind of developer may appear who wants to connect to the Netbackup server (or something like that) and do something from Java, ignoring the SSL certificate. This worked for me, and we use Windows Active Directory to authenticate with the Netbackup server.
public static void main(String[] args) throws Exception { SSLContext sslcontext = null; try { sslcontext = SSLContext.getInstance("TLS"); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex); } try { sslcontext.init(null, new TrustManager[]{new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } @Override public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }}, new java.security.SecureRandom()); } catch (KeyManagementException ex) { Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex); } //HttpAuthenticationFeature feature = HttpAuthenticationFeature.basicBuilder().credentials(username, password).build(); ClientConfig clientConfig = new ClientConfig(); //clientConfig.register(feature); Client client = ClientBuilder.newBuilder().withConfig(clientConfig) .sslContext(sslcontext) .hostnameVerifier((s1, s2) -> true) .build(); //String the_url = "https://the_server:1556/netbackup/security/cacert"; String the_token; { String the_url = "https://the_server:1556/netbackup/login"; WebTarget webTarget = client.target(the_url); Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON); String jsonString = new JSONObject() .put("domainType", "NT") .put("domainName", "XX") .put("userName", "the username") .put("password", "the password").toString(); System.out.println(jsonString); Response response = invocationBuilder.post(Entity.json(jsonString)); String data = response.readEntity(String.class); JSONObject jo = new JSONObject(data); the_token = jo.getString("token"); System.out.println("token is:" + the_token); } { String the_url = "https://the_server:1556/netbackup/admin/jobs/1122012"; //job id 1122012 is an example WebTarget webTarget = client.target(the_url); Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, the_token).header(HttpHeaders.ACCEPT, "application/vnd.netbackup+json;version=1.0"); Response response = invocationBuilder.get(); System.out.println("response status:" + response.getStatus()); String data = response.readEntity(String.class); //JSONObject jo = new JSONObject(data); System.out.println(data); } }
I know that this can be considered off-topic, but I'm sure that a developer who is trying to connect to the Netbackup server is likely to be here. By the way, many thanks to all the answers to this question! The specification I'm talking about is here, and there is no Java example in their code examples (currently).
*** This, of course, is not safe, because we ignore the certificate!
xtsoler Apr 03 '19 at 7:16 2019-04-03 07:16
source share