tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/SSLCertificateService.java
private String authenticatePacbot(String clientid,String clientsecret) throws Exception {
		        String certManagerAPIEndpoint = pacbotGetTokenEndpoint;
		        JsonParser jsonParser = new JsonParser();
		        String encoding = Base64.getEncoder().encodeToString((clientid+":"+clientsecret).getBytes());
		        
		        		String authHeader = "Basic " + new String(encoding);
		        		String responseStr = "";
		        		String bearerToken="";    
		        
		        HttpClient httpClient;
		        try {
		            httpClient = HttpClientBuilder.create().setSSLHostnameVerifier(
		                    NoopHostnameVerifier.INSTANCE).
		                    setSSLContext(
		                            new SSLContextBuilder().loadTrustMaterial(null,new TrustStrategy() {
		                                @Override
		                                public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
		                                    return true;
		                                }
		                            }).build()
		                    ).setRedirectStrategy(new LaxRedirectStrategy()).build();
		        } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e1) {
		            log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
		                    put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
		                    put(LogMessage.ACTION, SSLCertificateConstants.ONBOARD_SSL_CERTIFICATE).
		                    put(LogMessage.MESSAGE, "Failed to get certificates. Failed to create hhtpClient").
		                    put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
		                    build()));
		            return null;
		        }
				try {
					HttpPost postRequest = new HttpPost(certManagerAPIEndpoint);
				        postRequest.addHeader(HttpHeaders.AUTHORIZATION, authHeader);         
				               
				        HttpResponse apiResponse = httpClient.execute(postRequest);

			            if (apiResponse.getStatusLine().getStatusCode() != 200) {
			                return null;
			            }	            
			            responseStr =  EntityUtils.toString(apiResponse.getEntity());	          
				} catch (Exception e) {
					log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
		                    put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
		                    put(LogMessage.ACTION, "authenticatePacbot").
		                    put(LogMessage.MESSAGE,"Pacbot authentication failed.").
		                    put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
		                    build()));
		            return null;
				}
				JsonObject res = jsonParser.parse(responseStr).getAsJsonObject();
		        if(!ObjectUtils.isEmpty(res)) {
		        	bearerToken = res.get("access_token").getAsString();
		        	log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
		                    put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
		                    put(LogMessage.ACTION, "authenticatePacbot").
		                    put(LogMessage.MESSAGE,"Pacbot authentication successful.").
		                    put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
		                    build()));
		        }
		            return bearerToken;
		        
		    }
/**
			 * Login to pacbot to get bearer token
			 * @param clientid
			 * @param clientsecret
			 * @return
			 * @throws Exception
			 */
Login to pacbot to get bearer token
@param clientid
@param clientsecret
@return
@throws Exception
Login to pacbot to get bearer token @param clientid @param clientsecret @return @throws Exception
private String authenticatePacbot(String clientid,String clientsecret) throws Exception {
		        String certManagerAPIEndpoint = pacbotGetTokenEndpoint;
		        JsonParser jsonParser = new JsonParser();
		        String encoding = Base64.getEncoder().encodeToString((clientid+":"+clientsecret).getBytes());
		        		String authHeader = "Basic " + new String(encoding);
		        		String responseStr = "";
		        		String bearerToken="";    
		        HttpClient httpClient;
		        try {
		            httpClient = HttpClientBuilder.create().setSSLHostnameVerifier(
		                    NoopHostnameVerifier.INSTANCE).
		                    setSSLContext(
		                            new SSLContextBuilder().loadTrustMaterial(null,new TrustStrategy() {
		                                @Override
		                                public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
		                                    return true;
		                                }
		                            }).build()
		                    ).setRedirectStrategy(new LaxRedirectStrategy()).build();
		        } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e1) {
		            log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
		                    put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
		                    put(LogMessage.ACTION, SSLCertificateConstants.ONBOARD_SSL_CERTIFICATE).
		                    put(LogMessage.MESSAGE, "Failed to get certificates. Failed to create hhtpClient").
		                    put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
		                    build()));
		            return null;
		        }
				try {
					HttpPost postRequest = new HttpPost(certManagerAPIEndpoint);
				        postRequest.addHeader(HttpHeaders.AUTHORIZATION, authHeader);         
				        HttpResponse apiResponse = httpClient.execute(postRequest);
			            if (apiResponse.getStatusLine().getStatusCode() != 200) {
			                return null;
			            }	            
			            responseStr =  EntityUtils.toString(apiResponse.getEntity());	          
				} catch (Exception e) {
					log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
		                    put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
		                    put(LogMessage.ACTION, "authenticatePacbot").
		                    put(LogMessage.MESSAGE,"Pacbot authentication failed.").
		                    put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
		                    build()));
		            return null;
				}
				JsonObject res = jsonParser.parse(responseStr).getAsJsonObject();
		        if(!ObjectUtils.isEmpty(res)) {
		        	bearerToken = res.get("access_token").getAsString();
		        	log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
		                    put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
		                    put(LogMessage.ACTION, "authenticatePacbot").
		                    put(LogMessage.MESSAGE,"Pacbot authentication successful.").
		                    put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
		                    build()));
		        }
		            return bearerToken;
		    }
private String authenticatePacbot ( String clientid , String clientsecret ) throws Exception { String certManagerAPIEndpoint = pacbotGetTokenEndpoint ; JsonParser jsonParser = new JsonParser ( ) ; String encoding = Base64 . getEncoder ( ) . encodeToString ( ( clientid + ":" + clientsecret ) . getBytes ( ) ) ; String authHeader = "Basic " + new String ( encoding ) ; String responseStr = "" ; String bearerToken = "" ; HttpClient httpClient ; try { httpClient = HttpClientBuilder . create ( ) . setSSLHostnameVerifier ( NoopHostnameVerifier . INSTANCE ) . setSSLContext ( new SSLContextBuilder ( ) . loadTrustMaterial ( null , new TrustStrategy ( ) { @ Override public boolean isTrusted ( X509Certificate [ ] arg0 , String arg1 ) throws CertificateException { return true ; } } ) . build ( ) ) . setRedirectStrategy ( new LaxRedirectStrategy ( ) ) . build ( ) ; } catch ( KeyManagementException | NoSuchAlgorithmException | KeyStoreException e1 ) { log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . ONBOARD_SSL_CERTIFICATE ) . put ( LogMessage . MESSAGE , "Failed to get certificates. Failed to create hhtpClient" ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return null ; } try { HttpPost postRequest = new HttpPost ( certManagerAPIEndpoint ) ; postRequest . addHeader ( HttpHeaders . AUTHORIZATION , authHeader ) ; HttpResponse apiResponse = httpClient . execute ( postRequest ) ; if ( apiResponse . getStatusLine ( ) . getStatusCode ( ) != 200 ) { return null ; } responseStr = EntityUtils . toString ( apiResponse . getEntity ( ) ) ; } catch ( Exception e ) { log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "authenticatePacbot" ) . put ( LogMessage . MESSAGE , "Pacbot authentication failed." ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return null ; } JsonObject res = jsonParser . parse ( responseStr ) . getAsJsonObject ( ) ; if ( ! ObjectUtils . isEmpty ( res ) ) { bearerToken = res . get ( "access_token" ) . getAsString ( ) ; log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "authenticatePacbot" ) . put ( LogMessage . MESSAGE , "Pacbot authentication successful." ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; } return bearerToken ; }
Login to pacbot to get bearer token
 @param clientid
 @param clientsecret
 @return
 @throws Exception
Login to pacbot to get bearer token @param clientid @param clientsecret @return @throws Exception