tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/IAMServiceAccountsService.java
private void updateGroupPolicyAssociationOnIAMSvcaccDelete(String iamSvcAccountName, Map<String, String> acessInfo,
															   String token, UserDetails userDetails) {
		OIDCGroup oidcGroup = new OIDCGroup();
		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
				.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
				.put(LogMessage.ACTION, "updateGroupPolicyAssociationOnIAMSvcaccDelete")
				.put(LogMessage.MESSAGE, String.format("trying to delete group policies on IAM service account delete " +
						"for [%s]", iamSvcAccountName))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		if (TVaultConstants.USERPASS.equals(vaultAuthMethod)) {
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
					.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
					.put(LogMessage.ACTION, "updateGroupPolicyAssociationOnIAMSvcaccDelete")
					.put(LogMessage.MESSAGE, "Inside userpass of updateGroupPolicyAssociationOnIAMSvcaccDelete...Just Returning...")
					.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			return;
		}
		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> groups = acessInfo.keySet();
			ObjectMapper objMapper = new ObjectMapper();
			for (String groupName : groups) {
				Response response = new Response();
				if (TVaultConstants.LDAP.equals(vaultAuthMethod)) {
					response = reqProcessor.process(GROUPPATH, GROUPNAME + groupName + "\"}",
							token);
				} else if (TVaultConstants.OIDC.equals(vaultAuthMethod)) {
					// call read api with groupname
					oidcGroup = oidcUtil.getIdentityGroupDetails(groupName, token);
					if (oidcGroup != null) {
						response.setHttpstatus(HttpStatus.OK);
						response.setResponse(oidcGroup.getPolicies().toString());
					} else {
						response.setHttpstatus(HttpStatus.BAD_REQUEST);
					}
				}

				String responseJson = TVaultConstants.EMPTY;
				List<String> policies = new ArrayList<>();
				List<String> currentpolicies = new ArrayList<>();
				if (HttpStatus.OK.equals(response.getHttpstatus())) {
					responseJson = response.getResponse();
					try {
						// OIDC Changes
						if (TVaultConstants.LDAP.equals(vaultAuthMethod)) {
							currentpolicies = ControllerUtil.getPoliciesAsListFromJson(objMapper, responseJson);
						} else if (TVaultConstants.OIDC.equals(vaultAuthMethod) && oidcGroup != null) {
							currentpolicies.addAll(oidcGroup.getPolicies());
						}
					} catch (IOException e) {
						log.error(e);
						log.error(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
								.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
								.put(LogMessage.ACTION, "updateGroupPolicyAssociationOnIAMSvcaccDelete")
								.put(LogMessage.MESSAGE, String.format("updateGroupPolicyAssociationOnIAMSvcaccDelete " +
												"failed [%s]", e.getMessage()))
								.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.debug(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
							.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
							.put(LogMessage.ACTION, "updateGroupPolicyAssociationOnIAMSvcaccDelete")
							.put(LogMessage.MESSAGE, String.format("Current policies [%s]", policies))
							.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL))
							.build()));
					if (TVaultConstants.LDAP.equals(vaultAuthMethod)) {
						ControllerUtil.configureLDAPGroup(groupName, policiesString, token);
					} else if (TVaultConstants.OIDC.equals(vaultAuthMethod)) {
						oidcUtil.updateGroupPolicies(token, groupName, policies, currentpolicies, oidcGroup != null ? oidcGroup.getId() : null);
						oidcUtil.renewUserToken(userDetails.getClientToken());
					}
				}
			}
		}
	}
/**
	 * Update Group policy on IAM Service account offboarding
	 *
	 * @param iamSvcAccountName
	 * @param acessInfo
	 * @param token
	 * @param userDetails
	 */
Update Group policy on IAM Service account offboarding
@param iamSvcAccountName
@param acessInfo
@param token
@param userDetails
Update Group policy on IAM Service account offboarding @param iamSvcAccountName @param acessInfo @param token @param userDetails
private void updateGroupPolicyAssociationOnIAMSvcaccDelete(String iamSvcAccountName, Map<String, String> acessInfo,
															   String token, UserDetails userDetails) {
		OIDCGroup oidcGroup = new OIDCGroup();
		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
				.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
				.put(LogMessage.ACTION, "updateGroupPolicyAssociationOnIAMSvcaccDelete")
				.put(LogMessage.MESSAGE, String.format("trying to delete group policies on IAM service account delete " +
						"for [%s]", iamSvcAccountName))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		if (TVaultConstants.USERPASS.equals(vaultAuthMethod)) {
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
					.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
					.put(LogMessage.ACTION, "updateGroupPolicyAssociationOnIAMSvcaccDelete")
					.put(LogMessage.MESSAGE, "Inside userpass of updateGroupPolicyAssociationOnIAMSvcaccDelete...Just Returning...")
					.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			return;
		}
		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> groups = acessInfo.keySet();
			ObjectMapper objMapper = new ObjectMapper();
			for (String groupName : groups) {
				Response response = new Response();
				if (TVaultConstants.LDAP.equals(vaultAuthMethod)) {
					response = reqProcessor.process(GROUPPATH, GROUPNAME + groupName + "\"}",
							token);
				} else if (TVaultConstants.OIDC.equals(vaultAuthMethod)) {
					oidcGroup = oidcUtil.getIdentityGroupDetails(groupName, token);
					if (oidcGroup != null) {
						response.setHttpstatus(HttpStatus.OK);
						response.setResponse(oidcGroup.getPolicies().toString());
					} else {
						response.setHttpstatus(HttpStatus.BAD_REQUEST);
					}
				}
				String responseJson = TVaultConstants.EMPTY;
				List<String> policies = new ArrayList<>();
				List<String> currentpolicies = new ArrayList<>();
				if (HttpStatus.OK.equals(response.getHttpstatus())) {
					responseJson = response.getResponse();
					try {
						if (TVaultConstants.LDAP.equals(vaultAuthMethod)) {
							currentpolicies = ControllerUtil.getPoliciesAsListFromJson(objMapper, responseJson);
						} else if (TVaultConstants.OIDC.equals(vaultAuthMethod) && oidcGroup != null) {
							currentpolicies.addAll(oidcGroup.getPolicies());
						}
					} catch (IOException e) {
						log.error(e);
						log.error(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
								.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
								.put(LogMessage.ACTION, "updateGroupPolicyAssociationOnIAMSvcaccDelete")
								.put(LogMessage.MESSAGE, String.format("updateGroupPolicyAssociationOnIAMSvcaccDelete " +
												"failed [%s]", e.getMessage()))
								.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.debug(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
							.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
							.put(LogMessage.ACTION, "updateGroupPolicyAssociationOnIAMSvcaccDelete")
							.put(LogMessage.MESSAGE, String.format("Current policies [%s]", policies))
							.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL))
							.build()));
					if (TVaultConstants.LDAP.equals(vaultAuthMethod)) {
						ControllerUtil.configureLDAPGroup(groupName, policiesString, token);
					} else if (TVaultConstants.OIDC.equals(vaultAuthMethod)) {
						oidcUtil.updateGroupPolicies(token, groupName, policies, currentpolicies, oidcGroup != null ? oidcGroup.getId() : null);
						oidcUtil.renewUserToken(userDetails.getClientToken());
					}
				}
			}
		}
	}
private void updateGroupPolicyAssociationOnIAMSvcaccDelete ( String iamSvcAccountName , Map < String , String > acessInfo , String token , UserDetails userDetails ) { OIDCGroup oidcGroup = new OIDCGroup ( ) ; log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "updateGroupPolicyAssociationOnIAMSvcaccDelete" ) . put ( LogMessage . MESSAGE , String . format ( "trying to delete group policies on IAM service account delete " + "for [%s]" , iamSvcAccountName ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; if ( TVaultConstants . USERPASS . equals ( vaultAuthMethod ) ) { log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "updateGroupPolicyAssociationOnIAMSvcaccDelete" ) . put ( LogMessage . MESSAGE , "Inside userpass of updateGroupPolicyAssociationOnIAMSvcaccDelete...Just Returning..." ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return ; } 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 > groups = acessInfo . keySet ( ) ; ObjectMapper objMapper = new ObjectMapper ( ) ; for ( String groupName : groups ) { Response response = new Response ( ) ; if ( TVaultConstants . LDAP . equals ( vaultAuthMethod ) ) { response = reqProcessor . process ( GROUPPATH , GROUPNAME + groupName + "\"}" , token ) ; } else if ( TVaultConstants . OIDC . equals ( vaultAuthMethod ) ) { oidcGroup = oidcUtil . getIdentityGroupDetails ( groupName , token ) ; if ( oidcGroup != null ) { response . setHttpstatus ( HttpStatus . OK ) ; response . setResponse ( oidcGroup . getPolicies ( ) . toString ( ) ) ; } else { response . setHttpstatus ( HttpStatus . BAD_REQUEST ) ; } } String responseJson = TVaultConstants . EMPTY ; List < String > policies = new ArrayList < > ( ) ; List < String > currentpolicies = new ArrayList < > ( ) ; if ( HttpStatus . OK . equals ( response . getHttpstatus ( ) ) ) { responseJson = response . getResponse ( ) ; try { if ( TVaultConstants . LDAP . equals ( vaultAuthMethod ) ) { currentpolicies = ControllerUtil . getPoliciesAsListFromJson ( objMapper , responseJson ) ; } else if ( TVaultConstants . OIDC . equals ( vaultAuthMethod ) && oidcGroup != null ) { currentpolicies . addAll ( oidcGroup . getPolicies ( ) ) ; } } catch ( IOException e ) { log . error ( e ) ; log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "updateGroupPolicyAssociationOnIAMSvcaccDelete" ) . put ( LogMessage . MESSAGE , String . format ( "updateGroupPolicyAssociationOnIAMSvcaccDelete " + "failed [%s]" , e . getMessage ( ) ) ) . 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 . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "updateGroupPolicyAssociationOnIAMSvcaccDelete" ) . put ( LogMessage . MESSAGE , String . format ( "Current policies [%s]" , policies ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; if ( TVaultConstants . LDAP . equals ( vaultAuthMethod ) ) { ControllerUtil . configureLDAPGroup ( groupName , policiesString , token ) ; } else if ( TVaultConstants . OIDC . equals ( vaultAuthMethod ) ) { oidcUtil . updateGroupPolicies ( token , groupName , policies , currentpolicies , oidcGroup != null ? oidcGroup . getId ( ) : null ) ; oidcUtil . renewUserToken ( userDetails . getClientToken ( ) ) ; } } } } }
Update Group policy on IAM Service account offboarding
 @param iamSvcAccountName
 @param acessInfo
 @param token
 @param userDetails
Update Group policy on IAM Service account offboarding @param iamSvcAccountName @param acessInfo @param token @param userDetails
// call read api with groupname // OIDC Changes