Browse Source

Fix NPE in Redis Security Store

pull/4798/head
Andrii Shvaika 5 years ago
parent
commit
5bff4d1a6b
  1. 12
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/TbLwM2mRedisSecurityStore.java

12
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/TbLwM2mRedisSecurityStore.java

@ -46,7 +46,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore {
lock = redisLock.obtain(toLockKey(endpoint));
lock.lock();
byte[] data = connection.get((SEC_EP + endpoint).getBytes());
if (data == null) {
if (data == null || data.length == 0) {
return null;
} else {
return ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo();
@ -69,7 +69,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore {
return null;
} else {
byte[] data = connection.get((SEC_EP + new String(ep)).getBytes());
if (data == null) {
if (data == null || data.length == 0) {
return null;
} else {
return ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo();
@ -122,7 +122,11 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore {
lock = redisLock.obtain(endpoint);
lock.lock();
byte[] data = connection.get((SEC_EP + endpoint).getBytes());
return (TbLwM2MSecurityInfo) serializer.asObject(data);
if (data != null && data.length > 0) {
return (TbLwM2MSecurityInfo) serializer.asObject(data);
} else {
return null;
}
} finally {
if (lock != null) {
lock.unlock();
@ -137,7 +141,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore {
lock = redisLock.obtain(endpoint);
lock.lock();
byte[] data = connection.get((SEC_EP + endpoint).getBytes());
if (data != null) {
if (data != null && data.length > 0) {
SecurityInfo info = ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo();
if (info != null && info.getIdentity() != null) {
connection.hDel(PSKID_SEC.getBytes(), info.getIdentity().getBytes());

Loading…
Cancel
Save