SSLCertificateService { public ResponseEntity<String> authenticate(CertManagerLoginRequest certManagerLoginRequest) throws Exception { String certManagerAPIEndpoint = "/auth/certmanager/login"; log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "CertManager Login with User name"). put(LogMessage.MESSAGE, String.format("Trying to authenticate with CertManager with user name = [%s]" ,certManagerLoginRequest.getUsername())). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); CertResponse response = reqProcessor.processCert(certManagerAPIEndpoint, certManagerLoginRequest, "", getCertmanagerEndPoint(tokenGenerator)); if (HttpStatus.OK.equals(response.getHttpstatus())) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, SSLCertificateConstants.CUSTOMER_LOGIN). put(LogMessage.MESSAGE, "CertManager Authentication Successful"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, SSLCertificateConstants.CUSTOMER_LOGIN). put(LogMessage.MESSAGE, "CertManager Authentication failed."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\":[\"CertManager Login Failed.\"]}" + "HTTP STATUSCODE :" + response.getHttpstatus()); } }  ResponseEntity<String> authenticate(CertManagerLoginRequest certManagerLoginRequest); CertManagerLogin login(CertManagerLoginRequest certManagerLoginRequest); ResponseEntity<String> generateSSLCertificate(SSLCertificateRequest sslCertificateRequest,
                                                               UserDetails userDetails ,String token); ResponseEntity<String> getServiceCertificates(String token, UserDetails userDetails, String certName, Integer limit, Integer offset, String certType); String getNclmToken(); ResponseEntity<String> getTargetSystemList(String token, UserDetails userDetails,String certType); ResponseEntity<String> getTargetSystemServiceList(String token, UserDetails userDetails, String targetSystemId); ResponseEntity<String> getRevocationReasons(Integer certificateId, String token); ResponseEntity<String> issueRevocationRequest(String certType, String certificateName, UserDetails userDetails, String token,
			RevocationRequest revocationRequest); String getCurrentLocalDateTimeStamp(); Boolean validateOwnerPermissionForNonAdmin(UserDetails userDetails, String certificateName); ResponseEntity<String> addUserToCertificate(CertificateUser certificateUser, UserDetails userDetails, boolean addSudoPermission); ResponseEntity<String> addGroupToCertificate(UserDetails userDetails, String userToken, CertificateGroup certificateGroup); boolean isAuthorized(UserDetails userDetails, String certificatename, String certType); ResponseEntity<String> addingGroupToCertificate(String token, CertificateGroup certificateGroup, UserDetails userDetails); ResponseEntity<String> associateApproletoCertificate(CertificateApprole certificateApprole, UserDetails userDetails); boolean hasDownloadPermission(String certificateName, UserDetails userDetails, String certType); SSLCertificateMetadataDetails getCertificateMetadata(String token, String certificateName); ResponseEntity<InputStreamResource> downloadCertificateWithPrivateKey(String token, CertificateDownloadRequest certificateDownloadRequest, UserDetails userDetails); ResponseEntity<InputStreamResource> downloadCertificateWithPrivateKey(CertificateDownloadRequest certificateDownloadRequest, SSLCertificateMetadataDetails sslCertificateMetadataDetails); ResponseEntity<InputStreamResource> downloadCertificate(String token, UserDetails userDetails,
                                                                   String certificateName, String certificateType,
                                                                   String sslCertType); ResponseEntity<String> getCertificateDetails(String token, String certificateName, String certificateType); ResponseEntity<String> renewCertificate(String certType, String certificateName, UserDetails userDetails, String token); ResponseEntity<String> removeUserFromCertificate(CertificateUser certificateUser, UserDetails userDetails); ResponseEntity<String> removeGroupFromCertificate(CertificateGroup certificateGroup, UserDetails userDetails); ResponseEntity<String> getListOfCertificates(String token, String certificateType); ResponseEntity<String> updateCertOwner(String token, String certType,String certName,String certOwnerEmailId,  UserDetails userDetails); ResponseEntity<String> validateApprovalStatusAndGetCertificateDetails(String certName, String certType,
			UserDetails userDetails); ResponseEntity<String> deleteCertificate( String token, String certType, String certificateName, UserDetails userDetails); Boolean validateCertOwnerPermissionForNonAdmin(UserDetails userDetails, String certificateName, String certType); ResponseEntity<String> getAllCertificates(String token, String certName, Integer limit, Integer offset); ResponseEntity<String> getAllCertificatesOnCertType(UserDetails userDetails, String certificateType); ResponseEntity<String> checkCertificateStatus(String certName, String certType,	
			UserDetails userDetails); ResponseEntity<String> getAllSelfServiceGroups(UserDetails userDetails); ResponseEntity<String> removeGroupFromCertificateForDelete(CertificateGroup certificateGroup, UserDetails userDetails); @Value("${sslcertmanager.targetsystemgroup.public_single_san.ts_gp_id}")
    private int public_single_san_ts_gp_id; @Value("${sslcertmanager.targetsystemgroup.public_multi_san.ts_gp_id}")
    private int public_multi_san_ts_gp_id; }
@Test public void test_authenticate_success() throws Exception { String jsonStr = "{ \"username\": \"testusername\", \"password\": \"testpassword\"}"; CertResponse response = new CertResponse(); response.setHttpstatus(HttpStatus.OK); response.setResponse("Success"); response.setSuccess(true); CertManagerLoginRequest certManagerLoginRequest = new CertManagerLoginRequest("testusername", "testpassword"); when(JSONUtil.getJSON(Mockito.any())).thenReturn(jsonStr); when(reqProcessor.processCert(Mockito.anyString(), Mockito.anyObject(), Mockito.anyString(), Mockito.anyString())).thenReturn(response); ResponseEntity<String> responseEntity = sSLCertificateService.authenticate(certManagerLoginRequest); assertEquals(HttpStatus.OK,responseEntity.getStatusCode()); }
@Test public void test_authenticate_Unauthorized() throws Exception { String jsonStr = "{ \"username\": \"testusername1\", \"password\": \"testpassword1\"}"; CertResponse response = new CertResponse(); response.setHttpstatus(HttpStatus.UNAUTHORIZED); response.setResponse("Success"); response.setSuccess(true); CertManagerLoginRequest certManagerLoginRequest = new CertManagerLoginRequest("testusername", "testpassword"); when(JSONUtil.getJSON(Mockito.any())).thenReturn(jsonStr); when(reqProcessor.processCert(Mockito.anyString(), Mockito.anyObject(), Mockito.anyString(), Mockito.anyString())).thenReturn(response); ResponseEntity<String> responseEntity = sSLCertificateService.authenticate(certManagerLoginRequest); assertEquals(HttpStatus.UNAUTHORIZED,responseEntity.getStatusCode()); }