tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/IAMServiceAccountsService.java
private void processNewGroupPolicy(String token, String policyToAdd, String iamSvcAccountName, OIDCGroup oidcGroup,
									   IAMServiceAccountGroup iamServiceAccountGroup, List<String> policies, List<String> currentPolicies) {
		log.debug(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(POLICYSTR, policyToAdd))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		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();

		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("Group policies are, read - [%s], write - [%s], deny -[%s], owner - [%s]", readPolicy,
								writePolicy, denyPolicy, sudoPolicy))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		Response groupResp = new Response();

		if (TVaultConstants.LDAP.equals(vaultAuthMethod)) {
			groupResp = reqProcessor.process(GROUPPATH,
					GROUPNAME + iamServiceAccountGroup.getGroupname() + "\"}", token);
		} else if (TVaultConstants.OIDC.equals(vaultAuthMethod)) {
			// call read api with groupname
			oidcGroup = oidcUtil.getIdentityGroupDetails(iamServiceAccountGroup.getGroupname(), token);
			if (oidcGroup != null) {
				groupResp.setHttpstatus(HttpStatus.OK);
				groupResp.setResponse(oidcGroup.getPolicies().toString());
			} else {
				groupResp.setHttpstatus(HttpStatus.BAD_REQUEST);
			}
		}

		log.debug(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("Group Response status is [%s]", groupResp.getHttpstatus()))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));

		String responseJson = "";

		if (HttpStatus.OK.equals(groupResp.getHttpstatus())) {
			responseJson = groupResp.getResponse();
			try {
				ObjectMapper objMapper = new ObjectMapper();
				// 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, IAMServiceAccountConstants.ADD_GROUP_TO_IAMSVCACC_MSG)
						.put(LogMessage.MESSAGE, "Exception while creating currentpolicies")
						.put(LogMessage.STACKTRACE, Arrays.toString(e.getStackTrace()))
						.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			}

			policies.addAll(currentPolicies);
			policies.remove(readPolicy);
			policies.remove(writePolicy);
			policies.remove(denyPolicy);
		}

		policies.add(policyToAdd);
	}
/**
	 * Helper method for adding a new policy to a group.
	 * Adds current policies for the group as well as the new policy to the policies list.
	 * @param token
	 * @param policyToAdd
	 * @param iamSvcAccountName
	 * @param oidcGroup
	 * @param iamServiceAccountGroup
	 * @param policies
	 * @param currentPolicies
	 * @return void
	 */
Helper method for adding a new policy to a group.
Adds current policies for the group as well as the new policy to the policies list.
Helper method for adding a new policy to a group . Adds current policies for the group as well as the new policy to the policies list .
private void processNewGroupPolicy(String token, String policyToAdd, String iamSvcAccountName, OIDCGroup oidcGroup,
									   IAMServiceAccountGroup iamServiceAccountGroup, List<String> policies, List<String> currentPolicies) {
		log.debug(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(POLICYSTR, policyToAdd))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		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();
		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("Group policies are, read - [%s], write - [%s], deny -[%s], owner - [%s]", readPolicy,
								writePolicy, denyPolicy, sudoPolicy))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		Response groupResp = new Response();
		if (TVaultConstants.LDAP.equals(vaultAuthMethod)) {
			groupResp = reqProcessor.process(GROUPPATH,
					GROUPNAME + iamServiceAccountGroup.getGroupname() + "\"}", token);
		} else if (TVaultConstants.OIDC.equals(vaultAuthMethod)) {
			oidcGroup = oidcUtil.getIdentityGroupDetails(iamServiceAccountGroup.getGroupname(), token);
			if (oidcGroup != null) {
				groupResp.setHttpstatus(HttpStatus.OK);
				groupResp.setResponse(oidcGroup.getPolicies().toString());
			} else {
				groupResp.setHttpstatus(HttpStatus.BAD_REQUEST);
			}
		}
		log.debug(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("Group Response status is [%s]", groupResp.getHttpstatus()))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		String responseJson = "";
		if (HttpStatus.OK.equals(groupResp.getHttpstatus())) {
			responseJson = groupResp.getResponse();
			try {
				ObjectMapper objMapper = new ObjectMapper();
				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, IAMServiceAccountConstants.ADD_GROUP_TO_IAMSVCACC_MSG)
						.put(LogMessage.MESSAGE, "Exception while creating currentpolicies")
						.put(LogMessage.STACKTRACE, Arrays.toString(e.getStackTrace()))
						.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			}
			policies.addAll(currentPolicies);
			policies.remove(readPolicy);
			policies.remove(writePolicy);
			policies.remove(denyPolicy);
		}
		policies.add(policyToAdd);
	}
private void processNewGroupPolicy ( String token , String policyToAdd , String iamSvcAccountName , OIDCGroup oidcGroup , IAMServiceAccountGroup iamServiceAccountGroup , List < String > policies , List < String > currentPolicies ) { log . debug ( 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 ( POLICYSTR , policyToAdd ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; 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 ( ) ; 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 ( "Group policies are, read - [%s], write - [%s], deny -[%s], owner - [%s]" , readPolicy , writePolicy , denyPolicy , sudoPolicy ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; Response groupResp = new Response ( ) ; if ( TVaultConstants . LDAP . equals ( vaultAuthMethod ) ) { groupResp = reqProcessor . process ( GROUPPATH , GROUPNAME + iamServiceAccountGroup . getGroupname ( ) + "\"}" , token ) ; } else if ( TVaultConstants . OIDC . equals ( vaultAuthMethod ) ) { oidcGroup = oidcUtil . getIdentityGroupDetails ( iamServiceAccountGroup . getGroupname ( ) , token ) ; if ( oidcGroup != null ) { groupResp . setHttpstatus ( HttpStatus . OK ) ; groupResp . setResponse ( oidcGroup . getPolicies ( ) . toString ( ) ) ; } else { groupResp . setHttpstatus ( HttpStatus . BAD_REQUEST ) ; } } log . debug ( 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 ( "Group Response status is [%s]" , groupResp . getHttpstatus ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; String responseJson = "" ; if ( HttpStatus . OK . equals ( groupResp . getHttpstatus ( ) ) ) { responseJson = groupResp . getResponse ( ) ; try { ObjectMapper objMapper = new ObjectMapper ( ) ; 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 , IAMServiceAccountConstants . ADD_GROUP_TO_IAMSVCACC_MSG ) . put ( LogMessage . MESSAGE , "Exception while creating currentpolicies" ) . put ( LogMessage . STACKTRACE , Arrays . toString ( e . getStackTrace ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; } policies . addAll ( currentPolicies ) ; policies . remove ( readPolicy ) ; policies . remove ( writePolicy ) ; policies . remove ( denyPolicy ) ; } policies . add ( policyToAdd ) ; }
Helper method for adding a new policy to a group.
Helper method for adding a new policy to a group .
// call read api with groupname // OIDC Changes