tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/IAMServiceAccountsService.java
private ResponseEntity<String> processAndRemoveUserPermissionFromIAMSvcAcc(String token,
			IAMServiceAccountUser iamServiceAccountUser, UserDetails userDetails, OIDCEntityResponse oidcEntityResponse,
			String uniqueIAMSvcaccName, List<String> policiesToRemove) {

		Response userResponse = new Response();
		if (TVaultConstants.USERPASS.equals(vaultAuthMethod)) {
			userResponse = reqProcessor.process(READPATH, "{\"username\":\"" + iamServiceAccountUser.getUsername() + "\"}",
					token);
		} else if (TVaultConstants.LDAP.equals(vaultAuthMethod)) {
			userResponse = reqProcessor.process(USERPATH, "{\"username\":\"" + iamServiceAccountUser.getUsername() + "\"}", token);
		} else if (TVaultConstants.OIDC.equals(vaultAuthMethod)) {
			// OIDC implementation changes
			ResponseEntity<OIDCEntityResponse> responseEntity = oidcUtil.oidcFetchEntityDetails(token, iamServiceAccountUser.getUsername(), userDetails, true);
			if (!responseEntity.getStatusCode().equals(HttpStatus.OK)) {
				if (responseEntity.getStatusCode().equals(HttpStatus.FORBIDDEN)) {
					log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
							put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
							put(LogMessage.ACTION, IAMServiceAccountConstants.REMOVE_USER_FROM_IAMSVCACC_MSG).
							put(LogMessage.MESSAGE, "Trying to fetch OIDC user policies, failed").
							put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
							build()));
				}
				return ResponseEntity.status(HttpStatus.NOT_FOUND).body("{\"messages\":[\"User configuration failed. Invalid user\"]}");
			}
			oidcEntityResponse.setEntityName(responseEntity.getBody().getEntityName());
			oidcEntityResponse.setPolicies(responseEntity.getBody().getPolicies());
			userResponse.setResponse(oidcEntityResponse.getPolicies().toString());
			userResponse.setHttpstatus(responseEntity.getStatusCode());
		}

		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
				put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
				put(LogMessage.ACTION, IAMServiceAccountConstants.REMOVE_USER_FROM_IAMSVCACC_MSG).
				put(LogMessage.MESSAGE, String.format ("userResponse status is [%s]", userResponse.getHttpstatus())).
				put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
				build()));

		return createPoliciesAndRemoveUserFromSvcAcc(token, iamServiceAccountUser, userDetails, oidcEntityResponse,
				uniqueIAMSvcaccName, userResponse, policiesToRemove);
	}
/**
	 * Method to verify the user for removing from IAM service account.
	 * @param token
	 * @param iamServiceAccountUser
	 * @param userDetails
	 * @param oidcEntityResponse
	 * @param uniqueIAMSvcaccName
	 * @param policiesToRemove
	 * @return
	 */
Method to verify the user for removing from IAM service account.
Method to verify the user for removing from IAM service account .
private ResponseEntity<String> processAndRemoveUserPermissionFromIAMSvcAcc(String token,
			IAMServiceAccountUser iamServiceAccountUser, UserDetails userDetails, OIDCEntityResponse oidcEntityResponse,
			String uniqueIAMSvcaccName, List<String> policiesToRemove) {
		Response userResponse = new Response();
		if (TVaultConstants.USERPASS.equals(vaultAuthMethod)) {
			userResponse = reqProcessor.process(READPATH, "{\"username\":\"" + iamServiceAccountUser.getUsername() + "\"}",
					token);
		} else if (TVaultConstants.LDAP.equals(vaultAuthMethod)) {
			userResponse = reqProcessor.process(USERPATH, "{\"username\":\"" + iamServiceAccountUser.getUsername() + "\"}", token);
		} else if (TVaultConstants.OIDC.equals(vaultAuthMethod)) {
			ResponseEntity<OIDCEntityResponse> responseEntity = oidcUtil.oidcFetchEntityDetails(token, iamServiceAccountUser.getUsername(), userDetails, true);
			if (!responseEntity.getStatusCode().equals(HttpStatus.OK)) {
				if (responseEntity.getStatusCode().equals(HttpStatus.FORBIDDEN)) {
					log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
							put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
							put(LogMessage.ACTION, IAMServiceAccountConstants.REMOVE_USER_FROM_IAMSVCACC_MSG).
							put(LogMessage.MESSAGE, "Trying to fetch OIDC user policies, failed").
							put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
							build()));
				}
				return ResponseEntity.status(HttpStatus.NOT_FOUND).body("{\"messages\":[\"User configuration failed. Invalid user\"]}");
			}
			oidcEntityResponse.setEntityName(responseEntity.getBody().getEntityName());
			oidcEntityResponse.setPolicies(responseEntity.getBody().getPolicies());
			userResponse.setResponse(oidcEntityResponse.getPolicies().toString());
			userResponse.setHttpstatus(responseEntity.getStatusCode());
		}
		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
				put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
				put(LogMessage.ACTION, IAMServiceAccountConstants.REMOVE_USER_FROM_IAMSVCACC_MSG).
				put(LogMessage.MESSAGE, String.format ("userResponse status is [%s]", userResponse.getHttpstatus())).
				put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
				build()));
		return createPoliciesAndRemoveUserFromSvcAcc(token, iamServiceAccountUser, userDetails, oidcEntityResponse,
				uniqueIAMSvcaccName, userResponse, policiesToRemove);
	}
private ResponseEntity < String > processAndRemoveUserPermissionFromIAMSvcAcc ( String token , IAMServiceAccountUser iamServiceAccountUser , UserDetails userDetails , OIDCEntityResponse oidcEntityResponse , String uniqueIAMSvcaccName , List < String > policiesToRemove ) { Response userResponse = new Response ( ) ; if ( TVaultConstants . USERPASS . equals ( vaultAuthMethod ) ) { userResponse = reqProcessor . process ( READPATH , "{\"username\":\"" + iamServiceAccountUser . getUsername ( ) + "\"}" , token ) ; } else if ( TVaultConstants . LDAP . equals ( vaultAuthMethod ) ) { userResponse = reqProcessor . process ( USERPATH , "{\"username\":\"" + iamServiceAccountUser . getUsername ( ) + "\"}" , token ) ; } else if ( TVaultConstants . OIDC . equals ( vaultAuthMethod ) ) { ResponseEntity < OIDCEntityResponse > responseEntity = oidcUtil . oidcFetchEntityDetails ( token , iamServiceAccountUser . getUsername ( ) , userDetails , true ) ; if ( ! responseEntity . getStatusCode ( ) . equals ( HttpStatus . OK ) ) { if ( responseEntity . getStatusCode ( ) . equals ( HttpStatus . FORBIDDEN ) ) { log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , IAMServiceAccountConstants . REMOVE_USER_FROM_IAMSVCACC_MSG ) . put ( LogMessage . MESSAGE , "Trying to fetch OIDC user policies, failed" ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; } return ResponseEntity . status ( HttpStatus . NOT_FOUND ) . body ( "{\"messages\":[\"User configuration failed. Invalid user\"]}" ) ; } oidcEntityResponse . setEntityName ( responseEntity . getBody ( ) . getEntityName ( ) ) ; oidcEntityResponse . setPolicies ( responseEntity . getBody ( ) . getPolicies ( ) ) ; userResponse . setResponse ( oidcEntityResponse . getPolicies ( ) . toString ( ) ) ; userResponse . setHttpstatus ( responseEntity . getStatusCode ( ) ) ; } log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , IAMServiceAccountConstants . REMOVE_USER_FROM_IAMSVCACC_MSG ) . put ( LogMessage . MESSAGE , String . format ( "userResponse status is [%s]" , userResponse . getHttpstatus ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return createPoliciesAndRemoveUserFromSvcAcc ( token , iamServiceAccountUser , userDetails , oidcEntityResponse , uniqueIAMSvcaccName , userResponse , policiesToRemove ) ; }
Method to verify the user for removing from IAM service account.
Method to verify the user for removing from IAM service account .
// OIDC implementation changes