From 0fb5a577b87681931b148aed7c8dbefe8975f666 Mon Sep 17 00:00:00 2001 From: Maninda Date: Thu, 5 Jan 2017 11:47:09 +0530 Subject: [PATCH] Fixed some issues found in FindBugs security analysis. --- .../extension/api/filter/ApiPermissionFilter.java | 2 +- .../mgt/jaxrs/api/common/GsonMessageBodyHandler.java | 6 +----- .../mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java | 6 +----- .../device/mgt/jaxrs/common/GsonMessageBodyHandler.java | 6 +----- .../carbon/device/mgt/common/device/details/DeviceInfo.java | 2 +- .../device/mgt/common/device/details/DeviceLocation.java | 2 +- 6 files changed, 6 insertions(+), 18 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/filter/ApiPermissionFilter.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/filter/ApiPermissionFilter.java index bc7dab70535..9c1dfac4bdd 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/filter/ApiPermissionFilter.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/filter/ApiPermissionFilter.java @@ -119,7 +119,7 @@ public class ApiPermissionFilter implements Filter { .getThreadLocalCarbonContext().getTenantId()); return userRealm.getAuthorizationManager().isUserAuthorized(username, permission, action); } catch (UserStoreException e) { - String errorMsg = String.format("Unable to authorize the user : %s", username, e); + String errorMsg = String.format("Unable to authorize the user : %s", username); log.error(errorMsg, e); return false; } diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/common/GsonMessageBodyHandler.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/common/GsonMessageBodyHandler.java index 9cd6c3190ab..91b3283e688 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/common/GsonMessageBodyHandler.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/common/GsonMessageBodyHandler.java @@ -83,11 +83,7 @@ public class GsonMessageBodyHandler implements MessageBodyWriter, Messag OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8); try { - Type jsonType = null; - if (type.equals(type)) { - jsonType = type; - } - getGson().toJson(object, jsonType, writer); + getGson().toJson(object, type, writer); } finally { writer.close(); } diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java index 6abb296c175..7ca13eb59f4 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java @@ -83,11 +83,7 @@ public class GsonMessageBodyHandler implements MessageBodyWriter, Messag OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8); try { - Type jsonType = null; - if (type.equals(type)) { - jsonType = type; - } - getGson().toJson(object, jsonType, writer); + getGson().toJson(object, type, writer); } finally { writer.close(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/common/GsonMessageBodyHandler.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/common/GsonMessageBodyHandler.java index f069edee755..a25fb848330 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/common/GsonMessageBodyHandler.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/common/GsonMessageBodyHandler.java @@ -83,11 +83,7 @@ public class GsonMessageBodyHandler implements MessageBodyWriter, Messag OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8); try { - Type jsonType = null; - if (type.equals(type)) { - jsonType = type; - } - getGson().toJson(object, jsonType, writer); + getGson().toJson(object, type, writer); } finally { writer.close(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java index 343add988ec..b7f5a5b14cd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java @@ -370,7 +370,7 @@ public class DeviceInfo implements Serializable { } public Date getUpdatedTime() { - if(updatedTime.equals(null)){ + if(updatedTime == null){ updatedTime = new Date(); } return updatedTime; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java index 5223b0f047c..f1107091b08 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java @@ -137,7 +137,7 @@ public class DeviceLocation implements Serializable { } public Date getUpdatedTime() { - if(updatedTime.equals(null)){ + if(updatedTime == null ){ updatedTime = new Date(); } return updatedTime;