statistical defects fixed 47/19047/3
authorJung Seungho <shonest.jung@samsung.com>
Mon, 17 Apr 2017 08:12:10 +0000 (17:12 +0900)
committerJee Hyeok Kim <jihyeok13.kim@samsung.com>
Mon, 24 Apr 2017 01:36:55 +0000 (01:36 +0000)
Change-Id: Id600550ead3fc240e6d266c945650792754dba21
Signed-off-by: Jung Seungho <shonest.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19047
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Jee Hyeok Kim <jihyeok13.kim@samsung.com>
21 files changed:
cloud/account/src/main/java/org/iotivity/cloud/accountserver/Constants.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/MongoDB.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/AccountResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupAclManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupBrokerManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/id/Acl.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/id/AclResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/verify/AclVerifyResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/credprov/crl/CrlManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/credprov/crl/CrlResource.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/DeviceServerSystem.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/RouteResource.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/DevicePresence.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourcePresence.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/kafka/KafkaConsumerWrapper.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/resources/MQBrokerResource.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/topic/Topic.java
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/db/DBManager.java
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/db/MongoDB.java
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/presence/PresenceManager.java

index c8ca7dc..e75c2b6 100644 (file)
@@ -58,6 +58,8 @@ public class Constants extends OICConstants {
 
     // Database table key
 
+    public static final String RESP_GROUP_PERMISSION      = "gp";
+
     public static final String KEYFIELD_SN                = "serialNumber";
 
     public static final String KEYFIELD_NA                = "notAfter";
index a79d027..9e522d5 100644 (file)
  */
 package org.iotivity.cloud.accountserver.db;
 
-import java.util.List;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -276,7 +276,7 @@ public class MongoDB {
             Document doc) {
 
         if (tableName == null || doc == null)
-            return null;
+            return new ArrayList<>();
 
         MongoCollection<Document> collection = db.getCollection(tableName);
         MongoCursor<Document> cursor = collection.find(doc).iterator();
@@ -306,7 +306,8 @@ public class MongoDB {
 
         while (entryIter.hasNext()) {
 
-            Map.Entry<String, Object> entry = (Map.Entry<String, Object>) entryIter.next();
+            Map.Entry<String, Object> entry = (Map.Entry<String, Object>) entryIter
+                    .next();
 
             String entryKey = entry.getKey();
 
@@ -314,13 +315,15 @@ public class MongoDB {
             if (entry.getValue() != null && !entryKey.equals("_id")) {
 
                 // if value is Array
-                if (entry.getValue() instanceof List && !((List) entry.getValue()).isEmpty()
+                if (entry.getValue() instanceof List
+                        && !((List) entry.getValue()).isEmpty()
                         && ((List) entry.getValue()).get(0) instanceof Document)
 
                 {
                     List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
 
-                    for (Document document : (List<Document>) entry.getValue()) {
+                    for (Document document : (List<Document>) entry
+                            .getValue()) {
                         list.add(convertDocumentToHashMap(document));
                     }
                     resourceMap.put(entry.getKey(), list);
index 811fbbc..5f67c93 100644 (file)
@@ -125,10 +125,6 @@ public class AccountResource extends Resource {
 
     private IResponse handleGetSearch(IRequest request) {
 
-        if (!request.getUriPath().equals(Constants.ACCOUNT_SEARCH_FULL_URI)) {
-            throw new BadRequestException("invalid request uri");
-        }
-
         HashMap<String, List<String>> queryData = request.getUriQueryMap();
 
         if (queryData == null) {
@@ -137,9 +133,11 @@ public class AccountResource extends Resource {
 
         HashMap<String, Object> responsePayload = null;
 
+        String uriQuery = request.getUriQuery();
+
         // AND or OR operation to find users
-        if (request.getUriQuery().contains(",")) {
-            queryData = mAsManager.getQueryMap(request.getUriQuery(), ",");
+        if (uriQuery != null && uriQuery.contains(",")) {
+            queryData = mAsManager.getQueryMap(uriQuery, ",");
             responsePayload = (mAsManager.searchUserUsingCriteria(queryData,
                     SearchOperation.AND));
         } else {
index 42a8935..c302c83 100644 (file)
@@ -274,9 +274,6 @@ public class GroupAclManager {
         ArrayList<AceTable> getAceTableList = new ArrayList<>();
         ArrayList<HashMap<String, Object>> getAceList = AccountDBManager
                 .getInstance().selectRecord(Constants.ACE_TABLE, condition);
-        if (getAceList == null) {
-            return null;
-        }
         for (HashMap<String, Object> getAce : getAceList) {
             AceTable getAceTable = new AceTable();
             getAceTable = mTypeAceTable.convertMaptoObject(getAce, getAceTable);
index 820f62e..f675585 100644 (file)
@@ -51,7 +51,7 @@ public class GroupBrokerManager {
         return mGroupBrokerMgr;
     }
 
-    private class GroupSubscriber {
+    private static class GroupSubscriber {
         GroupSubscriber(Device subscriber, IRequest request) {
             mSubscriber = subscriber;
             mRequest = request;
index 62dfc3e..3f06327 100644 (file)
 package org.iotivity.cloud.accountserver.resources.acl.id;
 
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.UUID;
 import java.util.ListIterator;
+import java.util.UUID;
 
 import org.iotivity.cloud.accountserver.Constants;
 import org.iotivity.cloud.accountserver.db.AccountDBManager;
@@ -48,11 +45,11 @@ import org.iotivity.cloud.util.Log;
 
 public class Acl {
 
-    private Cbor<HashMap<String, Object>>  mCbor      = new Cbor<>();
-    private String                         mAclid     = null;
-    private String                         mOid       = null;
-    private String                         mDi        = null;
-    private TypeCastingManager<AclTable> mTypeAcl = new TypeCastingManager<>();
+    private Cbor<HashMap<String, Object>> mCbor    = new Cbor<>();
+    private String                        mAclid   = null;
+    private String                        mOid     = null;
+    private String                        mDi      = null;
+    private TypeCastingManager<AclTable>  mTypeAcl = new TypeCastingManager<>();
 
     public Acl(String aclid) {
         mAclid = aclid;
@@ -64,138 +61,140 @@ public class Acl {
         mDi = di;
     }
 
-    private class AclSubscriber {
+    private static class AclSubscriber {
         AclSubscriber(Device subscriber, IRequest request) {
             mSubscriber = subscriber;
             mRequest = request;
         }
 
-        public Device mSubscriber;
+        public Device   mSubscriber;
         public IRequest mRequest;
     }
 
-    private HashMap<String, AclSubscriber> mSubscribers  = new HashMap<>();
+    private HashMap<String, AclSubscriber> mSubscribers = new HashMap<>();
 
     public static String valueOf(Object object) {
         return (object == null) ? "" : object.toString();
     }
 
     @SuppressWarnings("unchecked")
-        public static AclTable convertMaptoAclObject(HashMap<String, Object> aclMap) {
-            AclTable aclTable = new AclTable();
-            try {
-                aclTable.setAclid(valueOf(aclMap.get(Constants.KEYFIELD_ACLID)));
-                aclTable.setDi(valueOf(aclMap.get(Constants.KEYFIELD_DI)));
-                aclTable.setOid(valueOf(aclMap.get(Constants.REQ_OWNER_ID)));
-                aclTable.setRowneruuid(valueOf(aclMap.get(Constants.REQ_ROWNER_ID)));
-
-                List<Ace> aceList = new ArrayList<Ace>();
-
-                List<HashMap<String, Object>> aclist = (List<HashMap<String, Object>>) aclMap
+    public static AclTable convertMaptoAclObject(
+            HashMap<String, Object> aclMap) {
+        AclTable aclTable = new AclTable();
+        try {
+            aclTable.setAclid(valueOf(aclMap.get(Constants.KEYFIELD_ACLID)));
+            aclTable.setDi(valueOf(aclMap.get(Constants.KEYFIELD_DI)));
+            aclTable.setOid(valueOf(aclMap.get(Constants.REQ_OWNER_ID)));
+            aclTable.setRowneruuid(
+                    valueOf(aclMap.get(Constants.REQ_ROWNER_ID)));
+
+            List<Ace> aceList = new ArrayList<Ace>();
+
+            List<HashMap<String, Object>> aclist = (List<HashMap<String, Object>>) aclMap
                     .get(Constants.REQ_ACL_LIST);
 
-                if (aclist == null) {
-                    return aclTable;
-                }
+            if (aclist == null) {
+                return aclTable;
+            }
 
-                for (HashMap<String, Object> eachAce : aclist) {
+            for (HashMap<String, Object> eachAce : aclist) {
 
-                    Ace ace = new Ace();
+                Ace ace = new Ace();
 
-                    ace.setAceid(valueOf(eachAce.get(Constants.REQ_ACE_ID)));
-                    ace.setSubjectuuid(valueOf(eachAce
-                                .get(Constants.KEYFIELD_ACE_SUBJECT_ID)));
-                    ace.setStype(Integer.valueOf(eachAce.get(
-                                    Constants.KEYFIELD_ACE_SUBJECT_TYPE).toString()));
-                    ace.setPermission(Integer.valueOf(eachAce.get(
-                                    Constants.KEYFIELD_ACE_PERMISSION).toString()));
+                ace.setAceid(valueOf(eachAce.get(Constants.REQ_ACE_ID)));
+                ace.setSubjectuuid(valueOf(
+                        eachAce.get(Constants.KEYFIELD_ACE_SUBJECT_ID)));
+                ace.setStype(Integer.valueOf(eachAce
+                        .get(Constants.KEYFIELD_ACE_SUBJECT_TYPE).toString()));
+                ace.setPermission(Integer.valueOf(eachAce
+                        .get(Constants.KEYFIELD_ACE_PERMISSION).toString()));
 
-                    Object validity = eachAce.get(Constants.KEYFIELD_ACE_VALIDITY);
-                    if (validity != null) {
-                        ace.setValidity((List<String>) validity);
-                    }
+                Object validity = eachAce.get(Constants.KEYFIELD_ACE_VALIDITY);
+                if (validity != null) {
+                    ace.setValidity((List<String>) validity);
+                }
 
-                    List<AceResource> resourceLst = new ArrayList<AceResource>();
-                    List<HashMap<String, Object>> resourceList = (List<HashMap<String, Object>>) eachAce
+                List<AceResource> resourceLst = new ArrayList<AceResource>();
+                List<HashMap<String, Object>> resourceList = (List<HashMap<String, Object>>) eachAce
                         .get(Constants.KEYFIELD_ACE_RESOURCE);
-                    for (HashMap<String, Object> resrouce : resourceList) {
+                for (HashMap<String, Object> resrouce : resourceList) {
 
-                        AceResource aceResource = new AceResource();
-                        aceResource.setHref(valueOf(resrouce
-                                    .get(Constants.KEYFIELD_ACE_RESOURCE_HREF)));
-                        List<String> rtList = (List<String>) resrouce
+                    AceResource aceResource = new AceResource();
+                    aceResource.setHref(valueOf(resrouce
+                            .get(Constants.KEYFIELD_ACE_RESOURCE_HREF)));
+                    List<String> rtList = (List<String>) resrouce
                             .get(Constants.KEYFIELD_ACE_RESOURCE_RT);
-                        aceResource.setRt(rtList);
-                        List<String> ifList = (List<String>) resrouce
+                    aceResource.setRt(rtList);
+                    List<String> ifList = (List<String>) resrouce
                             .get(Constants.KEYFIELD_ACE_RESOURCE_IF);
-                        aceResource.setOicif(ifList);
+                    aceResource.setOicif(ifList);
 
-                        resourceLst.add(aceResource);
-                    }
-                    ace.setResources(resourceLst);
+                    resourceLst.add(aceResource);
+                }
+                ace.setResources(resourceLst);
 
-                    aceList.add(ace);
+                aceList.add(ace);
 
-                }
-                aclTable.setAclist(aceList);
-            } catch (Exception e) {
-                throw new InternalServerErrorException(
-                        "Map to Acl Object casting error " + e.getMessage());
             }
-            return aclTable;
-
+            aclTable.setAclist(aceList);
+        } catch (Exception e) {
+            throw new InternalServerErrorException(
+                    "Map to Acl Object casting error " + e.getMessage());
         }
+        return aclTable;
+
+    }
 
     @SuppressWarnings("unchecked")
 
-        public List<HashMap<String, Object>> addACE(List<HashMap<String, Object>> aclist) {
-            Log.v("IN addACE");
-            HashMap<String, Object> hashmap = AccountDBManager.getInstance()
+    public List<HashMap<String, Object>> addACE(
+            List<HashMap<String, Object>> aclist) {
+        Log.v("IN addACE");
+        HashMap<String, Object> hashmap = AccountDBManager.getInstance()
                 .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
-            if (hashmap == null) {
-                throw new BadRequestException("aclid is invalid");
-            }
-            List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap
+        if (hashmap == null) {
+            throw new BadRequestException("aclid is invalid");
+        }
+        List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap
                 .get(Constants.REQ_ACL_LIST);
 
-
-            ListIterator<HashMap<String, Object>> iterator = aclist.listIterator();
-            while (iterator.hasNext()) {
-                HashMap<String, Object> aceMap = iterator.next();
-                if (aceMap.get(Constants.KEYFIELD_ACE_SUBJECT_ID)
-                        .equals(hashmap.get(Constants.REQ_OWNER_ID))) {
-                    // remove current iterator
-                    iterator.remove();
-                    continue;
-                }
-                aceMap.put(Constants.REQ_ACE_ID, UUID.randomUUID().toString());
+        ListIterator<HashMap<String, Object>> iterator = aclist.listIterator();
+        while (iterator.hasNext()) {
+            HashMap<String, Object> aceMap = iterator.next();
+            if (aceMap.get(Constants.KEYFIELD_ACE_SUBJECT_ID)
+                    .equals(hashmap.get(Constants.REQ_OWNER_ID))) {
+                // remove current iterator
+                iterator.remove();
+                continue;
             }
+            aceMap.put(Constants.REQ_ACE_ID, UUID.randomUUID().toString());
+        }
 
-            List<HashMap<String, Object>> newAcList = new ArrayList<HashMap<String, Object>>(
-                    aclist);
+        List<HashMap<String, Object>> newAcList = new ArrayList<HashMap<String, Object>>(
+                aclist);
 
-            if (aclDbList != null) {
-                newAcList.addAll(aclDbList);
-            }
-            hashmap.put(Constants.REQ_ACL_LIST, newAcList);
-            AccountDBManager.getInstance().updateRecord(Constants.ACL_TABLE,
-                    hashmap);
-            notifyToSubscriber(getResponsePayload(true));
-            Log.v("OUT addACE");
-            return aclist;
+        if (aclDbList != null) {
+            newAcList.addAll(aclDbList);
         }
+        hashmap.put(Constants.REQ_ACL_LIST, newAcList);
+        AccountDBManager.getInstance().updateRecord(Constants.ACL_TABLE,
+                hashmap);
+        notifyToSubscriber(getResponsePayload(true));
+        Log.v("OUT addACE");
+        return aclist;
+    }
 
     public HashMap<String, Object> getACE(String aceid) {
         HashMap<String, Object> hashmap = AccountDBManager.getInstance()
-            .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
+                .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
         if (hashmap == null) {
             throw new BadRequestException("aclid is invalid");
         }
 
         List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap
-            .get(Constants.REQ_ACL_LIST);
+                .get(Constants.REQ_ACL_LIST);
         ListIterator<HashMap<String, Object>> iterator = aclDbList
-            .listIterator();
+                .listIterator();
         while (iterator.hasNext()) {
             HashMap<String, Object> aceMap = iterator.next();
             if (aceMap.get(Constants.REQ_ACE_ID).equals(aceid)) {
@@ -205,17 +204,18 @@ public class Acl {
         }
         throw new BadRequestException("aceid is invalid");
     }
+
     public boolean isValidAceId(String aceid) {
         HashMap<String, Object> hashmap = AccountDBManager.getInstance()
-            .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
+                .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
         if (hashmap == null) {
             return false;
         }
 
         List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap
-            .get(Constants.REQ_ACL_LIST);
+                .get(Constants.REQ_ACL_LIST);
         ListIterator<HashMap<String, Object>> iterator = aclDbList
-            .listIterator();
+                .listIterator();
         while (iterator.hasNext()) {
             HashMap<String, Object> aceMap = iterator.next();
             if (aceMap.get(Constants.REQ_ACE_ID).equals(aceid)) {
@@ -224,17 +224,20 @@ public class Acl {
         }
         return false;
     }
+
     public void updateACE(String aceid, HashMap<String, Object> ace) {
         Log.v("IN updateACE");
 
         HashMap<String, Object> hashmap = AccountDBManager.getInstance()
-            .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
+                .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
 
-        List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap.get(Constants.REQ_ACL_LIST);
+        List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap
+                .get(Constants.REQ_ACL_LIST);
 
         ace.put(Constants.REQ_ACE_ID, aceid);
 
-        ListIterator<HashMap<String, Object>> iterator = aclDbList.listIterator();
+        ListIterator<HashMap<String, Object>> iterator = aclDbList
+                .listIterator();
         while (iterator.hasNext()) {
             HashMap<String, Object> aceMap = iterator.next();
             if (aceMap.get(Constants.REQ_ACE_ID).equals(aceid)) {
@@ -245,7 +248,8 @@ public class Acl {
         }
 
         hashmap.put(Constants.REQ_ACL_LIST, aclDbList);
-        AccountDBManager.getInstance().updateRecord(Constants.ACL_TABLE, hashmap);
+        AccountDBManager.getInstance().updateRecord(Constants.ACL_TABLE,
+                hashmap);
         notifyToSubscriber(getResponsePayload(true));
         Log.v("OUT updateACE");
 
@@ -254,13 +258,13 @@ public class Acl {
     public void deleteACE(String aceid) {
 
         HashMap<String, Object> hashmap = AccountDBManager.getInstance()
-            .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
+                .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
 
         List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap
-            .get(Constants.REQ_ACL_LIST);
-
+                .get(Constants.REQ_ACL_LIST);
 
-        ListIterator<HashMap<String, Object>> iterator = aclDbList.listIterator();
+        ListIterator<HashMap<String, Object>> iterator = aclDbList
+                .listIterator();
         while (iterator.hasNext()) {
             HashMap<String, Object> aceMap = iterator.next();
             if (aceMap.get(Constants.REQ_ACE_ID).equals(aceid)) {
@@ -280,7 +284,7 @@ public class Acl {
         AclTable aclTable = getAclTable();
         aclTable.setAclist(null);
         AccountDBManager.getInstance().updateRecord(Constants.ACL_TABLE,
-            mTypeAcl.convertObjectToMap(aclTable));
+                mTypeAcl.convertObjectToMap(aclTable));
         notifyToSubscriber(getResponsePayload(true));
     }
 
@@ -314,7 +318,7 @@ public class Acl {
         String mDi = aclTable.getDi();
         if (!mDi.equals(di)) {
             throw new UnAuthorizedException(
-                di + "is not Device ID of this ACL");
+                    di + "is not Device ID of this ACL");
         }
     }
 
@@ -323,31 +327,30 @@ public class Acl {
         synchronized (mSubscribers) {
 
             Iterator<String> iterator = mSubscribers.keySet().iterator();
-            while(iterator.hasNext()) {
+            while (iterator.hasNext()) {
                 String key = iterator.next();
                 AclSubscriber aclSubscriber = mSubscribers.get(key);
                 aclSubscriber.mSubscriber.sendResponse(
-                    MessageBuilder.createResponse(aclSubscriber.mRequest,
-                        ResponseStatus.CONTENT,
-                        ContentFormat.APPLICATION_CBOR,
-                        mCbor.encodingPayloadToCbor(
-                            notifyBytePayloadData)));
+                        MessageBuilder.createResponse(aclSubscriber.mRequest,
+                                ResponseStatus.CONTENT,
+                                ContentFormat.APPLICATION_CBOR,
+                                mCbor.encodingPayloadToCbor(
+                                        notifyBytePayloadData)));
             }
         }
     }
 
     private AclTable getAclTable() {
         AclTable getAclTable = new AclTable();
-        getAclTable = convertMaptoAclObject(
-                AccountDBManager.getInstance().selectRecord(
-                    Constants.ACL_TABLE, getCondition()).get(0));
+        getAclTable = convertMaptoAclObject(AccountDBManager.getInstance()
+                .selectRecord(Constants.ACL_TABLE, getCondition()).get(0));
         return getAclTable;
     }
 
     private HashMap<String, Object> getAclTablePayLoad() {
         HashMap<String, Object> aclPayload = new HashMap<>();
         aclPayload = AccountDBManager.getInstance()
-            .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
+                .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
         return aclPayload;
     }
 
@@ -361,5 +364,4 @@ public class Acl {
         return condition;
     }
 
-
 }
index 8a0e91a..a7e4215 100644 (file)
@@ -88,10 +88,14 @@ public class AclResource extends Resource {
             throws ServerException {
 
         if (getUriPathSegments().containsAll(request.getUriPathSegments())) {
-            String oid = request.getUriQueryMap().get(Constants.REQ_OWNER_ID)
-                    .get(0);
-            String di = request.getUriQueryMap().get(Constants.REQ_DEVICE_ID)
-                    .get(0);
+            HashMap<String, List<String>> queryMap = request.getUriQueryMap();
+
+            checkQueryException(Arrays.asList(Constants.REQ_OWNER_ID,
+                    Constants.REQ_DEVICE_ID), queryMap);
+
+            String oid = queryMap.get(Constants.REQ_OWNER_ID).get(0);
+            String di = queryMap.get(Constants.REQ_DEVICE_ID).get(0);
+
             if (mAclManager.getAclid(di) == null) {
                 return MessageBuilder.createResponse(request,
                         ResponseStatus.CREATED, ContentFormat.APPLICATION_CBOR,
@@ -116,13 +120,26 @@ public class AclResource extends Resource {
         HashMap<String, Object> payloadData = mCbor
                 .parsePayloadFromCbor(request.getPayload(), HashMap.class);
 
-        if (null != request.getUriQueryMap()) {
+        HashMap<String, List<String>> queryMap = request.getUriQueryMap();
+
+        if (null != queryMap) {
             String aclid = request.getUriPathSegments()
                     .get(getUriPathSegments().size());
-            String aceid = request.getUriQueryMap().get(Constants.REQ_ACE_ID)
-                    .get(0);
+
+            checkQueryException(Constants.REQ_ACE_ID, queryMap);
+
+            String aceid = queryMap.get(Constants.REQ_ACE_ID).get(0);
+
+            checkPayloadException(Constants.REQ_ACL_LIST, payloadData);
+
             List<HashMap<String, Object>> aclist = (List<HashMap<String, Object>>) payloadData
                     .get(Constants.REQ_ACL_LIST);
+
+            if (aclist == null) {
+                throw new BadRequestException(
+                        Constants.REQ_ACL_LIST + " payload value is null");
+            }
+
             mAclManager.updateACE(aclid, aceid, aclist.get(0));
             return MessageBuilder.createResponse(request,
                     ResponseStatus.CHANGED);
@@ -153,8 +170,10 @@ public class AclResource extends Resource {
 
         HashMap<String, Object> responsePayload = null;
         String di = null;
-
+        HashMap<String, List<String>> queryMap = request.getUriQueryMap();
         if (getUriPathSegments().containsAll(request.getUriPathSegments())) {
+            checkQueryException(Arrays.asList(Constants.REQ_DEVICE_ID),
+                    queryMap);
             di = request.getUriQueryMap().get(Constants.REQ_DEVICE_ID).get(0);
             if (di == null) {
                 throw new PreconditionFailedException("di is invalid");
@@ -168,14 +187,16 @@ public class AclResource extends Resource {
                     responsePayload = mAclManager.getAclInfo(aclid);
                     break;
                 case SUBSCRIBE:
-                    di = request.getUriQueryMap().get(Constants.REQ_DEVICE_ID)
-                            .get(0);
+                    checkQueryException(Arrays.asList(Constants.REQ_DEVICE_ID),
+                            queryMap);
+                    di = queryMap.get(Constants.REQ_DEVICE_ID).get(0);
                     responsePayload = mAclManager.addAclSubscriber(aclid, di,
                             srcDevice, request);
                     break;
                 case UNSUBSCRIBE:
-                    di = request.getUriQueryMap().get(Constants.REQ_DEVICE_ID)
-                            .get(0);
+                    checkQueryException(Arrays.asList(Constants.REQ_DEVICE_ID),
+                            queryMap);
+                    di = queryMap.get(Constants.REQ_DEVICE_ID).get(0);
                     responsePayload = mAclManager.removeAclSubscriber(aclid,
                             di);
                     break;
index 9a87ce0..1e46db8 100644 (file)
@@ -48,7 +48,7 @@ public class InviteManager {
 
     private TypeCastingManager<InviteTable> mTypeInvite = new TypeCastingManager<>();
 
-    private class InviteSubscriber {
+    private static class InviteSubscriber {
         InviteSubscriber(Device subscriber, IRequest request) {
             mSubscriber = subscriber;
             mRequest = request;
index 50e0720..bc83ef3 100644 (file)
@@ -32,11 +32,9 @@ import org.iotivity.cloud.accountserver.db.AclTable;
 import org.iotivity.cloud.accountserver.resources.acl.id.Ace;
 import org.iotivity.cloud.accountserver.resources.acl.id.AceResource;
 import org.iotivity.cloud.accountserver.resources.acl.id.Acl;
-import org.iotivity.cloud.accountserver.util.TypeCastingManager;
 import org.iotivity.cloud.base.device.Device;
 import org.iotivity.cloud.base.exception.ServerException;
 import org.iotivity.cloud.base.exception.ServerException.BadRequestException;
-import org.iotivity.cloud.base.exception.ServerException.PreconditionFailedException;
 import org.iotivity.cloud.base.protocols.IRequest;
 import org.iotivity.cloud.base.protocols.IResponse;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
@@ -51,119 +49,123 @@ public class AclVerifyResource extends Resource {
 
     public AclVerifyResource() {
         super(Arrays.asList(Constants.PREFIX_OIC, Constants.ACL_URI,
-                    Constants.VERIFY_URI));
+                Constants.VERIFY_URI));
     }
 
     @Override
-        public void onDefaultRequestReceived(Device srcDevice, IRequest request)
-        throws ServerException {
-
-            IResponse response = null;
-
-            switch (request.getMethod()) {
-                case GET:
-                    response = handleGetRequest(request);
-                    break;
-                default:
-                    throw new BadRequestException(request.getMethod()
-                            + " request type is not supported");
-            }
-
-            srcDevice.sendResponse(response);
+    public void onDefaultRequestReceived(Device srcDevice, IRequest request)
+            throws ServerException {
+
+        IResponse response = null;
+
+        switch (request.getMethod()) {
+            case GET:
+                response = handleGetRequest(request);
+                break;
+            default:
+                throw new BadRequestException(
+                        request.getMethod() + " request type is not supported");
         }
 
+        srcDevice.sendResponse(response);
+    }
+
     private boolean checkPermission(int permissionValue, String rme)
-        throws ServerException {
-            Permission per = null;
-            int rm_value = 0;
-            if (rme.equals("get")) {
-                per = Permission.Read;
-            } else if (rme.equals("post")) {
-                per = Permission.Update;
-            } else if (rme.equals("delete")) {
-                per = Permission.Delete;
-            }
-            if (per != null) {
-                rm_value = per.getValue();
-            }
-            // bit and operation
-            return ((permissionValue & rm_value) == rm_value);
+            throws ServerException {
+        Permission per = null;
+        int rm_value = 0;
+        if (rme.equals("get")) {
+            per = Permission.Read;
+        } else if (rme.equals("post")) {
+            per = Permission.Update;
+        } else if (rme.equals("delete")) {
+            per = Permission.Delete;
+        }
+        if (per != null) {
+            rm_value = per.getValue();
         }
+        // bit and operation
+        return ((permissionValue & rm_value) == rm_value);
+    }
 
     private boolean checkResourceUri(List<AceResource> aceResources, String uri)
-        throws ServerException {
-            for (AceResource aceResource : aceResources) {
-                if (aceResource.getHref().trim().equals("*") || aceResource.getHref().equals(uri)) {
-                    return true;
-                }
+            throws ServerException {
+        for (AceResource aceResource : aceResources) {
+            if (aceResource.getHref().trim().equals("*")
+                    || aceResource.getHref().equals(uri)) {
+                return true;
             }
-            return false;
         }
+        return false;
+    }
 
     private boolean verifyAcl(String sid, String di, String rm, String uri)
-        throws ServerException {
+            throws ServerException {
 
-            HashMap<String, Object> condition = new HashMap<>();
-            condition.put(Constants.KEYFIELD_DI, di);
+        HashMap<String, Object> condition = new HashMap<>();
+        condition.put(Constants.KEYFIELD_DI, di);
 
-            // Query AclTable with condition deviceId(di)
-            ArrayList<HashMap<String, Object>> aclResult = AccountDBManager
+        // Query AclTable with condition deviceId(di)
+        ArrayList<HashMap<String, Object>> aclResult = AccountDBManager
                 .getInstance().selectRecord(Constants.ACL_TABLE, condition);
 
-            // if aclResult size is zero then (di) does not exist
-            if (aclResult == null || aclResult.size() == 0) {
-                return false;
-            }
+        // if aclResult size is zero then (di) does not exist
+        if (aclResult == null || aclResult.size() == 0) {
+            return false;
+        }
 
-            for (HashMap<String, Object> eachAclMap : aclResult) {
+        for (HashMap<String, Object> eachAclMap : aclResult) {
 
-                AclTable aclTable = Acl.convertMaptoAclObject(eachAclMap);
-                if (aclTable.getOid().equals(sid)) {
-                    return true;
-                }
-                if (aclTable.getAclist() == null) {
-                    return false;
-                }
+            AclTable aclTable = Acl.convertMaptoAclObject(eachAclMap);
+            if (aclTable.getOid().equals(sid)) {
+                return true;
+            }
+            if (aclTable.getAclist() == null) {
+                return false;
+            }
 
-                for (Ace ace : aclTable.getAclist()) {
-                    if (ace.getSubjectuuid().equals(sid)) {
-                        // check permission matches
-                        if (checkPermission(ace.getPermission(), rm.toLowerCase())) {
-                            // check resource uri matches
-                            if (checkResourceUri(ace.getResources(), uri)) {
-                                return true;
-                            }
+            for (Ace ace : aclTable.getAclist()) {
+                if (ace.getSubjectuuid().equals(sid)) {
+                    // check permission matches
+                    if (checkPermission(ace.getPermission(),
+                            rm.toLowerCase())) {
+                        // check resource uri matches
+                        if (checkResourceUri(ace.getResources(), uri)) {
+                            return true;
                         }
                     }
                 }
             }
-            return false;
         }
+        return false;
+    }
 
-    private IResponse handleGetRequest(IRequest request) throws ServerException {
+    private IResponse handleGetRequest(IRequest request)
+            throws ServerException {
 
         String sid = null;
         String di = null;
         String rm = null;
         String uri = null;
 
-        if (getUriPathSegments().containsAll(request.getUriPathSegments())) {
-            sid = request.getUriQueryMap().get(Constants.REQ_SEARCH_USER_ID)
-                .get(0);
-            di = request.getUriQueryMap().get(Constants.REQ_DEVICE_ID).get(0);
-            rm = request.getUriQueryMap().get(Constants.REQ_REQUEST_METHOD)
-                .get(0);
-            uri = request.getUriQueryMap().get(Constants.REQ_REQUEST_URI)
-                .get(0);
-        } else {
-            throw new BadRequestException("uriPath is invalid");
-        }
+        HashMap<String, List<String>> queryMap = request.getUriQueryMap();
+
+        checkQueryException(Arrays.asList(Constants.REQ_SEARCH_USER_ID,
+                Constants.REQ_DEVICE_ID, Constants.REQ_REQUEST_METHOD,
+                Constants.REQ_REQUEST_URI), queryMap);
+
+        sid = queryMap.get(Constants.REQ_SEARCH_USER_ID).get(0);
+        di = queryMap.get(Constants.REQ_DEVICE_ID).get(0);
+        rm = queryMap.get(Constants.REQ_REQUEST_METHOD).get(0);
+        uri = queryMap.get(Constants.REQ_REQUEST_URI).get(0);
 
         HashMap<String, Object> responsePayload = new HashMap<>();
         if (verifyAcl(sid, di, rm, uri)) {
-            responsePayload.put("gp", Constants.RESP_ACL_ALLOWED);
+            responsePayload.put(Constants.RESP_GROUP_PERMISSION,
+                    Constants.RESP_ACL_ALLOWED);
         } else {
-            responsePayload.put("gp", Constants.RESP_ACL_DENIED);
+            responsePayload.put(Constants.RESP_GROUP_PERMISSION,
+                    Constants.RESP_ACL_DENIED);
         }
 
         return MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
index ca61263..32b6ce9 100644 (file)
  */
 package org.iotivity.cloud.accountserver.resources.credprov.crl;
 
-import org.bouncycastle.operator.OperatorCreationException;
-import org.bson.types.Binary;
-import org.iotivity.cloud.accountserver.Constants;
-import org.iotivity.cloud.accountserver.db.CRLTable;
-import org.iotivity.cloud.accountserver.util.TypeCastingManager;
-import org.iotivity.cloud.base.exception.ServerException;
-import org.iotivity.cloud.util.Log;
+import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.ACCOUNT_DB_MANAGER;
+import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.CERTIFICATE_FACTORY;
+import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.DER;
+import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.NEXT_UPDATE_INTERVAL;
+import static org.iotivity.cloud.accountserver.x509.crl.CrlIssuer.CRL_ISSUER;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.security.cert.CRLException;
 import java.security.cert.X509CRL;
 import java.text.ParseException;
-import java.util.*;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
-import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.*;
-import static org.iotivity.cloud.accountserver.x509.crl.CrlIssuer.CRL_ISSUER;
+import org.bouncycastle.operator.OperatorCreationException;
+import org.bson.types.Binary;
+import org.iotivity.cloud.accountserver.Constants;
+import org.iotivity.cloud.accountserver.db.CRLTable;
+import org.iotivity.cloud.accountserver.util.TypeCastingManager;
+import org.iotivity.cloud.base.exception.ServerException;
+import org.iotivity.cloud.util.Log;
 
 /**
- * Class is used to manage CRLs. It helps to create,
- * update CRLS, revoke certificates.
+ * Class is used to manage CRLs. It helps to create, update CRLS, revoke
+ * certificates.
  */
 public final class CrlManager {
 
@@ -53,12 +62,12 @@ public final class CrlManager {
     /**
      * X509 CRL presentation.
      */
-    private X509CRL x509CRL;
+    private X509CRL                             x509CRL;
 
     /**
      * Static manager for CRLs.
      */
-    public static final CrlManager CRL_MANAGER = new CrlManager();
+    public static final CrlManager              CRL_MANAGER    = new CrlManager();
 
     /**
      * Private constructor to make this class non-instantiable.
@@ -69,9 +78,11 @@ public final class CrlManager {
             Date thisUpdate = calendar.getTime();
             calendar.add(Calendar.DAY_OF_MONTH,
                     Integer.parseInt(NEXT_UPDATE_INTERVAL));
-            byte[] data = CRL_ISSUER.generate(thisUpdate, calendar.getTime(), Collections.emptyList());
+            byte[] data = CRL_ISSUER.generate(thisUpdate, calendar.getTime(),
+                    Collections.emptyList());
             ACCOUNT_DB_MANAGER.insertRecord(Constants.CRL_TABLE,
-                    castingManager.convertObjectToMap(new CRLTable(thisUpdate, new Binary(data))));
+                    castingManager.convertObjectToMap(
+                            new CRLTable(thisUpdate, new Binary(data))));
             setX509CRL(data);
         } catch (CRLException | IOException | OperatorCreationException e) {
             Log.e(e.getMessage());
@@ -81,43 +92,53 @@ public final class CrlManager {
     /**
      * Revokes specified serial numbers. Puts them to database.
      *
-     * @param serialNumbers specified var args serial numbers from 0.
+     * @param serialNumbers
+     *            specified var args serial numbers from 0.
      */
-    public void revoke(String... serialNumbers) throws CRLException, IOException, OperatorCreationException {
+    public void revoke(String... serialNumbers)
+            throws CRLException, IOException, OperatorCreationException {
         if (x509CRL != null) {
             update(x509CRL.getThisUpdate(),
-                    CRL_ISSUER.generate(x509CRL.getThisUpdate(), x509CRL.getNextUpdate(),
+                    CRL_ISSUER.generate(x509CRL.getThisUpdate(),
+                            x509CRL.getNextUpdate(),
                             x509CRL.getRevokedCertificates(), serialNumbers));
         }
     }
 
     /**
-     * Checks last update less than crl this update and returns response payload,
-     * including this update, next update, and CRL in DER encoding.
+     * Checks last update less than crl this update and returns response
+     * payload, including this update, next update, and CRL in DER encoding.
      */
-    Map<String, Object> getPayload(String lastUpdate) throws ServerException.PreconditionFailedException, CRLException {
+    Map<String, Object> getPayload(String lastUpdate)
+            throws ServerException.PreconditionFailedException, CRLException {
         if (checkLastUpdate(lastUpdate) && x509CRL != null) {
             Map<String, Object> responsePayload = new HashMap<>();
-            responsePayload.put(Constants.REQ_THIS_UPDATE, DATE_FORMAT.format(x509CRL.getThisUpdate()));
-            responsePayload.put(Constants.REQ_NEXT_UPDATE, DATE_FORMAT.format(x509CRL.getNextUpdate()));
-            responsePayload.put(Constants.REQ_CRL, new CRL(DER, x509CRL.getEncoded()));
+            responsePayload.put(Constants.REQ_THIS_UPDATE,
+                    new SimpleDateFormat("yyyyMMddHHmmss")
+                            .format(x509CRL.getThisUpdate()));
+            responsePayload.put(Constants.REQ_NEXT_UPDATE,
+                    new SimpleDateFormat("yyyyMMddHHmmss")
+                            .format(x509CRL.getNextUpdate()));
+            responsePayload.put(Constants.REQ_CRL,
+                    new CRL(DER, x509CRL.getEncoded()));
             return responsePayload;
         }
         return Collections.emptyMap();
     }
 
-
     /**
      * Checks if last update is before CRL this update.
      *
-     * @param lastUpdate specified last update;
+     * @param lastUpdate
+     *            specified last update;
      * @return true if before and false - otherwise.
      */
     private boolean checkLastUpdate(String lastUpdate) {
         boolean checkCondition = false;
         try {
             if (x509CRL != null) {
-                checkCondition = DATE_FORMAT.parse(lastUpdate).before(x509CRL.getThisUpdate());
+                checkCondition = new SimpleDateFormat("yyyyMMddHHmmss")
+                        .parse(lastUpdate).before(x509CRL.getThisUpdate());
             }
         } catch (ParseException e) {
             Log.e(e.getMessage());
@@ -125,18 +146,19 @@ public final class CrlManager {
         return checkCondition;
     }
 
-
     /**
      * Updates CRLTable with specified this update and binary CRL data.
      */
     void update(Date thisUpdate, byte[] data) throws CRLException {
-        ArrayList<HashMap<String, Object>> crlList = ACCOUNT_DB_MANAGER.selectRecord(Constants.CRL_TABLE,
-                new HashMap<>());
+        ArrayList<HashMap<String, Object>> crlList = ACCOUNT_DB_MANAGER
+                .selectRecord(Constants.CRL_TABLE, new HashMap<>());
         if (crlList != null && !crlList.isEmpty()) {
-            CRLTable crlTable = castingManager.convertMaptoObject(crlList.get(0), new CRLTable());
+            CRLTable crlTable = castingManager
+                    .convertMaptoObject(crlList.get(0), new CRLTable());
             crlTable.setThisUpdate(thisUpdate);
             crlTable.setBinaryData(new Binary(data));
-            ACCOUNT_DB_MANAGER.updateRecord(Constants.CRL_TABLE, castingManager.convertObjectToMap(crlTable));
+            ACCOUNT_DB_MANAGER.updateRecord(Constants.CRL_TABLE,
+                    castingManager.convertObjectToMap(crlTable));
             setX509CRL(data);
         }
     }
@@ -145,7 +167,8 @@ public final class CrlManager {
      * Updates currect x509 CRL state by parsing specified data.
      */
     private void setX509CRL(byte[] data) throws CRLException {
-        x509CRL = (X509CRL) CERTIFICATE_FACTORY.generateCRL(new ByteArrayInputStream(data));
+        x509CRL = (X509CRL) CERTIFICATE_FACTORY
+                .generateCRL(new ByteArrayInputStream(data));
     }
 
     /**
index 13a51a2..fa75701 100644 (file)
  */
 package org.iotivity.cloud.accountserver.resources.credprov.crl;
 
+import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.BASE_64;
+import static org.iotivity.cloud.accountserver.resources.credprov.crl.CrlManager.CRL_MANAGER;
+
+import java.io.IOException;
+import java.security.cert.CRLException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import org.bouncycastle.operator.OperatorCreationException;
 import org.bouncycastle.util.encoders.Base64;
@@ -37,18 +49,8 @@ import org.iotivity.cloud.base.resource.Resource;
 import org.iotivity.cloud.util.Cbor;
 import org.iotivity.cloud.util.Log;
 
-import java.io.IOException;
-import java.security.cert.CRLException;
-import java.text.ParseException;
-import java.util.*;
-
-import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.BASE_64;
-import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.DATE_FORMAT;
-import static org.iotivity.cloud.accountserver.resources.credprov.crl.CrlManager.CRL_MANAGER;
-
 /**
- * Class is used working with POST and GET requests and
- * handles CRL requests.
+ * Class is used working with POST and GET requests and handles CRL requests.
  */
 public class CrlResource extends Resource {
 
@@ -61,8 +63,8 @@ public class CrlResource extends Resource {
      * Creates resource for handling CRL requests(GET and POST)
      */
     public CrlResource() {
-        super(Arrays.asList(Constants.PREFIX_OIC,
-                Constants.CREDPROV_URI, Constants.REQ_CRL));
+        super(Arrays.asList(Constants.PREFIX_OIC, Constants.CREDPROV_URI,
+                Constants.REQ_CRL));
 
     }
 
@@ -78,39 +80,37 @@ public class CrlResource extends Resource {
                 response = handleGetRequest(request);
                 break;
             default:
-                response = MessageBuilder.createResponse(request, ResponseStatus.BAD_REQUEST);
+                response = MessageBuilder.createResponse(request,
+                        ResponseStatus.BAD_REQUEST);
         }
         srcDevice.sendResponse(response);
     }
 
     /**
-     * Method handles GET requests with specified format:
-     * GET /oic/credprov/crl?lu=20170701000000
-     * Checks if “lu” value is not after the latest update.
-     * If so, response with the latest CRL, otherwise response error (e.g. 4.04 Not Found)
-     * And response of next format:
-     * 2.05 CONTENTS
-     * {
-     *      “tu” : “20160711000000”,
-     *      “nu” : “20161011000000”,
-     *      “crl” : {
-     *          “encoding” : “oic.sec.encoding.base64”,
-     *          “data” : “<Base64 encoded CRL Binary>”
-     *       }
-     * }
+     * Method handles GET requests with specified format: GET
+     * /oic/credprov/crl?lu=20170701000000 Checks if “lu” value is not after the
+     * latest update. If so, response with the latest CRL, otherwise response
+     * error (e.g. 4.04 Not Found) And response of next format: 2.05 CONTENTS {
+     * “tu” : “20160711000000”, “nu” : “20161011000000”, “crl” : { “encoding” :
+     * “oic.sec.encoding.base64”, “data” : “<Base64 encoded CRL Binary>” } }
      */
     private IResponse handleGetRequest(IRequest request)
             throws ServerException {
         HashMap<String, List<String>> queryData = request.getUriQueryMap();
-        IResponse iResponse = MessageBuilder.createResponse(request, ResponseStatus.NOT_FOUND);
+        IResponse iResponse = MessageBuilder.createResponse(request,
+                ResponseStatus.NOT_FOUND);
         if (queryData != null) {
-            List<String> lastUpdateList = queryData.get(Constants.REQ_LAST_UPDATE);
+            List<String> lastUpdateList = queryData
+                    .get(Constants.REQ_LAST_UPDATE);
             if (lastUpdateList != null && !lastUpdateList.isEmpty()) {
                 try {
-                    Map<String, Object> payload = CRL_MANAGER.getPayload(lastUpdateList.get(0));
+                    Map<String, Object> payload = CRL_MANAGER
+                            .getPayload(lastUpdateList.get(0));
                     if (!payload.isEmpty()) {
-                        iResponse = MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
-                                ContentFormat.APPLICATION_CBOR, MAP_CBOR.encodingPayloadToCbor(payload));
+                        iResponse = MessageBuilder.createResponse(request,
+                                ResponseStatus.CONTENT,
+                                ContentFormat.APPLICATION_CBOR,
+                                MAP_CBOR.encodingPayloadToCbor(payload));
                     }
                 } catch (CRLException e) {
                     Log.e(e.getMessage());
@@ -121,60 +121,63 @@ public class CrlResource extends Resource {
     }
 
     /**
-     * Handles POST requests of next formats:
-     * POST /oic/credprov/crl
-     * {
-     *      “tu” : “20160727000000”,
-     *      “nu” : “20161027000000”,
-     *      “rcsn” : “123456”
-     * }
-     * AND
-     * POST /oic/credprov/crl
-     * {
-     *      “tu” : “20160727000000”,
-     *      “nu” : “20161027000000”,
-     *      “crl” : {
-     *          “encoding” : “oic.sec.encoding.base64”,
-     *          “data” : “<Base64 encoded New CRL Binary>”
-     *       }
-     * }
-     * And responds back with 2.04 CHANGED if everything is ok, and PRECONDITION_FAILED - otherwise
+     * Handles POST requests of next formats: POST /oic/credprov/crl { “tu” :
+     * “20160727000000”, “nu” : “20161027000000”, “rcsn” : “123456” } AND POST
+     * /oic/credprov/crl { “tu” : “20160727000000”, “nu” : “20161027000000”,
+     * “crl” : { “encoding” : “oic.sec.encoding.base64”, “data” : “<Base64
+     * encoded New CRL Binary>” } } And responds back with 2.04 CHANGED if
+     * everything is ok, and PRECONDITION_FAILED - otherwise
      */
     private IResponse handlePostRequest(IRequest request)
             throws ServerException {
         byte[] requestPayload = request.getPayload();
-        IResponse response = MessageBuilder.createResponse(request, ResponseStatus.PRECONDITION_FAILED);
+        IResponse response = MessageBuilder.createResponse(request,
+                ResponseStatus.PRECONDITION_FAILED);
         if (requestPayload != null) {
             Map<String, Object> payloadData = MAP_CBOR
                     .parsePayloadFromCbor(request.getPayload(), HashMap.class);
             if (payloadData != null) {
                 Object thisUpdate = payloadData.get(Constants.REQ_THIS_UPDATE);
                 Object nextUpdate = payloadData.get(Constants.REQ_NEXT_UPDATE);
-                if (thisUpdate != null && thisUpdate instanceof String && nextUpdate != null && nextUpdate instanceof String) {
+                if (thisUpdate != null && thisUpdate instanceof String
+                        && nextUpdate != null && nextUpdate instanceof String) {
                     Date thisUpdateDate;
                     try {
-                        thisUpdateDate = DATE_FORMAT.parse(thisUpdate.toString());
-                        Object reqSerialNumber = payloadData.get(Constants.REQ_SERIAL_NUMBER);
+                        thisUpdateDate = new SimpleDateFormat("yyyyMMddHHmmss")
+                                .parse(thisUpdate.toString());
+                        Object reqSerialNumber = payloadData
+                                .get(Constants.REQ_SERIAL_NUMBER);
                         Object crl = payloadData.get(Constants.REQ_CRL);
-                        if (reqSerialNumber != null && reqSerialNumber instanceof List) {
-                            CRL_MANAGER.revoke(((List<String>) reqSerialNumber).toArray(new String[]{}));
-                            response = MessageBuilder.createResponse(request, ResponseStatus.CHANGED);
+                        if (reqSerialNumber != null
+                                && reqSerialNumber instanceof List) {
+                            CRL_MANAGER.revoke(((List<String>) reqSerialNumber)
+                                    .toArray(new String[] {}));
+                            response = MessageBuilder.createResponse(request,
+                                    ResponseStatus.CHANGED);
                         } else if (crl != null && crl instanceof Map) {
-                            Object encoding = ((Map<String, Object>) crl).get(Constants.ENCODING);
-                            Object crlData = ((Map<String, Object>) crl).get(Constants.DATA);
-                            if (encoding != null && encoding instanceof String && crlData != null && crlData instanceof byte[]) {
+                            Object encoding = ((Map<String, Object>) crl)
+                                    .get(Constants.ENCODING);
+                            Object crlData = ((Map<String, Object>) crl)
+                                    .get(Constants.DATA);
+                            if (encoding != null && encoding instanceof String
+                                    && crlData != null
+                                    && crlData instanceof byte[]) {
                                 try {
                                     if (encoding.equals(BASE_64)) {
-                                        crlData = Base64.decode((byte[]) crlData);
+                                        crlData = Base64
+                                                .decode((byte[]) crlData);
                                     }
-                                    CRL_MANAGER.update(thisUpdateDate, (byte[]) crlData);
-                                    response = MessageBuilder.createResponse(request, ResponseStatus.CHANGED);
+                                    CRL_MANAGER.update(thisUpdateDate,
+                                            (byte[]) crlData);
+                                    response = MessageBuilder.createResponse(
+                                            request, ResponseStatus.CHANGED);
                                 } catch (DecoderException e) {
                                     Log.e(e.getMessage() + e.getClass());
                                 }
                             }
                         }
-                    } catch (CRLException | IOException | OperatorCreationException | ParseException e) {
+                    } catch (CRLException | IOException
+                            | OperatorCreationException | ParseException e) {
                         Log.e(e.getMessage() + e.getClass());
                     }
                 }
index 23c4575..976e904 100644 (file)
@@ -23,6 +23,7 @@ package org.iotivity.cloud.ciserver;
 
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 
 import org.iotivity.cloud.base.OICConstants;
 import org.iotivity.cloud.base.ServerSystem;
@@ -34,6 +35,7 @@ import org.iotivity.cloud.base.exception.ClientException;
 import org.iotivity.cloud.base.exception.ServerException;
 import org.iotivity.cloud.base.exception.ServerException.BadOptionException;
 import org.iotivity.cloud.base.exception.ServerException.BadRequestException;
+import org.iotivity.cloud.base.exception.ServerException.InternalServerErrorException;
 import org.iotivity.cloud.base.exception.ServerException.UnAuthorizedException;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
 import org.iotivity.cloud.base.protocols.coap.CoapRequest;
@@ -79,7 +81,7 @@ public class DeviceServerSystem extends ServerSystem {
      * This class provides a set of APIs to manage device pool.
      *
      */
-    public class CoapDevicePool {
+    public static class CoapDevicePool {
         HashMap<String, Device> mMapDevice = new HashMap<>();
 
         /**
@@ -112,12 +114,14 @@ public class DeviceServerSystem extends ServerSystem {
         }
 
         private void removeObserveDevice(Device device) throws ClientException {
-            Iterator<String> iterator = mMapDevice.keySet().iterator();
-            while (iterator.hasNext()) {
-                String deviceId = iterator.next();
-                CoapDevice getDevice = (CoapDevice) queryDevice(deviceId);
-                getDevice.removeObserveChannel(
-                        ((CoapDevice) device).getRequestChannel());
+            synchronized (mMapDevice) {
+                Iterator<String> iterator = mMapDevice.keySet().iterator();
+                while (iterator.hasNext()) {
+                    String deviceId = iterator.next();
+                    CoapDevice getDevice = (CoapDevice) queryDevice(deviceId);
+                    getDevice.removeObserveChannel(
+                            ((CoapDevice) device).getRequestChannel());
+                }
             }
         }
 
@@ -159,15 +163,24 @@ public class DeviceServerSystem extends ServerSystem {
 
                     CoapRequest coapRequest = (CoapRequest) msg;
                     IRequestChannel targetChannel = null;
-                    if (coapRequest.getUriPath()
-                            .contains(Constants.ROUTE_FULL_URI)) {
+                    String urlPath = coapRequest.getUriPath();
+
+                    if (urlPath == null) {
+                        throw new InternalServerErrorException(
+                                "request uriPath is null");
+                    }
+
+                    if (urlPath.contains(Constants.ROUTE_FULL_URI)) {
 
                         int RouteResourcePathSize = Constants.ROUTE_FULL_URI
                                 .split("/").length;
-                        CoapDevice targetDevice = (CoapDevice) mDevicePool
-                                .queryDevice(coapRequest.getUriPathSegments()
-                                        .get(RouteResourcePathSize - 1));
-                        targetChannel = targetDevice.getRequestChannel();
+                        List<String> uriPath = coapRequest.getUriPathSegments();
+                        if (uriPath != null && !uriPath.isEmpty()) {
+                            CoapDevice targetDevice = (CoapDevice) mDevicePool
+                                    .queryDevice(uriPath
+                                            .get(RouteResourcePathSize - 1));
+                            targetChannel = targetDevice.getRequestChannel();
+                        }
                     }
                     switch (coapRequest.getObserve()) {
                         case SUBSCRIBE:
@@ -209,7 +222,14 @@ public class DeviceServerSystem extends ServerSystem {
                 // Once the response is valid, add this to deviceList
                 CoapResponse response = (CoapResponse) msg;
 
-                switch (response.getUriPath()) {
+                String urlPath = response.getUriPath();
+
+                if (urlPath == null) {
+                    throw new InternalServerErrorException(
+                            "request uriPath is null");
+                }
+
+                switch (urlPath) {
                     case OICConstants.ACCOUNT_SESSION_FULL_URI:
                         if (response.getStatus() != ResponseStatus.CHANGED) {
                             bCloseConnection = true;
@@ -312,7 +332,14 @@ public class DeviceServerSystem extends ServerSystem {
 
                 CoapResponse response = (CoapResponse) msg;
 
-                switch (response.getUriPath()) {
+                String urlPath = response.getUriPath();
+
+                if (urlPath == null) {
+                    throw new InternalServerErrorException(
+                            "request uriPath is null");
+                }
+
+                switch (urlPath) {
 
                     case OICConstants.ACCOUNT_SESSION_FULL_URI:
                         HashMap<String, Object> payloadData = mCbor
@@ -363,7 +390,14 @@ public class DeviceServerSystem extends ServerSystem {
                 // And check first response is VALID then add or cut
                 CoapRequest request = (CoapRequest) msg;
 
-                switch (request.getUriPath()) {
+                String urlPath = request.getUriPath();
+
+                if (urlPath == null) {
+                    throw new InternalServerErrorException(
+                            "request uriPath is null");
+                }
+
+                switch (urlPath) {
                     // Check whether request is about account
                     case OICConstants.ACCOUNT_FULL_URI:
                     case OICConstants.ACCOUNT_TOKENREFRESH_FULL_URI:
@@ -424,7 +458,7 @@ public class DeviceServerSystem extends ServerSystem {
     }
 
     @Sharable
-    class HttpAuthHandler extends ChannelDuplexHandler {
+    static class HttpAuthHandler extends ChannelDuplexHandler {
         @Override
         public void channelActive(ChannelHandlerContext ctx) throws Exception {
             // After current channel authenticated, raise to upper layer
index 9ba78a8..cb474f6 100644 (file)
@@ -33,6 +33,7 @@ import org.iotivity.cloud.base.device.Device;
 import org.iotivity.cloud.base.device.IRequestChannel;
 import org.iotivity.cloud.base.device.IResponseEventHandler;
 import org.iotivity.cloud.base.exception.ServerException;
+import org.iotivity.cloud.base.exception.ServerException.InternalServerErrorException;
 import org.iotivity.cloud.base.protocols.IRequest;
 import org.iotivity.cloud.base.protocols.IResponse;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
@@ -81,17 +82,21 @@ public class RouteResource extends Resource {
         List<String> uriPathSegment = request.getUriPathSegments();
 
         // Remove prefix path
-        for (String path : getUriPathSegments()) {
-            uriPathSegment.remove(path);
-        }
-        uriPathSegment.remove(0);
+        if (uriPathSegment != null) {
+            for (String path : getUriPathSegments()) {
+                uriPathSegment.remove(path);
+            }
+            uriPathSegment.remove(0);
 
-        StringBuilder uriPath = new StringBuilder();
-        for (String path : uriPathSegment) {
-            uriPath.append("/" + path);
-        }
+            StringBuilder uriPath = new StringBuilder();
+            for (String path : uriPathSegment) {
+                uriPath.append("/" + path);
+            }
 
-        return uriPath.toString();
+            return uriPath.toString();
+        }
+        throw new InternalServerErrorException(
+                "Can not extract TargetUriPath from uriPath!");
     }
 
     private IResponse convertReponseUri(IResponse response, String di) {
@@ -105,7 +110,9 @@ public class RouteResource extends Resource {
             uriPath.append("/" + path);
         }
 
-        if (coapResponse.getUriPath().isEmpty() == false) {
+        String resUriPath = coapResponse.getUriPath();
+
+        if (resUriPath != null && !resUriPath.isEmpty()) {
             convertedUri = uriPath.toString() + "/" + di
                     + coapResponse.getUriPath();
         }
@@ -115,7 +122,12 @@ public class RouteResource extends Resource {
     }
 
     private String getDeviceId(IRequest request) {
-        return request.getUriPathSegments().get(getUriPathSegments().size());
+        List<String> uriPathSegment = request.getUriPathSegments();
+        if (uriPathSegment == null)
+            throw new InternalServerErrorException(
+                    "Can not find deviceId from uriPath!");
+
+        return uriPathSegment.get(getUriPathSegments().size());
     }
 
     /**
index 80d22c0..17b4076 100644 (file)
@@ -95,12 +95,14 @@ public class DevicePresence extends Resource {
                     } else {
                         String additionalQuery = makeAdditionalQuery(
                                 payloadData, mSrcDevice.getDeviceId());
-
-                        String uriQuery = additionalQuery.toString()
-                                + (mRequest.getUriQuery() != null
-                                        ? (";" + mRequest.getUriQuery()) : "");
-                        mRequest = MessageBuilder.modifyRequest(mRequest, null,
-                                uriQuery, null, null);
+                        if (additionalQuery != null) {
+                            String uriQuery = additionalQuery.toString()
+                                    + (mRequest.getUriQuery() != null
+                                            ? (";" + mRequest.getUriQuery())
+                                            : "");
+                            mRequest = MessageBuilder.modifyRequest(mRequest,
+                                    null, uriQuery, null, null);
+                        }
                     }
 
                     mRDServer.sendRequest(mRequest, mSrcDevice);
index a8aa880..95dd639 100644 (file)
@@ -79,14 +79,15 @@ public class ResourcePresence extends Resource {
 
                     String additionalQuery = makeAdditionalQuery(payloadData,
                             mSrcDevice.getDeviceId());
-
-                    String uriQuery = additionalQuery.toString()
-                            + (mRequest.getUriQuery() != null
-                                    ? (";" + mRequest.getUriQuery()) : "");
-                    mRequest = MessageBuilder.modifyRequest(mRequest, null,
-                            uriQuery, null, null);
-
-                    mRDServer.sendRequest(mRequest, mSrcDevice);
+                    if (additionalQuery != null) {
+                        String uriQuery = additionalQuery.toString()
+                                + (mRequest.getUriQuery() != null
+                                        ? (";" + mRequest.getUriQuery()) : "");
+                        mRequest = MessageBuilder.modifyRequest(mRequest, null,
+                                uriQuery, null, null);
+
+                        mRDServer.sendRequest(mRequest, mSrcDevice);
+                    }
                     break;
 
                 default:
index 73e1e50..1ff5224 100644 (file)
@@ -30,6 +30,12 @@ import java.util.Properties;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
+import org.I0Itec.zkclient.ZkClient;
+import org.I0Itec.zkclient.ZkConnection;
+import org.iotivity.cloud.mqserver.Constants;
+import org.iotivity.cloud.mqserver.topic.Topic;
+import org.iotivity.cloud.util.Log;
+
 import kafka.admin.AdminUtils;
 import kafka.api.FetchRequest;
 import kafka.api.FetchRequestBuilder;
@@ -48,12 +54,6 @@ import kafka.message.MessageAndOffset;
 import kafka.utils.ZKStringSerializer$;
 import kafka.utils.ZkUtils;
 
-import org.I0Itec.zkclient.ZkClient;
-import org.I0Itec.zkclient.ZkConnection;
-import org.iotivity.cloud.mqserver.Constants;
-import org.iotivity.cloud.mqserver.topic.Topic;
-import org.iotivity.cloud.util.Log;
-
 /**
  *
  * This class provides a set of APIs to use Kafka consumer APIs for receiving
@@ -118,8 +118,8 @@ public class KafkaConsumerWrapper {
         }
 
         // remove consumer group info if already exist
-        List<String> subscribers = mZkClient.getChildren(ZkUtils
-                .ConsumersPath());
+        List<String> subscribers = mZkClient
+                .getChildren(ZkUtils.ConsumersPath());
 
         if (subscribers.contains(mTopicName)) {
             AdminUtils.deleteConsumerGroupInZK(mZkUtils, mTopicName);
@@ -152,8 +152,8 @@ public class KafkaConsumerWrapper {
 
                     for (final MessageAndMetadata<byte[], byte[]> messageAndMetadata : stream) {
 
-                        mInternalConsumer.onMessagePublished(messageAndMetadata
-                                .message());
+                        mInternalConsumer.onMessagePublished(
+                                messageAndMetadata.message());
                     }
                 }
             });
@@ -175,8 +175,8 @@ public class KafkaConsumerWrapper {
         Log.d("kafka unsubscribeTopic - " + mTopicName);
 
         // remove consumer group info in zookeeper
-        List<String> subscribers = mZkClient.getChildren(ZkUtils
-                .ConsumersPath());
+        List<String> subscribers = mZkClient
+                .getChildren(ZkUtils.ConsumersPath());
 
         if (subscribers.contains(mTopicName)) {
             AdminUtils.deleteConsumerGroupInZK(mZkUtils, mTopicName);
@@ -213,8 +213,8 @@ public class KafkaConsumerWrapper {
         Log.d("kafka get all messages - " + mTopicName);
 
         String brokerHost = mBroker.substring(0, mBroker.indexOf(':'));
-        int brokerPort = Integer.parseInt(mBroker.substring(mBroker
-                .indexOf(':') + 1));
+        int brokerPort = Integer
+                .parseInt(mBroker.substring(mBroker.indexOf(':') + 1));
 
         Log.d("host " + brokerHost + ", port " + brokerPort);
 
@@ -255,10 +255,12 @@ public class KafkaConsumerWrapper {
                 lastOffset = messageAndOffset.nextOffset();
                 ByteBuffer payload = messageAndOffset.message().payload();
 
-                byte[] bytes = new byte[payload.limit()];
-                payload.get(bytes);
+                if (payload != null) {
+                    byte[] bytes = new byte[payload.limit()];
+                    payload.get(bytes);
 
-                initialData.add(bytes);
+                    initialData.add(bytes);
+                }
             }
         }
 
@@ -289,8 +291,8 @@ public class KafkaConsumerWrapper {
                 partition);
 
         Map<TopicAndPartition, PartitionOffsetRequestInfo> requestInfo = new HashMap<>();
-        requestInfo.put(topicAndPartition, new PartitionOffsetRequestInfo(
-                whichTime, 1));
+        requestInfo.put(topicAndPartition,
+                new PartitionOffsetRequestInfo(whichTime, 1));
 
         kafka.javaapi.OffsetRequest request = new kafka.javaapi.OffsetRequest(
                 requestInfo, kafka.api.OffsetRequest.CurrentVersion(),
index 4d07cdc..3710c5f 100644 (file)
@@ -96,7 +96,8 @@ public class MQBrokerResource extends Resource {
     private IResponse handleGetRequest(Device srcDevice, IRequest request) {
 
         // DISCOVER
-        if (request.getUriPathSegments().size() == getUriPathSegments().size()) {
+        if (request.getUriPathSegments().size() == getUriPathSegments()
+                .size()) {
             return discoverTopic(request);
         }
 
@@ -118,7 +119,8 @@ public class MQBrokerResource extends Resource {
     // CREATE topic
     private IResponse handlePutRequest(IRequest request) {
 
-        if (request.getUriPathSegments().size() == getUriPathSegments().size()) {
+        if (request.getUriPathSegments().size() == getUriPathSegments()
+                .size()) {
 
             throw new BadRequestException(
                     "topic name is not included in request uri");
@@ -142,14 +144,19 @@ public class MQBrokerResource extends Resource {
     private IResponse createTopic(IRequest request) {
 
         // main topic creation request
-        if (request.getUriPathSegments().size() == getUriPathSegments().size() + 1) {
+        if (request.getUriPathSegments().size() == getUriPathSegments().size()
+                + 1) {
             return createMainTopic(request);
         }
 
         // subtopic creation request
         String uriPath = request.getUriPath();
-        uriPath = uriPath.substring(0, uriPath.lastIndexOf('/'));
 
+        if (uriPath == null) {
+            throw new BadRequestException("uriPath is not invalid");
+        }
+
+        uriPath = uriPath.substring(0, uriPath.lastIndexOf('/'));
         Topic targetTopic = mTopicManager.getTopic(uriPath);
 
         if (targetTopic == null) {
@@ -170,9 +177,13 @@ public class MQBrokerResource extends Resource {
         // subtopic removal request
         String uriPath = request.getUriPath();
 
+        if (uriPath == null) {
+            throw new BadRequestException("uriPath is not invalid");
+        }
+
         String parentName = uriPath.substring(0, uriPath.lastIndexOf('/'));
-        String targetName = request.getUriPathSegments().get(
-                request.getUriPathSegments().size() - 1);
+        String targetName = request.getUriPathSegments()
+                .get(request.getUriPathSegments().size() - 1);
 
         Topic parentTopic = mTopicManager.getTopic(parentName);
 
@@ -243,14 +254,14 @@ public class MQBrokerResource extends Resource {
         }
 
         return MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
-                ContentFormat.APPLICATION_CBOR, MessageQueueUtils.buildPayload(
-                        Constants.MQ_TOPICLIST, topicList));
+                ContentFormat.APPLICATION_CBOR, MessageQueueUtils
+                        .buildPayload(Constants.MQ_TOPICLIST, topicList));
     }
 
     private IResponse createMainTopic(IRequest request) {
 
-        String topicName = request.getUriPathSegments().get(
-                request.getUriPathSegments().size() - 1);
+        String topicName = request.getUriPathSegments()
+                .get(request.getUriPathSegments().size() - 1);
 
         String type = new String();
 
@@ -282,7 +293,12 @@ public class MQBrokerResource extends Resource {
 
         IResponse response = MessageBuilder.createResponse(request,
                 ResponseStatus.CREATED);
-        response.setLocationPath(request.getUriPath());
+        String uriPath = request.getUriPath();
+        if (uriPath == null) {
+            throw new InternalServerErrorException(
+                    "uriPath is null in handleCreateSubtopic");
+        }
+        response.setLocationPath(uriPath);
         return response;
     }
 
index d70deeb..63ac153 100644 (file)
@@ -53,7 +53,7 @@ public class Topic {
 
     private byte[]                 mLatestData   = null;
 
-    private class TopicSubscriber {
+    private static class TopicSubscriber {
         TopicSubscriber(Device subscriber, IRequest request) {
             mSubscriber = subscriber;
             mRequest = request;
@@ -144,7 +144,12 @@ public class Topic {
 
         IResponse response = MessageBuilder.createResponse(request,
                 ResponseStatus.CREATED);
-        response.setLocationPath(request.getUriPath());
+        String uriPath = request.getUriPath();
+        if (uriPath == null) {
+            throw new InternalServerErrorException(
+                    "uriPath is null in handleCreateSubtopic");
+        }
+        response.setLocationPath(uriPath);
         return response;
     }
 
index d4be884..02ea023 100644 (file)
@@ -156,7 +156,7 @@ public class DBManager {
         ArrayList<HashMap<String, Object>> records = _selectRecord(tableName,
                 condition);
 
-        if (records.size() > 1) {
+        if (records != null && records.size() > 1) {
             throw new InternalServerErrorException(
                     "Database record select failed");
         }
index d15100c..509e9ec 100644 (file)
@@ -269,7 +269,7 @@ public class MongoDB {
             Document doc) {
 
         if (tableName == null || doc == null)
-            return null;
+            return new ArrayList<>();
 
         MongoCollection<Document> collection = db.getCollection(tableName);
         MongoCursor<Document> cursor = collection.find(doc).iterator();
index 1d6f05d..5bb321f 100644 (file)
@@ -53,7 +53,7 @@ public class PresenceManager {
 
     private Cbor<HashMap<String, Object>> mCbor            = new Cbor<>();
 
-    private class PresenceSubscriber {
+    private static class PresenceSubscriber {
         PresenceSubscriber(Device subscriber, IRequest request) {
             mSubscriber = subscriber;
             mRequest = request;
@@ -63,7 +63,7 @@ public class PresenceManager {
         public IRequest mRequest;
     }
 
-    private class PresenceInfo {
+    private static class PresenceInfo {
 
         PresenceInfo() {
             mSubscriber = new HashMap<>();