tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/SSLCertificateService.java
private boolean deleteAllPermissionAddedToCertificate(SSLCertificateMetadataDetails certificateMetaData,
			String certificatePath, String authToken, UserDetails userDetails) {
		boolean permissionRemoved = true;
		try {
			Response response = getCertificateDetailsByMatadataPath(certificatePath, authToken);
			JsonParser jsonParser = new JsonParser();
			JsonObject object = ((JsonObject) jsonParser.parse(response.getResponse())).getAsJsonObject("data");

			//remove user permissions
			deleteUserPermissionForCertificate(certificateMetaData.getCertType(), certificateMetaData.getCertificateName(), userDetails, jsonParser, object);
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
			        .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
			        .put(LogMessage.ACTION, SSLCertificateConstants.VALIDATE_CERTIFICATE_DETAILS_MSG)
			        .put(LogMessage.MESSAGE, String.format("DeleteUserPermissionForCertificate Completed for certificate = [%s]", certificateMetaData.getCertificateName()))
			        .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));

			//remove group permissions
			removeGroupPermissionsToCertificate(certificateMetaData.getCertType(), certificateMetaData.getCertificateName(), userDetails, jsonParser, object);
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
			        .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
			        .put(LogMessage.ACTION, SSLCertificateConstants.VALIDATE_CERTIFICATE_DETAILS_MSG)
			        .put(LogMessage.MESSAGE, String.format("RemoveGroupPermissionsToCertificate Completed for certificate = [%s]", certificateMetaData.getCertificateName()))
			        .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));

			//remove AWS role permissions
			deleteAwsRoleOnCertificateDelete(certificateMetaData.getCertificateName(), authToken, jsonParser, object);
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
			        .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
			        .put(LogMessage.ACTION, SSLCertificateConstants.VALIDATE_CERTIFICATE_DETAILS_MSG)
			        .put(LogMessage.MESSAGE, String.format("DeleteAwsRoleOnCertificate Completed for certificate = [%s]", certificateMetaData.getCertificateName()))
			        .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			//remove App role permissions
			deleteApprolePolicyAssociationOnCertificate(certificateMetaData.getCertificateName(), authToken, jsonParser, object);
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
			        .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
			        .put(LogMessage.ACTION, SSLCertificateConstants.VALIDATE_CERTIFICATE_DETAILS_MSG)
			        .put(LogMessage.MESSAGE, String.format("DeleteApprolePolicyAssociationOnCertificate Completed for certificate = [%s]", certificateMetaData.getCertificateName()))
			        .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));

			// remove Sudo permissions
			removeSudoPermissionForPreviousOwner(certificateMetaData.getCertOwnerNtid().toLowerCase(),
					certificateMetaData.getCertificateName(), userDetails,
					certificateMetaData.getCertType());
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
			        .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
			        .put(LogMessage.ACTION, SSLCertificateConstants.VALIDATE_CERTIFICATE_DETAILS_MSG)
			        .put(LogMessage.MESSAGE, String.format("RemoveSudoPermissionForPreviousOwner Completed for certificate = [%s]", certificateMetaData.getCertificateName()))
			        .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));

		} catch (JsonSyntaxException e) {
			permissionRemoved = false;
			log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
					put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
					put(LogMessage.ACTION, SSLCertificateConstants.VALIDATE_CERTIFICATE_DETAILS_MSG).
					put(LogMessage.MESSAGE, "Remove permissions to the certificate failed").
					put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
					build()));
		}

		return permissionRemoved;
	}
/**
	 * Method to delete all permissions added to the certificate.
	 * @param certificateMetaData
	 * @param certificatePath
	 * @param authToken
	 * @param userDetails
	 * @return
	 */
Method to delete all permissions added to the certificate.
Method to delete all permissions added to the certificate .
private boolean deleteAllPermissionAddedToCertificate(SSLCertificateMetadataDetails certificateMetaData,
			String certificatePath, String authToken, UserDetails userDetails) {
		boolean permissionRemoved = true;
		try {
			Response response = getCertificateDetailsByMatadataPath(certificatePath, authToken);
			JsonParser jsonParser = new JsonParser();
			JsonObject object = ((JsonObject) jsonParser.parse(response.getResponse())).getAsJsonObject("data");
			deleteUserPermissionForCertificate(certificateMetaData.getCertType(), certificateMetaData.getCertificateName(), userDetails, jsonParser, object);
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
			        .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
			        .put(LogMessage.ACTION, SSLCertificateConstants.VALIDATE_CERTIFICATE_DETAILS_MSG)
			        .put(LogMessage.MESSAGE, String.format("DeleteUserPermissionForCertificate Completed for certificate = [%s]", certificateMetaData.getCertificateName()))
			        .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			removeGroupPermissionsToCertificate(certificateMetaData.getCertType(), certificateMetaData.getCertificateName(), userDetails, jsonParser, object);
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
			        .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
			        .put(LogMessage.ACTION, SSLCertificateConstants.VALIDATE_CERTIFICATE_DETAILS_MSG)
			        .put(LogMessage.MESSAGE, String.format("RemoveGroupPermissionsToCertificate Completed for certificate = [%s]", certificateMetaData.getCertificateName()))
			        .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			deleteAwsRoleOnCertificateDelete(certificateMetaData.getCertificateName(), authToken, jsonParser, object);
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
			        .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
			        .put(LogMessage.ACTION, SSLCertificateConstants.VALIDATE_CERTIFICATE_DETAILS_MSG)
			        .put(LogMessage.MESSAGE, String.format("DeleteAwsRoleOnCertificate Completed for certificate = [%s]", certificateMetaData.getCertificateName()))
			        .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			deleteApprolePolicyAssociationOnCertificate(certificateMetaData.getCertificateName(), authToken, jsonParser, object);
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
			        .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
			        .put(LogMessage.ACTION, SSLCertificateConstants.VALIDATE_CERTIFICATE_DETAILS_MSG)
			        .put(LogMessage.MESSAGE, String.format("DeleteApprolePolicyAssociationOnCertificate Completed for certificate = [%s]", certificateMetaData.getCertificateName()))
			        .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			removeSudoPermissionForPreviousOwner(certificateMetaData.getCertOwnerNtid().toLowerCase(),
					certificateMetaData.getCertificateName(), userDetails,
					certificateMetaData.getCertType());
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
			        .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
			        .put(LogMessage.ACTION, SSLCertificateConstants.VALIDATE_CERTIFICATE_DETAILS_MSG)
			        .put(LogMessage.MESSAGE, String.format("RemoveSudoPermissionForPreviousOwner Completed for certificate = [%s]", certificateMetaData.getCertificateName()))
			        .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		} catch (JsonSyntaxException e) {
			permissionRemoved = false;
			log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
					put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
					put(LogMessage.ACTION, SSLCertificateConstants.VALIDATE_CERTIFICATE_DETAILS_MSG).
					put(LogMessage.MESSAGE, "Remove permissions to the certificate failed").
					put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
					build()));
		}
		return permissionRemoved;
	}
private boolean deleteAllPermissionAddedToCertificate ( SSLCertificateMetadataDetails certificateMetaData , String certificatePath , String authToken , UserDetails userDetails ) { boolean permissionRemoved = true ; try { Response response = getCertificateDetailsByMatadataPath ( certificatePath , authToken ) ; JsonParser jsonParser = new JsonParser ( ) ; JsonObject object = ( ( JsonObject ) jsonParser . parse ( response . getResponse ( ) ) ) . getAsJsonObject ( "data" ) ; deleteUserPermissionForCertificate ( certificateMetaData . getCertType ( ) , certificateMetaData . getCertificateName ( ) , userDetails , jsonParser , object ) ; log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . VALIDATE_CERTIFICATE_DETAILS_MSG ) . put ( LogMessage . MESSAGE , String . format ( "DeleteUserPermissionForCertificate Completed for certificate = [%s]" , certificateMetaData . getCertificateName ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; removeGroupPermissionsToCertificate ( certificateMetaData . getCertType ( ) , certificateMetaData . getCertificateName ( ) , userDetails , jsonParser , object ) ; log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . VALIDATE_CERTIFICATE_DETAILS_MSG ) . put ( LogMessage . MESSAGE , String . format ( "RemoveGroupPermissionsToCertificate Completed for certificate = [%s]" , certificateMetaData . getCertificateName ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; deleteAwsRoleOnCertificateDelete ( certificateMetaData . getCertificateName ( ) , authToken , jsonParser , object ) ; log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . VALIDATE_CERTIFICATE_DETAILS_MSG ) . put ( LogMessage . MESSAGE , String . format ( "DeleteAwsRoleOnCertificate Completed for certificate = [%s]" , certificateMetaData . getCertificateName ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; deleteApprolePolicyAssociationOnCertificate ( certificateMetaData . getCertificateName ( ) , authToken , jsonParser , object ) ; log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . VALIDATE_CERTIFICATE_DETAILS_MSG ) . put ( LogMessage . MESSAGE , String . format ( "DeleteApprolePolicyAssociationOnCertificate Completed for certificate = [%s]" , certificateMetaData . getCertificateName ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; removeSudoPermissionForPreviousOwner ( certificateMetaData . getCertOwnerNtid ( ) . toLowerCase ( ) , certificateMetaData . getCertificateName ( ) , userDetails , certificateMetaData . getCertType ( ) ) ; log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . VALIDATE_CERTIFICATE_DETAILS_MSG ) . put ( LogMessage . MESSAGE , String . format ( "RemoveSudoPermissionForPreviousOwner Completed for certificate = [%s]" , certificateMetaData . getCertificateName ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; } catch ( JsonSyntaxException e ) { permissionRemoved = false ; log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . VALIDATE_CERTIFICATE_DETAILS_MSG ) . put ( LogMessage . MESSAGE , "Remove permissions to the certificate failed" ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; } return permissionRemoved ; }
Method to delete all permissions added to the certificate.
Method to delete all permissions added to the certificate .
//remove user permissions //remove group permissions //remove AWS role permissions //remove App role permissions // remove Sudo permissions