tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/SSLCertificateService.java
private ResponseEntity<String> removePoliciesAndCallMetadataUpdate(String groupName, String certificateName,
			String authToken, String certificateType, UserDetails userDetails, OIDCGroup oidcGroup,
			Response groupResp) {
		String metaDataPath = (certificateType.equalsIgnoreCase(SSLCertificateConstants.INTERNAL))?
	            SSLCertificateConstants.SSL_CERT_PATH_VALUE :SSLCertificateConstants.SSL_CERT_PATH_VALUE_EXT;

		String certificatePath = metaDataPath + certificateName;
		String certPrefix=(certificateType.equalsIgnoreCase(SSLCertificateConstants.INTERNAL))?
                SSLCertificateConstants.INTERNAL_POLICY_NAME :SSLCertificateConstants.EXTERNAL_POLICY_NAME;
		String readPolicy = SSLCertificateConstants.READ_CERT_POLICY_PREFIX+certPrefix+"_"+certificateName;
		String writePolicy = SSLCertificateConstants.WRITE_CERT_POLICY_PREFIX+certPrefix+"_"+certificateName;
		String denyPolicy = SSLCertificateConstants.DENY_CERT_POLICY_PREFIX+certPrefix+"_"+certificateName;
		String sudoPolicy = SSLCertificateConstants.SUDO_CERT_POLICY_PREFIX+certPrefix+"_"+certificateName;

		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
				put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
				put(LogMessage.ACTION, SSLCertificateConstants.REMOVE_GROUP_FROM_CERT_MSG).
				put(LogMessage.MESSAGE, String.format ("Policies are, read - [%s], write - [%s], deny -[%s], owner - [%s]", readPolicy, writePolicy, denyPolicy, sudoPolicy)).
				put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
				build()));

		String responseJson="";
		List<String> policies = new ArrayList<>();
		List<String> currentpolicies = new ArrayList<>();

		if(groupResp != null && 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, SSLCertificateConstants.REMOVE_USER_FROM_CERT_MSG).
		                put(LogMessage.MESSAGE, "Exception while creating currentpolicies or groups").
		                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);
		}else {
			return deleteOrphanGroupEntriesForCertificate(authToken, certificatePath, groupName);
		}

		return configureGroupPoliciesAndCallMetadataUpdate(groupName, authToken, userDetails, oidcGroup,
				certificatePath, policies, currentpolicies);
	}
/**
	 * Method to update policies for remove group from certificate.
	 * @param groupName
	 * @param certificateName
	 * @param authToken
	 * @param certificateType
	 * @param userDetails
	 * @param oidcGroup
	 * @param groupResp
	 * @return
	 */
Method to update policies for remove group from certificate.
Method to update policies for remove group from certificate .
private ResponseEntity<String> removePoliciesAndCallMetadataUpdate(String groupName, String certificateName,
			String authToken, String certificateType, UserDetails userDetails, OIDCGroup oidcGroup,
			Response groupResp) {
		String metaDataPath = (certificateType.equalsIgnoreCase(SSLCertificateConstants.INTERNAL))?
	            SSLCertificateConstants.SSL_CERT_PATH_VALUE :SSLCertificateConstants.SSL_CERT_PATH_VALUE_EXT;
		String certificatePath = metaDataPath + certificateName;
		String certPrefix=(certificateType.equalsIgnoreCase(SSLCertificateConstants.INTERNAL))?
                SSLCertificateConstants.INTERNAL_POLICY_NAME :SSLCertificateConstants.EXTERNAL_POLICY_NAME;
		String readPolicy = SSLCertificateConstants.READ_CERT_POLICY_PREFIX+certPrefix+"_"+certificateName;
		String writePolicy = SSLCertificateConstants.WRITE_CERT_POLICY_PREFIX+certPrefix+"_"+certificateName;
		String denyPolicy = SSLCertificateConstants.DENY_CERT_POLICY_PREFIX+certPrefix+"_"+certificateName;
		String sudoPolicy = SSLCertificateConstants.SUDO_CERT_POLICY_PREFIX+certPrefix+"_"+certificateName;
		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
				put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
				put(LogMessage.ACTION, SSLCertificateConstants.REMOVE_GROUP_FROM_CERT_MSG).
				put(LogMessage.MESSAGE, String.format ("Policies are, read - [%s], write - [%s], deny -[%s], owner - [%s]", readPolicy, writePolicy, denyPolicy, sudoPolicy)).
				put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
				build()));
		String responseJson="";
		List<String> policies = new ArrayList<>();
		List<String> currentpolicies = new ArrayList<>();
		if(groupResp != null && 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, SSLCertificateConstants.REMOVE_USER_FROM_CERT_MSG).
		                put(LogMessage.MESSAGE, "Exception while creating currentpolicies or groups").
		                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);
		}else {
			return deleteOrphanGroupEntriesForCertificate(authToken, certificatePath, groupName);
		}
		return configureGroupPoliciesAndCallMetadataUpdate(groupName, authToken, userDetails, oidcGroup,
				certificatePath, policies, currentpolicies);
	}
private ResponseEntity < String > removePoliciesAndCallMetadataUpdate ( String groupName , String certificateName , String authToken , String certificateType , UserDetails userDetails , OIDCGroup oidcGroup , Response groupResp ) { String metaDataPath = ( certificateType . equalsIgnoreCase ( SSLCertificateConstants . INTERNAL ) ) ? SSLCertificateConstants . SSL_CERT_PATH_VALUE : SSLCertificateConstants . SSL_CERT_PATH_VALUE_EXT ; String certificatePath = metaDataPath + certificateName ; String certPrefix = ( certificateType . equalsIgnoreCase ( SSLCertificateConstants . INTERNAL ) ) ? SSLCertificateConstants . INTERNAL_POLICY_NAME : SSLCertificateConstants . EXTERNAL_POLICY_NAME ; String readPolicy = SSLCertificateConstants . READ_CERT_POLICY_PREFIX + certPrefix + "_" + certificateName ; String writePolicy = SSLCertificateConstants . WRITE_CERT_POLICY_PREFIX + certPrefix + "_" + certificateName ; String denyPolicy = SSLCertificateConstants . DENY_CERT_POLICY_PREFIX + certPrefix + "_" + certificateName ; String sudoPolicy = SSLCertificateConstants . SUDO_CERT_POLICY_PREFIX + certPrefix + "_" + certificateName ; log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . REMOVE_GROUP_FROM_CERT_MSG ) . put ( LogMessage . MESSAGE , String . format ( "Policies are, read - [%s], write - [%s], deny -[%s], owner - [%s]" , readPolicy , writePolicy , denyPolicy , sudoPolicy ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; String responseJson = "" ; List < String > policies = new ArrayList < > ( ) ; List < String > currentpolicies = new ArrayList < > ( ) ; if ( groupResp != null && 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 , SSLCertificateConstants . REMOVE_USER_FROM_CERT_MSG ) . put ( LogMessage . MESSAGE , "Exception while creating currentpolicies or groups" ) . 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 ) ; } else { return deleteOrphanGroupEntriesForCertificate ( authToken , certificatePath , groupName ) ; } return configureGroupPoliciesAndCallMetadataUpdate ( groupName , authToken , userDetails , oidcGroup , certificatePath , policies , currentpolicies ) ; }
Method to update policies for remove group from certificate.
Method to update policies for remove group from certificate .
// OIDC Changes