tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/IAMServiceAccountsService.java
private ResponseEntity<String> processAndAddGroupPoliciesToIAMSvcAcc(String token, UserDetails userDetails,
			OIDCGroup oidcGroup, IAMServiceAccountGroup iamServiceAccountGroup, String iamSvcAccountName) {
		List<String> policies = new ArrayList<>();
		List<String> currentpolicies = new ArrayList<>();
		String policy = new StringBuffer()
				.append(TVaultConstants.SVC_ACC_POLICIES_PREFIXES.getKey(iamServiceAccountGroup.getAccess()))
				.append(IAMServiceAccountConstants.IAMSVCACC_POLICY_PREFIX).append(iamSvcAccountName).toString();

		processNewGroupPolicy(token, policy, iamSvcAccountName, oidcGroup, iamServiceAccountGroup, policies, currentpolicies);

		ResponseEntity<String> configureGroupResponse = configureGroup(token, userDetails, oidcGroup, iamServiceAccountGroup,
				policies, currentpolicies);

		if (configureGroupResponse.getStatusCode().equals(HttpStatus.NO_CONTENT) ||
				configureGroupResponse.getStatusCode().equals(HttpStatus.OK)) {
			log.info(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
					.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
					.put(LogMessage.ACTION, IAMServiceAccountConstants.ADD_GROUP_TO_IAMSVCACC_MSG)
					.put(LogMessage.MESSAGE, String.format("Successfully added policy [%s] to group [%s]",
							policy, iamServiceAccountGroup.getGroupname()))
					.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));

			Response updateMetadataResponse = updateMetadata(token, iamSvcAccountName, IAMServiceAccountConstants.IAM_GROUP_MSG_STRING,
					iamServiceAccountGroup.getGroupname(), iamServiceAccountGroup.getAccess());

			if (updateMetadataResponse.getHttpstatus().equals(HttpStatus.NO_CONTENT) ||
					updateMetadataResponse.getHttpstatus().equals(HttpStatus.OK)) {
				log.info(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
						.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
						.put(LogMessage.ACTION, IAMServiceAccountConstants.ADD_GROUP_TO_IAMSVCACC_MSG)
						.put(LogMessage.MESSAGE, String.format("Successfully updated metadata for group [%s]", iamServiceAccountGroup.getGroupname()))
						.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			} else {
				log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
						.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
						.put(LogMessage.ACTION, IAMServiceAccountConstants.ADD_GROUP_TO_IAMSVCACC_MSG)
						.put(LogMessage.MESSAGE, String.format("Failed to update metadata for group [%s]", iamServiceAccountGroup.getGroupname()))
						.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
				String currentpoliciesString = org.apache.commons.lang3.StringUtils.join(currentpolicies, ",");

				return revertGroupPermissionForIAMSvcAcc(token, userDetails, oidcGroup,
						iamServiceAccountGroup.getGroupname(), currentpolicies, currentpoliciesString,
						updateMetadataResponse);
			}
		} else {
			log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
					.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
					.put(LogMessage.ACTION, IAMServiceAccountConstants.ADD_GROUP_TO_IAMSVCACC_MSG)
					.put(LogMessage.MESSAGE, String.format("Failed to configure group policies for group [%s]", iamServiceAccountGroup.getGroupname()))
					.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
					.body(String.format("{\"errors\":[\"Unable to update group policies for group %s\"]}", iamServiceAccountGroup.getGroupname()));
		}

		return ResponseEntity.status(HttpStatus.OK)
				.body("{\"messages\":[\"Group is successfully associated with IAM Service Account\"]}");
	}
/**
	 * Method to create policies for add group to IAM service account and call the update process.
	 * @param token
	 * @param userDetails
	 * @param oidcGroup
	 * @param iamServiceAccountGroup
	 * @param iamSvcAccountName
	 * @return
	 */
Method to create policies for add group to IAM service account and call the update process.
Method to create policies for add group to IAM service account and call the update process .
private ResponseEntity<String> processAndAddGroupPoliciesToIAMSvcAcc(String token, UserDetails userDetails,
			OIDCGroup oidcGroup, IAMServiceAccountGroup iamServiceAccountGroup, String iamSvcAccountName) {
		List<String> policies = new ArrayList<>();
		List<String> currentpolicies = new ArrayList<>();
		String policy = new StringBuffer()
				.append(TVaultConstants.SVC_ACC_POLICIES_PREFIXES.getKey(iamServiceAccountGroup.getAccess()))
				.append(IAMServiceAccountConstants.IAMSVCACC_POLICY_PREFIX).append(iamSvcAccountName).toString();
		processNewGroupPolicy(token, policy, iamSvcAccountName, oidcGroup, iamServiceAccountGroup, policies, currentpolicies);
		ResponseEntity<String> configureGroupResponse = configureGroup(token, userDetails, oidcGroup, iamServiceAccountGroup,
				policies, currentpolicies);
		if (configureGroupResponse.getStatusCode().equals(HttpStatus.NO_CONTENT) ||
				configureGroupResponse.getStatusCode().equals(HttpStatus.OK)) {
			log.info(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
					.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
					.put(LogMessage.ACTION, IAMServiceAccountConstants.ADD_GROUP_TO_IAMSVCACC_MSG)
					.put(LogMessage.MESSAGE, String.format("Successfully added policy [%s] to group [%s]",
							policy, iamServiceAccountGroup.getGroupname()))
					.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			Response updateMetadataResponse = updateMetadata(token, iamSvcAccountName, IAMServiceAccountConstants.IAM_GROUP_MSG_STRING,
					iamServiceAccountGroup.getGroupname(), iamServiceAccountGroup.getAccess());
			if (updateMetadataResponse.getHttpstatus().equals(HttpStatus.NO_CONTENT) ||
					updateMetadataResponse.getHttpstatus().equals(HttpStatus.OK)) {
				log.info(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
						.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
						.put(LogMessage.ACTION, IAMServiceAccountConstants.ADD_GROUP_TO_IAMSVCACC_MSG)
						.put(LogMessage.MESSAGE, String.format("Successfully updated metadata for group [%s]", iamServiceAccountGroup.getGroupname()))
						.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			} else {
				log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
						.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
						.put(LogMessage.ACTION, IAMServiceAccountConstants.ADD_GROUP_TO_IAMSVCACC_MSG)
						.put(LogMessage.MESSAGE, String.format("Failed to update metadata for group [%s]", iamServiceAccountGroup.getGroupname()))
						.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
				String currentpoliciesString = org.apache.commons.lang3.StringUtils.join(currentpolicies, ",");
				return revertGroupPermissionForIAMSvcAcc(token, userDetails, oidcGroup,
						iamServiceAccountGroup.getGroupname(), currentpolicies, currentpoliciesString,
						updateMetadataResponse);
			}
		} else {
			log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
					.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
					.put(LogMessage.ACTION, IAMServiceAccountConstants.ADD_GROUP_TO_IAMSVCACC_MSG)
					.put(LogMessage.MESSAGE, String.format("Failed to configure group policies for group [%s]", iamServiceAccountGroup.getGroupname()))
					.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
					.body(String.format("{\"errors\":[\"Unable to update group policies for group %s\"]}", iamServiceAccountGroup.getGroupname()));
		}
		return ResponseEntity.status(HttpStatus.OK)
				.body("{\"messages\":[\"Group is successfully associated with IAM Service Account\"]}");
	}
private ResponseEntity < String > processAndAddGroupPoliciesToIAMSvcAcc ( String token , UserDetails userDetails , OIDCGroup oidcGroup , IAMServiceAccountGroup iamServiceAccountGroup , String iamSvcAccountName ) { List < String > policies = new ArrayList < > ( ) ; List < String > currentpolicies = new ArrayList < > ( ) ; String policy = new StringBuffer ( ) . append ( TVaultConstants . SVC_ACC_POLICIES_PREFIXES . getKey ( iamServiceAccountGroup . getAccess ( ) ) ) . append ( IAMServiceAccountConstants . IAMSVCACC_POLICY_PREFIX ) . append ( iamSvcAccountName ) . toString ( ) ; processNewGroupPolicy ( token , policy , iamSvcAccountName , oidcGroup , iamServiceAccountGroup , policies , currentpolicies ) ; ResponseEntity < String > configureGroupResponse = configureGroup ( token , userDetails , oidcGroup , iamServiceAccountGroup , policies , currentpolicies ) ; if ( configureGroupResponse . getStatusCode ( ) . equals ( HttpStatus . NO_CONTENT ) || configureGroupResponse . getStatusCode ( ) . equals ( HttpStatus . OK ) ) { log . info ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , IAMServiceAccountConstants . ADD_GROUP_TO_IAMSVCACC_MSG ) . put ( LogMessage . MESSAGE , String . format ( "Successfully added policy [%s] to group [%s]" , policy , iamServiceAccountGroup . getGroupname ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; Response updateMetadataResponse = updateMetadata ( token , iamSvcAccountName , IAMServiceAccountConstants . IAM_GROUP_MSG_STRING , iamServiceAccountGroup . getGroupname ( ) , iamServiceAccountGroup . getAccess ( ) ) ; if ( updateMetadataResponse . getHttpstatus ( ) . equals ( HttpStatus . NO_CONTENT ) || updateMetadataResponse . getHttpstatus ( ) . equals ( HttpStatus . OK ) ) { log . info ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , IAMServiceAccountConstants . ADD_GROUP_TO_IAMSVCACC_MSG ) . put ( LogMessage . MESSAGE , String . format ( "Successfully updated metadata for group [%s]" , iamServiceAccountGroup . getGroupname ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; } else { log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , IAMServiceAccountConstants . ADD_GROUP_TO_IAMSVCACC_MSG ) . put ( LogMessage . MESSAGE , String . format ( "Failed to update metadata for group [%s]" , iamServiceAccountGroup . getGroupname ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; String currentpoliciesString = org . apache . commons . lang3 . StringUtils . join ( currentpolicies , "," ) ; return revertGroupPermissionForIAMSvcAcc ( token , userDetails , oidcGroup , iamServiceAccountGroup . getGroupname ( ) , currentpolicies , currentpoliciesString , updateMetadataResponse ) ; } } else { log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , IAMServiceAccountConstants . ADD_GROUP_TO_IAMSVCACC_MSG ) . put ( LogMessage . MESSAGE , String . format ( "Failed to configure group policies for group [%s]" , iamServiceAccountGroup . getGroupname ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return ResponseEntity . status ( HttpStatus . INTERNAL_SERVER_ERROR ) . body ( String . format ( "{\"errors\":[\"Unable to update group policies for group %s\"]}" , iamServiceAccountGroup . getGroupname ( ) ) ) ; } return ResponseEntity . status ( HttpStatus . OK ) . body ( "{\"messages\":[\"Group is successfully associated with IAM Service Account\"]}" ) ; }
Method to create policies for add group to IAM service account and call the update process.
Method to create policies for add group to IAM service account and call the update process .