From f19d6ff8ed6da92ff38176f731a90ad5aac1716e Mon Sep 17 00:00:00 2001 From: Shabirmean Date: Sun, 17 Jan 2016 20:16:09 +0530 Subject: [PATCH] Refactoring the VirtualFirealrm Service classes. --- .../service/VirtualFireAlarmService.java | 6 +- .../VirtualFireAlarmMQTTConnector.java | 4 +- .../VirtualFireAlarmXMPPConnector.java | 4 +- .../service/util/SecurityManager.java | 2 +- .../util/VirtualFireAlarmServiceUtils.java | 69 +++++++++++++++---- .../service/util/scep/SCEPOperation.java | 2 +- .../mgt/iot/sensormgt/SensorDataManager.java | 2 +- 7 files changed, 66 insertions(+), 23 deletions(-) diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java index 1507e518ae..bd17b86986 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java @@ -528,7 +528,6 @@ public class VirtualFireAlarmService { * * @param operation the SCEP operation requested by the client. [GetCACert] or [GetCACaps] * @param message any messages pertaining to the requested SCEP Operation. - * * @return an HTTP Response object with either the CA-Cert or the CA-Capabilities according to the operation. */ @GET @@ -613,12 +612,11 @@ public class VirtualFireAlarmService { * This acts as the endpoint exposed as part of the SCEP-Server for use by a SCEP Client. This is one of the two * method-signatures that takes different parameters according to the SCEP-Operation executed by the SCEP-Client * of the enrolling device. This API supports the SCEP Operation [PKIOperation]. - * + *

* Operation [PKIOperation] returns a certificate generated by the SCEP-Server for the enrolling device. * - * @param operation the final SCEP operation executed in the enrollment process - which is [PKIOperation] + * @param operation the final SCEP operation executed in the enrollment process - which is [PKIOperation] * @param inputStream an input stream consisting of the Certificate-Signing-Request (CSR) from the device. - * * @return an HTTP Response object with the signed certificate for the device by the CA of the SCEP Server. */ @POST diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmMQTTConnector.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmMQTTConnector.java index acc3622653..35344f80f7 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmMQTTConnector.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmMQTTConnector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -11,7 +11,7 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java index 531e115ec3..9308f57040 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -11,7 +11,7 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/SecurityManager.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/SecurityManager.java index c97c5503fe..169e3eca57 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/SecurityManager.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/SecurityManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VirtualFireAlarmServiceUtils.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VirtualFireAlarmServiceUtils.java index 916661a20c..8ac34ec438 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VirtualFireAlarmServiceUtils.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VirtualFireAlarmServiceUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -11,7 +11,7 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -50,6 +50,9 @@ import java.security.cert.X509Certificate; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; +/** + * + */ public class VirtualFireAlarmServiceUtils { private static final Log log = LogFactory.getLog(VirtualFireAlarmServiceUtils.class); @@ -59,8 +62,12 @@ public class VirtualFireAlarmServiceUtils { private static final String JSON_MESSAGE_KEY = "Msg"; private static final String JSON_SIGNATURE_KEY = "Sig"; - public static CertificateManagementService getCertificateManagementService() throws - VirtualFireAlarmException { + /** + * + * @return + * @throws VirtualFireAlarmException + */ + public static CertificateManagementService getCertificateManagementService() throws VirtualFireAlarmException { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); CertificateManagementService certificateManagementService = (CertificateManagementService) @@ -76,8 +83,16 @@ public class VirtualFireAlarmServiceUtils { } - public static String sendCommandViaHTTP(final String deviceHTTPEndpoint, String urlContext, - boolean fireAndForgot) throws DeviceManagementException { + /** + * + * @param deviceHTTPEndpoint + * @param urlContext + * @param fireAndForgot + * @return + * @throws DeviceManagementException + */ + public static String sendCommandViaHTTP(final String deviceHTTPEndpoint, String urlContext, boolean fireAndForgot) + throws DeviceManagementException { String responseMsg = ""; String urlString = VirtualFireAlarmConstants.URL_PREFIX + deviceHTTPEndpoint + urlContext; @@ -156,8 +171,13 @@ public class VirtualFireAlarmServiceUtils { /* This methods creates and returns a http connection object */ - public static HttpURLConnection getHttpConnection(String urlString) throws - DeviceManagementException { + /** + * + * @param urlString + * @return + * @throws DeviceManagementException + */ + public static HttpURLConnection getHttpConnection(String urlString) throws DeviceManagementException { URL connectionUrl = null; HttpURLConnection httpConnection; @@ -221,6 +241,13 @@ public class VirtualFireAlarmServiceUtils { return completeResponse.toString(); } + /** + * + * @param owner + * @param deviceId + * @param temperature + * @return + */ public static boolean publishToDAS(String owner, String deviceId, float temperature) { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); @@ -242,8 +269,14 @@ public class VirtualFireAlarmServiceUtils { return true; } - - + /** + * + * @param message + * @param encryptionKey + * @param signatureKey + * @return + * @throws VirtualFireAlarmException + */ public static String prepareSecurePayLoad(String message, Key encryptionKey, PrivateKey signatureKey) throws VirtualFireAlarmException { String encryptedMsg = SecurityManager.encryptMessage(message, encryptionKey); @@ -256,7 +289,14 @@ public class VirtualFireAlarmServiceUtils { return jsonPayload.toString(); } - + /** + * + * @param message + * @param decryptionKey + * @param verifySignatureKey + * @return + * @throws VirtualFireAlarmException + */ public static String extractMessageFromPayload(String message, Key decryptionKey, PublicKey verifySignatureKey) throws VirtualFireAlarmException { String actualMessage; @@ -282,7 +322,12 @@ public class VirtualFireAlarmServiceUtils { return actualMessage; } - + /** + * + * @param deviceId + * @return + * @throws VirtualFireAlarmException + */ public static PublicKey getDevicePublicKey(String deviceId) throws VirtualFireAlarmException { PublicKey clientPublicKey; String alias = ""; diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/scep/SCEPOperation.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/scep/SCEPOperation.java index 9ad390e5d8..5434816b75 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/scep/SCEPOperation.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/scep/SCEPOperation.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/sensormgt/SensorDataManager.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/sensormgt/SensorDataManager.java index f891a25756..c8edf98722 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/sensormgt/SensorDataManager.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/sensormgt/SensorDataManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except