tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/IAMServiceAccountsService.java
private String[] filterPoliciesBasedOnPrecedence(List<String> policies) {
		List<String> filteredList = new ArrayList<>();
		for (int i = 0; i < policies.size(); i++) {
			String policyName = policies.get(i);
			String[] iamPolicy = policyName.split("_", -1);
			if (iamPolicy.length >= 3) {
				String itemName = policyName.substring(1);
				List<String> matchingPolicies = filteredList.stream().filter(p -> p.substring(1).equals(itemName))
						.collect(Collectors.toList());
				if (!matchingPolicies.isEmpty()) {
					/*
					 * deny has highest priority. Read and write are additive in
					 * nature Removing all matching as there might be duplicate
					 * policies from user and groups
					 */
					if (policyName.startsWith("d_") || (policyName.startsWith("w_")
							&& !matchingPolicies.stream().anyMatch(p -> p.equals("d" + itemName)))) {
						filteredList.removeAll(matchingPolicies);
						filteredList.add(policyName);
					} else if (matchingPolicies.stream().anyMatch(p -> p.equals("d" + itemName))) {
						// policy is read and deny already in the list. Then
						// deny has precedence.
						filteredList.removeAll(matchingPolicies);
						filteredList.add("d" + itemName);
					} else if (matchingPolicies.stream().anyMatch(p -> p.equals("w" + itemName))) {
						// policy is read and write already in the list. Then
						// write has precedence.
						filteredList.removeAll(matchingPolicies);
						filteredList.add("w" + itemName);
					} else if (matchingPolicies.stream().anyMatch(p -> p.equals("r" + itemName))
							|| matchingPolicies.stream().anyMatch(p -> p.equals("o" + itemName))) {
						// policy is read and read already in the list. Then
						// remove all duplicates read and add single read
						// permission for that iam service account.
						filteredList.removeAll(matchingPolicies);
						filteredList.add("r" + itemName);
					}
				} else {
					filteredList.add(policyName);
				}
			}
		}
		return filteredList.toArray(new String[0]);
	}
/**
	 * Filter iam service accounts policies based on policy precedence.
	 * 
	 * @param policies
	 * @return
	 */
Filter iam service accounts policies based on policy precedence.

@param policies
@return
Filter iam service accounts policies based on policy precedence . @param policies @return
private String[] filterPoliciesBasedOnPrecedence(List<String> policies) {
		List<String> filteredList = new ArrayList<>();
		for (int i = 0; i < policies.size(); i++) {
			String policyName = policies.get(i);
			String[] iamPolicy = policyName.split("_", -1);
			if (iamPolicy.length >= 3) {
				String itemName = policyName.substring(1);
				List<String> matchingPolicies = filteredList.stream().filter(p -> p.substring(1).equals(itemName))
						.collect(Collectors.toList());
				if (!matchingPolicies.isEmpty()) {
					/*
					 * deny has highest priority. Read and write are additive in
					 * nature Removing all matching as there might be duplicate
					 * policies from user and groups
					 */
					if (policyName.startsWith("d_") || (policyName.startsWith("w_")
							&& !matchingPolicies.stream().anyMatch(p -> p.equals("d" + itemName)))) {
						filteredList.removeAll(matchingPolicies);
						filteredList.add(policyName);
					} else if (matchingPolicies.stream().anyMatch(p -> p.equals("d" + itemName))) {
						filteredList.removeAll(matchingPolicies);
						filteredList.add("d" + itemName);
					} else if (matchingPolicies.stream().anyMatch(p -> p.equals("w" + itemName))) {
						filteredList.removeAll(matchingPolicies);
						filteredList.add("w" + itemName);
					} else if (matchingPolicies.stream().anyMatch(p -> p.equals("r" + itemName))
							|| matchingPolicies.stream().anyMatch(p -> p.equals("o" + itemName))) {
						filteredList.removeAll(matchingPolicies);
						filteredList.add("r" + itemName);
					}
				} else {
					filteredList.add(policyName);
				}
			}
		}
		return filteredList.toArray(new String[0]);
	}
private String [ ] filterPoliciesBasedOnPrecedence ( List < String > policies ) { List < String > filteredList = new ArrayList < > ( ) ; for ( int i = 0 ; i < policies . size ( ) ; i ++ ) { String policyName = policies . get ( i ) ; String [ ] iamPolicy = policyName . split ( "_" , - 1 ) ; if ( iamPolicy . length >= 3 ) { String itemName = policyName . substring ( 1 ) ; List < String > matchingPolicies = filteredList . stream ( ) . filter ( p -> p . substring ( 1 ) . equals ( itemName ) ) . collect ( Collectors . toList ( ) ) ; if ( ! matchingPolicies . isEmpty ( ) ) { /*
					 * deny has highest priority. Read and write are additive in
					 * nature Removing all matching as there might be duplicate
					 * policies from user and groups
					 */ if ( policyName . startsWith ( "d_" ) || ( policyName . startsWith ( "w_" ) && ! matchingPolicies . stream ( ) . anyMatch ( p -> p . equals ( "d" + itemName ) ) ) ) { filteredList . removeAll ( matchingPolicies ) ; filteredList . add ( policyName ) ; } else if ( matchingPolicies . stream ( ) . anyMatch ( p -> p . equals ( "d" + itemName ) ) ) { filteredList . removeAll ( matchingPolicies ) ; filteredList . add ( "d" + itemName ) ; } else if ( matchingPolicies . stream ( ) . anyMatch ( p -> p . equals ( "w" + itemName ) ) ) { filteredList . removeAll ( matchingPolicies ) ; filteredList . add ( "w" + itemName ) ; } else if ( matchingPolicies . stream ( ) . anyMatch ( p -> p . equals ( "r" + itemName ) ) || matchingPolicies . stream ( ) . anyMatch ( p -> p . equals ( "o" + itemName ) ) ) { filteredList . removeAll ( matchingPolicies ) ; filteredList . add ( "r" + itemName ) ; } } else { filteredList . add ( policyName ) ; } } } return filteredList . toArray ( new String [ 0 ] ) ; }
Filter iam service accounts policies based on policy precedence.
Filter iam service accounts policies based on policy precedence .
// policy is read and deny already in the list. Then // deny has precedence. // policy is read and write already in the list. Then // write has precedence. // policy is read and read already in the list. Then // remove all duplicates read and add single read // permission for that iam service account.