@Test public void test_getAllCertificatesOnCertType_successfully() { String certificateType = "internal"; UserDetails userDetails = new UserDetails(); userDetails.setUsername("normaluser"); userDetails.setAdmin(false); userDetails.setClientToken(token); userDetails.setSelfSupportToken(token); String [] policies = {"r_users_s1", "w_users_s2", "r_shared_s3", "w_shared_s4", "r_apps_s5", "w_apps_s6", "d_apps_s7", "w_svcacct_test", "w_cert_certtest.t-mobile.com"}; ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"shared\":[{\"s3\":\"read\"},{\"s4\":\"write\"}],\"users\":[{\"s1\":\"read\"},{\"s2\":\"write\"}],\"cert\":[{\"certtest.t-mobile.com\":\"read\"}],\"apps\":[{\"s5\":\"read\"},{\"s6\":\"write\"},{\"s7\":\"deny\"}]}"); when(policyUtils.getCurrentPolicies(token, userDetails.getUsername(), userDetails)).thenReturn(policies); when(JSONUtil.getJSON(Mockito.any())).thenReturn("{\"shared\":[{\"s3\":\"read\"},{\"s4\":\"write\"}],\"users\":[{\"s1\":\"read\"},{\"s2\":\"write\"}],\"cert\":[{\"certtest.t-mobile.com\":\"read\"}],\"apps\":[{\"s5\":\"read\"},{\"s6\":\"write\"},{\"s7\":\"deny\"}]}"); ResponseEntity<String> responseEntity = sSLCertificateService.getAllCertificatesOnCertType(userDetails, certificateType); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
public ResponseEntity<String> getAllCertificatesOnCertType(UserDetails userDetails, String certificateType) { oidcUtil.renewUserToken(userDetails.getClientToken()); String token = userDetails.getSelfSupportToken(); if (userDetails.isAdmin()) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JSONUtil.getJSON(null)); } String certificatePrefix = TVaultConstants.CERT_POLICY_PREFIX; if (certificateType.equals(SSLCertificateConstants.EXTERNAL)) { certificatePrefix = TVaultConstants.CERT_POLICY_EXTERNAL_PREFIX; } String[] policies = policyUtils.getCurrentPolicies(token, userDetails.getUsername(), userDetails); policies = filterPoliciesBasedOnPrecedence(Arrays.asList(policies)); List<Map<String, String>> certListUsers = new ArrayList<>(); Map<String, List<Map<String, String>>> safeList = new HashMap<>(); if (policies != null) { for (String policy : policies) { Map<String, String> safePolicy = new HashMap<>(); String[] _policies = policy.split("_", -1); if (_policies.length >= 3) { String[] policyName = Arrays.copyOfRange(_policies, 2, _policies.length); String safeName = String.join("_", policyName); String safeType = _policies[1]; if (policy.startsWith("r_")) { safePolicy.put(safeName, "read"); } else if (policy.startsWith("w_")) { safePolicy.put(safeName, "write"); } else if (policy.startsWith("d_")) { safePolicy.put(safeName, "deny"); } if (!safePolicy.isEmpty()) { if (safeType.equals(certificatePrefix)) { certListUsers.add(safePolicy); } } } } safeList.put(certificatePrefix, certListUsers); } return ResponseEntity.status(HttpStatus.OK).body(JSONUtil.getJSON(safeList)); }
SSLCertificateService { public ResponseEntity<String> getAllCertificatesOnCertType(UserDetails userDetails, String certificateType) { oidcUtil.renewUserToken(userDetails.getClientToken()); String token = userDetails.getSelfSupportToken(); if (userDetails.isAdmin()) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JSONUtil.getJSON(null)); } String certificatePrefix = TVaultConstants.CERT_POLICY_PREFIX; if (certificateType.equals(SSLCertificateConstants.EXTERNAL)) { certificatePrefix = TVaultConstants.CERT_POLICY_EXTERNAL_PREFIX; } String[] policies = policyUtils.getCurrentPolicies(token, userDetails.getUsername(), userDetails); policies = filterPoliciesBasedOnPrecedence(Arrays.asList(policies)); List<Map<String, String>> certListUsers = new ArrayList<>(); Map<String, List<Map<String, String>>> safeList = new HashMap<>(); if (policies != null) { for (String policy : policies) { Map<String, String> safePolicy = new HashMap<>(); String[] _policies = policy.split("_", -1); if (_policies.length >= 3) { String[] policyName = Arrays.copyOfRange(_policies, 2, _policies.length); String safeName = String.join("_", policyName); String safeType = _policies[1]; if (policy.startsWith("r_")) { safePolicy.put(safeName, "read"); } else if (policy.startsWith("w_")) { safePolicy.put(safeName, "write"); } else if (policy.startsWith("d_")) { safePolicy.put(safeName, "deny"); } if (!safePolicy.isEmpty()) { if (safeType.equals(certificatePrefix)) { certListUsers.add(safePolicy); } } } } safeList.put(certificatePrefix, certListUsers); } return ResponseEntity.status(HttpStatus.OK).body(JSONUtil.getJSON(safeList)); } }
SSLCertificateService { public ResponseEntity<String> getAllCertificatesOnCertType(UserDetails userDetails, String certificateType) { oidcUtil.renewUserToken(userDetails.getClientToken()); String token = userDetails.getSelfSupportToken(); if (userDetails.isAdmin()) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JSONUtil.getJSON(null)); } String certificatePrefix = TVaultConstants.CERT_POLICY_PREFIX; if (certificateType.equals(SSLCertificateConstants.EXTERNAL)) { certificatePrefix = TVaultConstants.CERT_POLICY_EXTERNAL_PREFIX; } String[] policies = policyUtils.getCurrentPolicies(token, userDetails.getUsername(), userDetails); policies = filterPoliciesBasedOnPrecedence(Arrays.asList(policies)); List<Map<String, String>> certListUsers = new ArrayList<>(); Map<String, List<Map<String, String>>> safeList = new HashMap<>(); if (policies != null) { for (String policy : policies) { Map<String, String> safePolicy = new HashMap<>(); String[] _policies = policy.split("_", -1); if (_policies.length >= 3) { String[] policyName = Arrays.copyOfRange(_policies, 2, _policies.length); String safeName = String.join("_", policyName); String safeType = _policies[1]; if (policy.startsWith("r_")) { safePolicy.put(safeName, "read"); } else if (policy.startsWith("w_")) { safePolicy.put(safeName, "write"); } else if (policy.startsWith("d_")) { safePolicy.put(safeName, "deny"); } if (!safePolicy.isEmpty()) { if (safeType.equals(certificatePrefix)) { certListUsers.add(safePolicy); } } } } safeList.put(certificatePrefix, certListUsers); } return ResponseEntity.status(HttpStatus.OK).body(JSONUtil.getJSON(safeList)); }  }
SSLCertificateService { public ResponseEntity<String> getAllCertificatesOnCertType(UserDetails userDetails, String certificateType) { oidcUtil.renewUserToken(userDetails.getClientToken()); String token = userDetails.getSelfSupportToken(); if (userDetails.isAdmin()) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JSONUtil.getJSON(null)); } String certificatePrefix = TVaultConstants.CERT_POLICY_PREFIX; if (certificateType.equals(SSLCertificateConstants.EXTERNAL)) { certificatePrefix = TVaultConstants.CERT_POLICY_EXTERNAL_PREFIX; } String[] policies = policyUtils.getCurrentPolicies(token, userDetails.getUsername(), userDetails); policies = filterPoliciesBasedOnPrecedence(Arrays.asList(policies)); List<Map<String, String>> certListUsers = new ArrayList<>(); Map<String, List<Map<String, String>>> safeList = new HashMap<>(); if (policies != null) { for (String policy : policies) { Map<String, String> safePolicy = new HashMap<>(); String[] _policies = policy.split("_", -1); if (_policies.length >= 3) { String[] policyName = Arrays.copyOfRange(_policies, 2, _policies.length); String safeName = String.join("_", policyName); String safeType = _policies[1]; if (policy.startsWith("r_")) { safePolicy.put(safeName, "read"); } else if (policy.startsWith("w_")) { safePolicy.put(safeName, "write"); } else if (policy.startsWith("d_")) { safePolicy.put(safeName, "deny"); } if (!safePolicy.isEmpty()) { if (safeType.equals(certificatePrefix)) { certListUsers.add(safePolicy); } } } } safeList.put(certificatePrefix, certListUsers); } return ResponseEntity.status(HttpStatus.OK).body(JSONUtil.getJSON(safeList)); }  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); }
SSLCertificateService { public ResponseEntity<String> getAllCertificatesOnCertType(UserDetails userDetails, String certificateType) { oidcUtil.renewUserToken(userDetails.getClientToken()); String token = userDetails.getSelfSupportToken(); if (userDetails.isAdmin()) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JSONUtil.getJSON(null)); } String certificatePrefix = TVaultConstants.CERT_POLICY_PREFIX; if (certificateType.equals(SSLCertificateConstants.EXTERNAL)) { certificatePrefix = TVaultConstants.CERT_POLICY_EXTERNAL_PREFIX; } String[] policies = policyUtils.getCurrentPolicies(token, userDetails.getUsername(), userDetails); policies = filterPoliciesBasedOnPrecedence(Arrays.asList(policies)); List<Map<String, String>> certListUsers = new ArrayList<>(); Map<String, List<Map<String, String>>> safeList = new HashMap<>(); if (policies != null) { for (String policy : policies) { Map<String, String> safePolicy = new HashMap<>(); String[] _policies = policy.split("_", -1); if (_policies.length >= 3) { String[] policyName = Arrays.copyOfRange(_policies, 2, _policies.length); String safeName = String.join("_", policyName); String safeType = _policies[1]; if (policy.startsWith("r_")) { safePolicy.put(safeName, "read"); } else if (policy.startsWith("w_")) { safePolicy.put(safeName, "write"); } else if (policy.startsWith("d_")) { safePolicy.put(safeName, "deny"); } if (!safePolicy.isEmpty()) { if (safeType.equals(certificatePrefix)) { certListUsers.add(safePolicy); } } } } safeList.put(certificatePrefix, certListUsers); } return ResponseEntity.status(HttpStatus.OK).body(JSONUtil.getJSON(safeList)); }  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; }