tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/IAMServiceAccountsService.java
private void updateApprolePolicyAssociationOnIAMSvcaccDelete(String iamSvcAccountName,
																 Map<String, String> acessInfo, String token) {
		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
				.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
				.put(LogMessage.ACTION, "updateApprolePolicyAssociationOnIAMSvcaccDelete")
				.put(LogMessage.MESSAGE, String.format("trying to update approle policies on IAM service account " +
						"delete for [%s]", iamSvcAccountName))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		if (acessInfo != null) {
			String readPolicy = new StringBuffer()
					.append(TVaultConstants.SVC_ACC_POLICIES_PREFIXES.getKey(TVaultConstants.READ_POLICY))
					.append(IAMServiceAccountConstants.IAMSVCACC_POLICY_PREFIX).append(iamSvcAccountName).toString();
			String writePolicy = new StringBuffer()
					.append(TVaultConstants.SVC_ACC_POLICIES_PREFIXES.getKey(TVaultConstants.WRITE_POLICY))
					.append(IAMServiceAccountConstants.IAMSVCACC_POLICY_PREFIX).append(iamSvcAccountName).toString();
			String denyPolicy = new StringBuffer()
					.append(TVaultConstants.SVC_ACC_POLICIES_PREFIXES.getKey(TVaultConstants.DENY_POLICY))
					.append(IAMServiceAccountConstants.IAMSVCACC_POLICY_PREFIX).append(iamSvcAccountName).toString();
			String sudoPolicy = new StringBuffer()
					.append(TVaultConstants.SVC_ACC_POLICIES_PREFIXES.getKey(TVaultConstants.SUDO_POLICY))
					.append(IAMServiceAccountConstants.IAMSVCACC_POLICY_PREFIX).append(iamSvcAccountName).toString();
			Set<String> approles = acessInfo.keySet();
			ObjectMapper objMapper = new ObjectMapper();
			for (String approleName : approles) {
				Response roleResponse = reqProcessor.process("/auth/approle/role/read",
						"{\"role_name\":\"" + approleName + "\"}", token);
				String responseJson = "";
				List<String> policies = new ArrayList<>();
				List<String> currentpolicies = new ArrayList<>();
				if (HttpStatus.OK.equals(roleResponse.getHttpstatus())) {
					responseJson = roleResponse.getResponse();
					try {
						JsonNode policiesArry = objMapper.readTree(responseJson).get("data").get("policies");
						if (null != policiesArry) {
							for (JsonNode policyNode : policiesArry) {
								currentpolicies.add(policyNode.asText());
							}
						}
					} catch (IOException e) {
						log.error(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
								.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
								.put(LogMessage.ACTION, "updateApprolePolicyAssociationOnIAMSvcaccDelete")
								.put(LogMessage.MESSAGE, String.format("%s, Approle removal as part of offboarding " +
												"Service account failed.", approleName))
								.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL))
								.build()));
					}
					policies.addAll(currentpolicies);
					policies.remove(readPolicy);
					policies.remove(writePolicy);
					policies.remove(denyPolicy);
					policies.remove(sudoPolicy);

					String policiesString = org.apache.commons.lang3.StringUtils.join(policies, ",");
					log.info( JSONUtil.getJSON(ImmutableMap.<String, String> builder()
									.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
									.put(LogMessage.ACTION, "updateApprolePolicyAssociationOnIAMSvcaccDelete")
									.put(LogMessage.MESSAGE, "Current policies :" + policiesString + " is being configured")
									.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL))
									.build()));
					appRoleService.configureApprole(approleName, policiesString, token);
				}
			}
		}
	}
/**
	 * Approle policy update as part of offboarding
	 *
	 * @param iamSvcAccountName
	 * @param acessInfo
	 * @param token
	 */
Approle policy update as part of offboarding
@param iamSvcAccountName
@param acessInfo
@param token
Approle policy update as part of offboarding @param iamSvcAccountName @param acessInfo @param token
private void updateApprolePolicyAssociationOnIAMSvcaccDelete(String iamSvcAccountName,
																 Map<String, String> acessInfo, String token) {
		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
				.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
				.put(LogMessage.ACTION, "updateApprolePolicyAssociationOnIAMSvcaccDelete")
				.put(LogMessage.MESSAGE, String.format("trying to update approle policies on IAM service account " +
						"delete for [%s]", iamSvcAccountName))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		if (acessInfo != null) {
			String readPolicy = new StringBuffer()
					.append(TVaultConstants.SVC_ACC_POLICIES_PREFIXES.getKey(TVaultConstants.READ_POLICY))
					.append(IAMServiceAccountConstants.IAMSVCACC_POLICY_PREFIX).append(iamSvcAccountName).toString();
			String writePolicy = new StringBuffer()
					.append(TVaultConstants.SVC_ACC_POLICIES_PREFIXES.getKey(TVaultConstants.WRITE_POLICY))
					.append(IAMServiceAccountConstants.IAMSVCACC_POLICY_PREFIX).append(iamSvcAccountName).toString();
			String denyPolicy = new StringBuffer()
					.append(TVaultConstants.SVC_ACC_POLICIES_PREFIXES.getKey(TVaultConstants.DENY_POLICY))
					.append(IAMServiceAccountConstants.IAMSVCACC_POLICY_PREFIX).append(iamSvcAccountName).toString();
			String sudoPolicy = new StringBuffer()
					.append(TVaultConstants.SVC_ACC_POLICIES_PREFIXES.getKey(TVaultConstants.SUDO_POLICY))
					.append(IAMServiceAccountConstants.IAMSVCACC_POLICY_PREFIX).append(iamSvcAccountName).toString();
			Set<String> approles = acessInfo.keySet();
			ObjectMapper objMapper = new ObjectMapper();
			for (String approleName : approles) {
				Response roleResponse = reqProcessor.process("/auth/approle/role/read",
						"{\"role_name\":\"" + approleName + "\"}", token);
				String responseJson = "";
				List<String> policies = new ArrayList<>();
				List<String> currentpolicies = new ArrayList<>();
				if (HttpStatus.OK.equals(roleResponse.getHttpstatus())) {
					responseJson = roleResponse.getResponse();
					try {
						JsonNode policiesArry = objMapper.readTree(responseJson).get("data").get("policies");
						if (null != policiesArry) {
							for (JsonNode policyNode : policiesArry) {
								currentpolicies.add(policyNode.asText());
							}
						}
					} catch (IOException e) {
						log.error(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
								.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
								.put(LogMessage.ACTION, "updateApprolePolicyAssociationOnIAMSvcaccDelete")
								.put(LogMessage.MESSAGE, String.format("%s, Approle removal as part of offboarding " +
												"Service account failed.", approleName))
								.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL))
								.build()));
					}
					policies.addAll(currentpolicies);
					policies.remove(readPolicy);
					policies.remove(writePolicy);
					policies.remove(denyPolicy);
					policies.remove(sudoPolicy);
					String policiesString = org.apache.commons.lang3.StringUtils.join(policies, ",");
					log.info( JSONUtil.getJSON(ImmutableMap.<String, String> builder()
									.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
									.put(LogMessage.ACTION, "updateApprolePolicyAssociationOnIAMSvcaccDelete")
									.put(LogMessage.MESSAGE, "Current policies :" + policiesString + " is being configured")
									.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL))
									.build()));
					appRoleService.configureApprole(approleName, policiesString, token);
				}
			}
		}
	}
private void updateApprolePolicyAssociationOnIAMSvcaccDelete ( String iamSvcAccountName , Map < String , String > acessInfo , String token ) { log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "updateApprolePolicyAssociationOnIAMSvcaccDelete" ) . put ( LogMessage . MESSAGE , String . format ( "trying to update approle policies on IAM service account " + "delete for [%s]" , iamSvcAccountName ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; if ( acessInfo != null ) { String readPolicy = new StringBuffer ( ) . append ( TVaultConstants . SVC_ACC_POLICIES_PREFIXES . getKey ( TVaultConstants . READ_POLICY ) ) . append ( IAMServiceAccountConstants . IAMSVCACC_POLICY_PREFIX ) . append ( iamSvcAccountName ) . toString ( ) ; String writePolicy = new StringBuffer ( ) . append ( TVaultConstants . SVC_ACC_POLICIES_PREFIXES . getKey ( TVaultConstants . WRITE_POLICY ) ) . append ( IAMServiceAccountConstants . IAMSVCACC_POLICY_PREFIX ) . append ( iamSvcAccountName ) . toString ( ) ; String denyPolicy = new StringBuffer ( ) . append ( TVaultConstants . SVC_ACC_POLICIES_PREFIXES . getKey ( TVaultConstants . DENY_POLICY ) ) . append ( IAMServiceAccountConstants . IAMSVCACC_POLICY_PREFIX ) . append ( iamSvcAccountName ) . toString ( ) ; String sudoPolicy = new StringBuffer ( ) . append ( TVaultConstants . SVC_ACC_POLICIES_PREFIXES . getKey ( TVaultConstants . SUDO_POLICY ) ) . append ( IAMServiceAccountConstants . IAMSVCACC_POLICY_PREFIX ) . append ( iamSvcAccountName ) . toString ( ) ; Set < String > approles = acessInfo . keySet ( ) ; ObjectMapper objMapper = new ObjectMapper ( ) ; for ( String approleName : approles ) { Response roleResponse = reqProcessor . process ( "/auth/approle/role/read" , "{\"role_name\":\"" + approleName + "\"}" , token ) ; String responseJson = "" ; List < String > policies = new ArrayList < > ( ) ; List < String > currentpolicies = new ArrayList < > ( ) ; if ( HttpStatus . OK . equals ( roleResponse . getHttpstatus ( ) ) ) { responseJson = roleResponse . getResponse ( ) ; try { JsonNode policiesArry = objMapper . readTree ( responseJson ) . get ( "data" ) . get ( "policies" ) ; if ( null != policiesArry ) { for ( JsonNode policyNode : policiesArry ) { currentpolicies . add ( policyNode . asText ( ) ) ; } } } catch ( IOException e ) { log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "updateApprolePolicyAssociationOnIAMSvcaccDelete" ) . put ( LogMessage . MESSAGE , String . format ( "%s, Approle removal as part of offboarding " + "Service account failed." , approleName ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; } policies . addAll ( currentpolicies ) ; policies . remove ( readPolicy ) ; policies . remove ( writePolicy ) ; policies . remove ( denyPolicy ) ; policies . remove ( sudoPolicy ) ; String policiesString = org . apache . commons . lang3 . StringUtils . join ( policies , "," ) ; log . info ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "updateApprolePolicyAssociationOnIAMSvcaccDelete" ) . put ( LogMessage . MESSAGE , "Current policies :" + policiesString + " is being configured" ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; appRoleService . configureApprole ( approleName , policiesString , token ) ; } } } }
Approle policy update as part of offboarding
 @param iamSvcAccountName
 @param acessInfo
 @param token
Approle policy update as part of offboarding @param iamSvcAccountName @param acessInfo @param token