@Test public void test_getOnboardedServiceAccounts_admin_notfound() { UserDetails userDetails = getMockUser(true); String token = userDetails.getClientToken(); String expectedOutput = "{\"keys\":[]}"; Response onboardedSvsAccsResponse = getMockResponse(HttpStatus.NOT_FOUND, true, expectedOutput); when(reqProcessor.process("/ad/serviceaccount/onboardedlist","{}",token)).thenReturn(onboardedSvsAccsResponse); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body(expectedOutput); ResponseEntity<String> responseEntity = serviceAccountsService.getOnboardedServiceAccounts(token, userDetails); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
public ResponseEntity<String> getOnboardedServiceAccounts(String token, UserDetails userDetails) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "listOnboardedServiceAccounts"). put(LogMessage.MESSAGE, String.format("Trying to get list of onboaded service accounts")). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = null; if (userDetails.isAdmin()) { response = reqProcessor.process("/ad/serviceaccount/onboardedlist","{}",token); } else { String[] latestPolicies = policyUtils.getCurrentPolicies(userDetails.getSelfSupportToken(), userDetails.getUsername(), userDetails); List<String> onboardedlist = new ArrayList<>(); for (String policy: latestPolicies) { if (policy.startsWith("o_svcacct")) { onboardedlist.add(policy.substring(10)); } } response = new Response(); response.setHttpstatus(HttpStatus.OK); response.setSuccess(true); response.setResponse("{\"keys\":"+JSONUtil.getJSON(onboardedlist)+"}"); } 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, "listOnboardedServiceAccounts"). put(LogMessage.MESSAGE, "Successfully retrieved the list of Service Accounts"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else if (HttpStatus.NOT_FOUND.equals(response.getHttpstatus())) { return ResponseEntity.status(HttpStatus.OK).body("{\"keys\":[]}"); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }
ServiceAccountsService { public ResponseEntity<String> getOnboardedServiceAccounts(String token, UserDetails userDetails) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "listOnboardedServiceAccounts"). put(LogMessage.MESSAGE, String.format("Trying to get list of onboaded service accounts")). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = null; if (userDetails.isAdmin()) { response = reqProcessor.process("/ad/serviceaccount/onboardedlist","{}",token); } else { String[] latestPolicies = policyUtils.getCurrentPolicies(userDetails.getSelfSupportToken(), userDetails.getUsername(), userDetails); List<String> onboardedlist = new ArrayList<>(); for (String policy: latestPolicies) { if (policy.startsWith("o_svcacct")) { onboardedlist.add(policy.substring(10)); } } response = new Response(); response.setHttpstatus(HttpStatus.OK); response.setSuccess(true); response.setResponse("{\"keys\":"+JSONUtil.getJSON(onboardedlist)+"}"); } 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, "listOnboardedServiceAccounts"). put(LogMessage.MESSAGE, "Successfully retrieved the list of Service Accounts"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else if (HttpStatus.NOT_FOUND.equals(response.getHttpstatus())) { return ResponseEntity.status(HttpStatus.OK).body("{\"keys\":[]}"); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } }
ServiceAccountsService { public ResponseEntity<String> getOnboardedServiceAccounts(String token, UserDetails userDetails) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "listOnboardedServiceAccounts"). put(LogMessage.MESSAGE, String.format("Trying to get list of onboaded service accounts")). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = null; if (userDetails.isAdmin()) { response = reqProcessor.process("/ad/serviceaccount/onboardedlist","{}",token); } else { String[] latestPolicies = policyUtils.getCurrentPolicies(userDetails.getSelfSupportToken(), userDetails.getUsername(), userDetails); List<String> onboardedlist = new ArrayList<>(); for (String policy: latestPolicies) { if (policy.startsWith("o_svcacct")) { onboardedlist.add(policy.substring(10)); } } response = new Response(); response.setHttpstatus(HttpStatus.OK); response.setSuccess(true); response.setResponse("{\"keys\":"+JSONUtil.getJSON(onboardedlist)+"}"); } 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, "listOnboardedServiceAccounts"). put(LogMessage.MESSAGE, "Successfully retrieved the list of Service Accounts"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else if (HttpStatus.NOT_FOUND.equals(response.getHttpstatus())) { return ResponseEntity.status(HttpStatus.OK).body("{\"keys\":[]}"); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }  }
ServiceAccountsService { public ResponseEntity<String> getOnboardedServiceAccounts(String token, UserDetails userDetails) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "listOnboardedServiceAccounts"). put(LogMessage.MESSAGE, String.format("Trying to get list of onboaded service accounts")). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = null; if (userDetails.isAdmin()) { response = reqProcessor.process("/ad/serviceaccount/onboardedlist","{}",token); } else { String[] latestPolicies = policyUtils.getCurrentPolicies(userDetails.getSelfSupportToken(), userDetails.getUsername(), userDetails); List<String> onboardedlist = new ArrayList<>(); for (String policy: latestPolicies) { if (policy.startsWith("o_svcacct")) { onboardedlist.add(policy.substring(10)); } } response = new Response(); response.setHttpstatus(HttpStatus.OK); response.setSuccess(true); response.setResponse("{\"keys\":"+JSONUtil.getJSON(onboardedlist)+"}"); } 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, "listOnboardedServiceAccounts"). put(LogMessage.MESSAGE, "Successfully retrieved the list of Service Accounts"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else if (HttpStatus.NOT_FOUND.equals(response.getHttpstatus())) { return ResponseEntity.status(HttpStatus.OK).body("{\"keys\":[]}"); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }  ResponseEntity<ADServiceAccountObjects> getADServiceAccounts(String token, UserDetails userDetails, String UserPrincipalName, boolean excludeOnboarded); ResponseEntity<String> onboardServiceAccount(String token, ServiceAccount serviceAccount, UserDetails userDetails); ResponseEntity<String> offboardServiceAccount(String token, OnboardedServiceAccount serviceAccount, UserDetails userDetails); ResponseEntity<String> addUserToServiceAccount(String token, ServiceAccountUser serviceAccountUser, UserDetails userDetails, boolean isPartOfSvcAccOnboard); ResponseEntity<String> removeUserFromServiceAccount(String token, ServiceAccountUser serviceAccountUser, UserDetails userDetails); ResponseEntity<String> resetSvcAccPassword(String token, String svcAccName, UserDetails userDetails); ResponseEntity<String> readSvcAccPassword(String token, String svcAccName, UserDetails userDetails); ResponseEntity<String> getOnboarderdServiceAccount(String token, String svcAccName, UserDetails userDetails); boolean canAddOrRemoveUser(UserDetails userDetails, ServiceAccountUser serviceAccountUser, String action); ResponseEntity<String> getOnboardedServiceAccounts(String token,  UserDetails userDetails); boolean hasAddOrRemovePermission(UserDetails userDetails, String serviceAccount, String token); boolean hasAddUserPermission(UserDetails userDetails, String serviceAccount, String token, boolean isPartOfSvcAccOnboard); static boolean isSvcaccPermissionInputValid(String access); ResponseEntity<String> addGroupToServiceAccount(String token, ServiceAccountGroup serviceAccountGroup, UserDetails userDetails); ResponseEntity<String> removeGroupFromServiceAccount(String token, ServiceAccountGroup serviceAccountGroup, UserDetails userDetails); ResponseEntity<String> associateApproletoSvcAcc(UserDetails userDetails, String token, ServiceAccountApprole serviceAccountApprole); ResponseEntity<String> getServiceAccountMeta(String token, UserDetails userDetails, String path); ResponseEntity<String> removeApproleFromSvcAcc(UserDetails userDetails, String token, ServiceAccountApprole serviceAccountApprole); ResponseEntity<String> addAwsRoleToSvcacc(UserDetails userDetails, String token, ServiceAccountAWSRole serviceAccountAWSRole); ResponseEntity<String> removeAWSRoleFromSvcacc(UserDetails userDetails, String token, ServiceAccountAWSRole serviceAccountAWSRole); ResponseEntity<String> createAWSRole(UserDetails userDetails, String token, AWSLoginRole awsLoginRole); ResponseEntity<String> createIAMRole(UserDetails userDetails, String token, AWSIAMRole awsiamRole); ResponseEntity<String> updateOnboardedServiceAccount(String token, ServiceAccount serviceAccount, UserDetails userDetails); ResponseEntity<String> transferSvcAccountOwner(UserDetails userDetails, String token, String svcAccName); ResponseEntity<String> getServiceAccounts(UserDetails userDetails, String userToken); }
ServiceAccountsService { public ResponseEntity<String> getOnboardedServiceAccounts(String token, UserDetails userDetails) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "listOnboardedServiceAccounts"). put(LogMessage.MESSAGE, String.format("Trying to get list of onboaded service accounts")). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = null; if (userDetails.isAdmin()) { response = reqProcessor.process("/ad/serviceaccount/onboardedlist","{}",token); } else { String[] latestPolicies = policyUtils.getCurrentPolicies(userDetails.getSelfSupportToken(), userDetails.getUsername(), userDetails); List<String> onboardedlist = new ArrayList<>(); for (String policy: latestPolicies) { if (policy.startsWith("o_svcacct")) { onboardedlist.add(policy.substring(10)); } } response = new Response(); response.setHttpstatus(HttpStatus.OK); response.setSuccess(true); response.setResponse("{\"keys\":"+JSONUtil.getJSON(onboardedlist)+"}"); } 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, "listOnboardedServiceAccounts"). put(LogMessage.MESSAGE, "Successfully retrieved the list of Service Accounts"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else if (HttpStatus.NOT_FOUND.equals(response.getHttpstatus())) { return ResponseEntity.status(HttpStatus.OK).body("{\"keys\":[]}"); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }  ResponseEntity<ADServiceAccountObjects> getADServiceAccounts(String token, UserDetails userDetails, String UserPrincipalName, boolean excludeOnboarded); ResponseEntity<String> onboardServiceAccount(String token, ServiceAccount serviceAccount, UserDetails userDetails); ResponseEntity<String> offboardServiceAccount(String token, OnboardedServiceAccount serviceAccount, UserDetails userDetails); ResponseEntity<String> addUserToServiceAccount(String token, ServiceAccountUser serviceAccountUser, UserDetails userDetails, boolean isPartOfSvcAccOnboard); ResponseEntity<String> removeUserFromServiceAccount(String token, ServiceAccountUser serviceAccountUser, UserDetails userDetails); ResponseEntity<String> resetSvcAccPassword(String token, String svcAccName, UserDetails userDetails); ResponseEntity<String> readSvcAccPassword(String token, String svcAccName, UserDetails userDetails); ResponseEntity<String> getOnboarderdServiceAccount(String token, String svcAccName, UserDetails userDetails); boolean canAddOrRemoveUser(UserDetails userDetails, ServiceAccountUser serviceAccountUser, String action); ResponseEntity<String> getOnboardedServiceAccounts(String token,  UserDetails userDetails); boolean hasAddOrRemovePermission(UserDetails userDetails, String serviceAccount, String token); boolean hasAddUserPermission(UserDetails userDetails, String serviceAccount, String token, boolean isPartOfSvcAccOnboard); static boolean isSvcaccPermissionInputValid(String access); ResponseEntity<String> addGroupToServiceAccount(String token, ServiceAccountGroup serviceAccountGroup, UserDetails userDetails); ResponseEntity<String> removeGroupFromServiceAccount(String token, ServiceAccountGroup serviceAccountGroup, UserDetails userDetails); ResponseEntity<String> associateApproletoSvcAcc(UserDetails userDetails, String token, ServiceAccountApprole serviceAccountApprole); ResponseEntity<String> getServiceAccountMeta(String token, UserDetails userDetails, String path); ResponseEntity<String> removeApproleFromSvcAcc(UserDetails userDetails, String token, ServiceAccountApprole serviceAccountApprole); ResponseEntity<String> addAwsRoleToSvcacc(UserDetails userDetails, String token, ServiceAccountAWSRole serviceAccountAWSRole); ResponseEntity<String> removeAWSRoleFromSvcacc(UserDetails userDetails, String token, ServiceAccountAWSRole serviceAccountAWSRole); ResponseEntity<String> createAWSRole(UserDetails userDetails, String token, AWSLoginRole awsLoginRole); ResponseEntity<String> createIAMRole(UserDetails userDetails, String token, AWSIAMRole awsiamRole); ResponseEntity<String> updateOnboardedServiceAccount(String token, ServiceAccount serviceAccount, UserDetails userDetails); ResponseEntity<String> transferSvcAccountOwner(UserDetails userDetails, String token, String svcAccName); ResponseEntity<String> getServiceAccounts(UserDetails userDetails, String userToken);  }