From e7b3169d03b822bcbf4f522b2eeb4bcef790c563 Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Tue, 9 Feb 2021 09:55:39 +0100 Subject: [PATCH] Improved: Rename some connoted words like blacklist and whitelist (OFBIZ-12168) Renames respectively blacklist and whitelist to denylist and allowlist in several places. There are still a lot of master word which can be replaced by main, but not in contexts where slave is also used. I'll discuss that on dev ML again... Provides the migrateOldOrderBlacklistAndOldOrderBlacklistType service to migrate records from OrderBlacklist and OrderBlacklistType entities to new OrderDenylist and OrderDenylistType entities --- .../datamodel/data/seed/OrderSeedData.xml | 8 ++-- .../datamodel/entitydef/order-entitymodel.xml | 29 ++++++++++-- .../order/config/OrderEntityLabels.xml | 40 ++++++++-------- applications/order/ofbiz-component.xml | 1 + .../order/servicedef/services_order.xml | 20 ++++---- .../order/servicedef/services_upgrade.xml | 32 +++++++++++++ .../ofbiz/order/OrderBlacklistServices.groovy | 46 +++++++++++++++++++ .../order/shoppingcart/CheckOutEvents.java | 8 ++-- .../order/shoppingcart/CheckOutHelper.java | 32 ++++++------- .../webapp/ordermgr/WEB-INF/controller.xml | 14 +++--- .../config/SafeObjectInputStream.properties | 2 +- .../base/util/SafeObjectInputStream.java | 12 ++--- .../ofbiz/webapp/control/ControlFilter.java | 4 +- 13 files changed, 173 insertions(+), 75 deletions(-) create mode 100644 applications/order/servicedef/services_upgrade.xml create mode 100644 applications/order/src/main/groovy/org/apache/ofbiz/order/OrderBlacklistServices.groovy diff --git a/applications/datamodel/data/seed/OrderSeedData.xml b/applications/datamodel/data/seed/OrderSeedData.xml index 6210505cbd..106a613051 100644 --- a/applications/datamodel/data/seed/OrderSeedData.xml +++ b/applications/datamodel/data/seed/OrderSeedData.xml @@ -51,10 +51,10 @@ under the License. - - - - + + + + diff --git a/applications/datamodel/entitydef/order-entitymodel.xml b/applications/datamodel/entitydef/order-entitymodel.xml index 086bdede6f..839cd37f79 100644 --- a/applications/datamodel/entitydef/order-entitymodel.xml +++ b/applications/datamodel/entitydef/order-entitymodel.xml @@ -242,24 +242,43 @@ under the License. - - + - + + + + + + + + + + + + + + - + @@ -3076,4 +3095,4 @@ under the License. - \ No newline at end of file + diff --git a/applications/order/config/OrderEntityLabels.xml b/applications/order/config/OrderEntityLabels.xml index 491ff24ca5..971ba93dbe 100644 --- a/applications/order/config/OrderEntityLabels.xml +++ b/applications/order/config/OrderEntityLabels.xml @@ -445,60 +445,60 @@ 保修 保修 - + عنوان قائمة سوداء - Blacklist Adressen - Blacklist Address + Denylist Adressen + Denylist Address Dirección bloqueada Mettre l'adresse en liste noire - Indirizzo blacklist + Indirizzo denylist ブラックリスト住所 - Blacklist - Adres + Denylist - Adres Lista negra de endereços ที่อยู่ Địa chỉ Danh sách đen 地址黑名单 位址黑名單 - + بطاقة إئتمانية قائمة سوداء - Blacklist Kreditkarte - Blacklist Credit Card + Denylist Kreditkarte + Denylist Credit Card Tarjeta de crédito bloqueada Mettre la carte de crédit en liste noire - Blacklist carta di credito + Denylist carta di credito ブラックリストクレジットカード - Blacklist - Kredietkaart + Denylist - Kredietkaart Lista negra de cartões de crédito บัตรเครดิต Danh sách đen thẻ tín dụng 信用卡黑名单 信用卡黑名單 - + بريد إلكتروني قائمة سوداء - Blacklist E-Mail - Blacklist Email + Denylist E-Mail + Denylist Email Email bloqueado Mettre l'addresse de courriel en liste noire - Email blacklist + Email denylist ブラックリストEメール - Blacklist - Email + Denylist - Email Lista negra de e-mails อีเมล Danh sách đen thư điện tử 电子邮件黑名单 電子郵件黑名單 - + هاتف قائمة سوداء - Blacklist Telefon - Blacklist Phone + Denylist Telefon + Denylist Phone Teléfono bloqueado Mettre le n° de téléphone en liste noire - Telefono blacklist + Telefono denylist ブラックリスト電話番号 - Blacklist - Telefoon + Denylist - Telefoon Lista negra de telefones หมายเลขโทรศัพท์ Danh sách đen số điện thoại diff --git a/applications/order/ofbiz-component.xml b/applications/order/ofbiz-component.xml index 34db95f139..7fc3a3aabc 100644 --- a/applications/order/ofbiz-component.xml +++ b/applications/order/ofbiz-component.xml @@ -45,6 +45,7 @@ under the License. + diff --git a/applications/order/servicedef/services_order.xml b/applications/order/servicedef/services_order.xml index ac29188eb9..888359bdec 100644 --- a/applications/order/servicedef/services_order.xml +++ b/applications/order/servicedef/services_order.xml @@ -69,27 +69,27 @@ under the License. Delete an OrderAttribute record - - Create an OrderBlacklist record + + Create an OrderDenylist record - - Delete an OrderBlacklist record + + Delete an OrderDenylist record - - Create an OrderBlacklistType record + + Create an OrderDenylistType record - - Update an OrderBlacklistType record + + Update an OrderDenylistType record - - Delete an OrderBlacklistType record + + Delete an OrderDenylistType record diff --git a/applications/order/servicedef/services_upgrade.xml b/applications/order/servicedef/services_upgrade.xml new file mode 100644 index 0000000000..5123d29023 --- /dev/null +++ b/applications/order/servicedef/services_upgrade.xml @@ -0,0 +1,32 @@ + + + + + Order Component Services for upgrading data in existing DB + OFBiz + 1.0 + + + + Migration service to convert entries from OldOrderBlacklist and OldOrderBlacklistType to respectively OrderDenylist and OrderDenylistType entities + + diff --git a/applications/order/src/main/groovy/org/apache/ofbiz/order/OrderBlacklistServices.groovy b/applications/order/src/main/groovy/org/apache/ofbiz/order/OrderBlacklistServices.groovy new file mode 100644 index 0000000000..7d7252bb7f --- /dev/null +++ b/applications/order/src/main/groovy/org/apache/ofbiz/order/OrderBlacklistServices.groovy @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.ofbiz.entity.GenericValue + +/* + * Migrate all elements present on OldOrderBlacklist and OldOrderBlacklistType to respectively OrderDenylist and OrderDenylistType entities + * Update service for Deprecate since: branch release + */ +def migrateOldOrderBlacklistAndOldOrderBlacklistType() { + List oldOrderBlacklist = delegator.findAll("OldOrderBlacklist", false) + oldOrderBlacklist.each { + GenericValue OrderDenylist = makeValue("OrderDenylist") + OrderDenylist.blacklistString = it.blacklistString + OrderDenylist.orderBlacklistTypeId = it.orderBlacklistTypeId + OrderDenylist.create() + it.remove() + } + + List oldOrderBlacklistType = delegator.findAll("OldOrderBlacklistType", false) + oldOrderBlacklist.each { + GenericValue OrderDenylistType = makeValue("OrderDenylistType") + orderBlacklist.orderBlacklistTypeId = it.orderBlacklistTypeId + OrderDenylistType.description = it.description + OrderDenylistType.create() + it.remove() + } + + return success() +} diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutEvents.java b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutEvents.java index e56fef67f6..2671ea31d1 100644 --- a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutEvents.java +++ b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutEvents.java @@ -634,14 +634,14 @@ public class CheckOutEvents { return (callResult.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_SUCCESS)); } - public static String checkOrderBlacklist(HttpServletRequest request, HttpServletResponse response) { + public static String checkOrderDenylist(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); ShoppingCart cart = (ShoppingCart) session.getAttribute("shoppingCart"); Delegator delegator = (Delegator) request.getAttribute("delegator"); CheckOutHelper checkOutHelper = new CheckOutHelper(null, delegator, cart); String result; - Map callResult = checkOutHelper.checkOrderBlackList(); + Map callResult = checkOutHelper.checkOrderDenyList(); if (callResult.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_ERROR)) { request.setAttribute("_ERROR_MESSAGE_", callResult.get(ModelService.ERROR_MESSAGE)); result = "error"; @@ -655,7 +655,7 @@ public class CheckOutEvents { return result; } - public static String failedBlacklistCheck(HttpServletRequest request, HttpServletResponse response) { + public static String failedDenylistCheck(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); ShoppingCart cart = (ShoppingCart) session.getAttribute("shoppingCart"); Delegator delegator = (Delegator) request.getAttribute("delegator"); @@ -668,7 +668,7 @@ public class CheckOutEvents { // Load the properties store GenericValue productStore = ProductStoreWorker.getProductStore(cart.getProductStoreId(), delegator); CheckOutHelper checkOutHelper = new CheckOutHelper(dispatcher, delegator, cart); - Map callResult = checkOutHelper.failedBlacklistCheck(userLogin, productStore); + Map callResult = checkOutHelper.failedDenylistCheck(userLogin, productStore); //Generate any messages required ServiceUtil.getMessages(request, callResult, null); diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java index 75a34338e6..c031b078f4 100644 --- a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java +++ b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java @@ -1381,7 +1381,7 @@ public class CheckOutHelper { * Check order black list map. * @return the map */ - public Map checkOrderBlackList() { + public Map checkOrderDenyList() { if (cart == null) { return ServiceUtil.returnSuccess("success"); } @@ -1392,10 +1392,10 @@ public class CheckOutHelper { String shippingAddress = UtilFormatOut.checkNull(shippingAddressObj.getString("address1")).toUpperCase(Locale.getDefault()); shippingAddress = UtilFormatOut.makeSqlSafe(shippingAddress); List exprs = UtilMisc.toList(EntityCondition.makeCondition( - EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("blacklistString"), EntityOperator.EQUALS, + EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("denylistString"), EntityOperator.EQUALS, EntityFunction.UPPER(shippingAddress)), EntityOperator.AND, - EntityCondition.makeCondition("orderBlacklistTypeId", EntityOperator.EQUALS, "BLACKLIST_ADDRESS"))); + EntityCondition.makeCondition("orderDenylistTypeId", EntityOperator.EQUALS, "DENYLIST_ADDRESS"))); String errMsg = null; List paymentMethods = this.cart.getPaymentMethods(); @@ -1416,55 +1416,55 @@ public class CheckOutHelper { if (creditCard != null) { String creditCardNumber = UtilFormatOut.checkNull(creditCard.getString("cardNumber")); exprs.add(EntityCondition.makeCondition( - EntityCondition.makeCondition("blacklistString", EntityOperator.EQUALS, creditCardNumber), EntityOperator.AND, - EntityCondition.makeCondition("orderBlacklistTypeId", EntityOperator.EQUALS, "BLACKLIST_CREDITCARD"))); + EntityCondition.makeCondition("denylistString", EntityOperator.EQUALS, creditCardNumber), EntityOperator.AND, + EntityCondition.makeCondition("orderDenylistTypeId", EntityOperator.EQUALS, "DENYLIST_CREDITCARD"))); } if (billingAddress != null) { String address = UtilFormatOut.checkNull(billingAddress.getString("address1").toUpperCase(Locale.getDefault())); address = UtilFormatOut.makeSqlSafe(address); exprs.add(EntityCondition.makeCondition( - EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("blacklistString"), EntityOperator.EQUALS, + EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("denylistString"), EntityOperator.EQUALS, EntityFunction.UPPER(address)), EntityOperator.AND, - EntityCondition.makeCondition("orderBlacklistTypeId", EntityOperator.EQUALS, "BLACKLIST_ADDRESS"))); + EntityCondition.makeCondition("orderDenylistTypeId", EntityOperator.EQUALS, "DENYLIST_ADDRESS"))); } } } - List blacklistFound = null; + List denylistFound = null; if (!exprs.isEmpty()) { try { - blacklistFound = EntityQuery.use(this.delegator).from("OrderBlacklist").where(exprs).queryList(); + denylistFound = EntityQuery.use(this.delegator).from("OrderDenylist").where(exprs).queryList(); } catch (GenericEntityException e) { - Debug.logError(e, "Problems with OrderBlacklist lookup.", MODULE); + Debug.logError(e, "Problems with OrderDenylist lookup.", MODULE); errMsg = UtilProperties.getMessage(RES_ERROR, "checkhelper.problems_reading_database", cart.getLocale()); return ServiceUtil.returnError(errMsg); } } - if (UtilValidate.isNotEmpty(blacklistFound)) { + if (UtilValidate.isNotEmpty(denylistFound)) { return ServiceUtil.returnFailure(UtilProperties.getMessage(RES_ERROR, "OrderFailed", cart.getLocale())); } return ServiceUtil.returnSuccess("success"); } /** - * Check order blacklist map. + * Check order denylist map. * @param userLogin the user login * @return the map */ @Deprecated - public Map checkOrderBlacklist(GenericValue userLogin) { - return checkOrderBlackList(); + public Map checkOrderDenylist(GenericValue userLogin) { + return checkOrderDenyList(); } /** - * Failed blacklist check map. + * Failed denylist check map. * @param userLogin the user login * @param productStore the product store * @return the map */ - public Map failedBlacklistCheck(GenericValue userLogin, GenericValue productStore) { + public Map failedDenylistCheck(GenericValue userLogin, GenericValue productStore) { Map result; String errMsg = null; String rejectMessage = productStore.getString("authFraudMessage"); diff --git a/applications/order/webapp/ordermgr/WEB-INF/controller.xml b/applications/order/webapp/ordermgr/WEB-INF/controller.xml index f8cc97a6c7..df18ed1521 100644 --- a/applications/order/webapp/ordermgr/WEB-INF/controller.xml +++ b/applications/order/webapp/ordermgr/WEB-INF/controller.xml @@ -996,21 +996,21 @@ under the License. - - + + - + - + - + - + - + diff --git a/framework/base/config/SafeObjectInputStream.properties b/framework/base/config/SafeObjectInputStream.properties index 548eab76be..ca6c829504 100644 --- a/framework/base/config/SafeObjectInputStream.properties +++ b/framework/base/config/SafeObjectInputStream.properties @@ -18,7 +18,7 @@ ############################################################################### # Because of OFBIZ-10837 - Improve ObjectInputStream class. -# If you encounter a related issue (object not in the whitelist), +# If you encounter a related issue (object not in the allowlist), # you must provide a complete list of objects to pass to ObjectInputStream # through ListOfSafeObjectsForInputStream property # As an example, the a complete list of objects used by OFBiz OOTB is here. diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java index c18708ca32..e846081f93 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java @@ -36,14 +36,14 @@ import java.util.regex.Pattern; * only authorized class can be read from it. */ public final class SafeObjectInputStream extends ObjectInputStream { - private static final String[] DEFAULT_WHITELIST_PATTERN = { + private static final String[] DEFAULT_ALLOWLIST_PATTERN = { "byte\\[\\]", "foo", "SerializationInjector", "\\[Z", "\\[B", "\\[S", "\\[I", "\\[J", "\\[F", "\\[D", "\\[C", "java..*", "sun.util.calendar..*", "org.apache.ofbiz..*", "org.codehaus.groovy.runtime.GStringImpl", "groovy.lang.GString"}; /** The regular expression used to match serialized types. */ - private final Pattern whitelistPattern; + private final Pattern allowlistPattern; /** * Instantiates a safe object input stream. @@ -53,8 +53,8 @@ public final class SafeObjectInputStream extends ObjectInputStream { public SafeObjectInputStream(InputStream in) throws IOException { super(in); String safeObjectsProp = getPropertyValue("SafeObjectInputStream", "ListOfSafeObjectsForInputStream", ""); - String[] whitelist = safeObjectsProp.isEmpty() ? DEFAULT_WHITELIST_PATTERN : safeObjectsProp.split(","); - whitelistPattern = Arrays.stream(whitelist) + String[] allowlist = safeObjectsProp.isEmpty() ? DEFAULT_ALLOWLIST_PATTERN : safeObjectsProp.split(","); + allowlistPattern = Arrays.stream(allowlist) .map(String::trim) .filter(str -> !str.isEmpty()) .collect(collectingAndThen(joining("|", "(", ")"), Pattern::compile)); @@ -63,7 +63,7 @@ public final class SafeObjectInputStream extends ObjectInputStream { @Override protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException { String className = classDesc.getName(); - // BlackList exploits; eg: don't allow RMI here + // DenyList exploits; eg: don't allow RMI here if (className.contains("java.rmi.server")) { Debug.logWarning("***Incompatible class***: " + classDesc.getName() @@ -71,7 +71,7 @@ public final class SafeObjectInputStream extends ObjectInputStream { "SafeObjectInputStream"); return null; } - if (!whitelistPattern.matcher(className).find()) { + if (!allowlistPattern.matcher(className).find()) { // DiskFileItem, FileItemHeadersImpl are not serializable. if (className.contains("org.apache.commons.fileupload")) { return null; diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java index a6d8e96045..bf9551f616 100644 --- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java +++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java @@ -38,7 +38,7 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.ofbiz.base.util.Debug; /** - * A Filter used to specify a whitelist of allowed paths to the OFBiz application. + * A Filter used to specify an allowlist of allowed paths to the OFBiz application. * Requests that do not match any of the paths listed in allowedPaths are redirected to redirectPath, or an error code * is returned (the error code can be set in errorCode, the default value is 403). * If forceRedirectAll is set to Y then allowedPaths is ignored and all requests are redirected to redirectPath; note @@ -58,7 +58,7 @@ import org.apache.ofbiz.base.util.Debug; * - for its internal logic (to avoid an infinite loop of redirections when forceRedirectAll is set) the filter sets * a session parameter (_FORCE_REDIRECT_=true) before the first redirection; the parameter is removed during the * second pass before the request is forwarded to the next filter in the chain - * - the filter skips the check against the whitelist of allowed paths if a request attribute + * - the filter skips the check against the allowlist of allowed paths if a request attribute * with name _FORWARDED_FROM_SERVLET_ is present; this attribute is typically set by the ControlServlet to indicate * that the request path is safe and should not be checked again */