Browse Source

lwm2m - authorization in Bootstrap session

pull/5476/head
nickAS21 5 years ago
parent
commit
2d10409042
  1. 19
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2mDefaultBootstrapSessionManager.java

19
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2mDefaultBootstrapSessionManager.java

@ -34,6 +34,7 @@ import org.eclipse.leshan.server.security.BootstrapSecurityStore;
import org.eclipse.leshan.server.security.SecurityChecker; import org.eclipse.leshan.server.security.SecurityChecker;
import org.eclipse.leshan.server.security.SecurityInfo; import org.eclipse.leshan.server.security.SecurityInfo;
import org.thingsboard.server.common.transport.TransportService; import org.thingsboard.server.common.transport.TransportService;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2MAuthException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -81,15 +82,19 @@ public class LwM2mDefaultBootstrapSessionManager extends DefaultBootstrapSession
public BootstrapSession begin(BootstrapRequest request, Identity clientIdentity) { public BootstrapSession begin(BootstrapRequest request, Identity clientIdentity) {
boolean authorized; boolean authorized;
Iterator<SecurityInfo> securityInfos; Iterator<SecurityInfo> securityInfos;
if (bsSecurityStore != null && securityChecker != null) { try {
if (clientIdentity.isSecure() && clientIdentity.isPSK()) { if (bsSecurityStore != null && securityChecker != null) {
securityInfos = bsSecurityStore.getAllByEndpoint(clientIdentity.getPskIdentity()); if (clientIdentity.isSecure() && clientIdentity.isPSK()) {
securityInfos = bsSecurityStore.getAllByEndpoint(clientIdentity.getPskIdentity());
} else {
securityInfos = bsSecurityStore.getAllByEndpoint(request.getEndpointName());
}
authorized = securityChecker.checkSecurityInfos(request.getEndpointName(), clientIdentity, securityInfos);
} else { } else {
securityInfos = bsSecurityStore.getAllByEndpoint(request.getEndpointName()); authorized = true;
} }
authorized = securityChecker.checkSecurityInfos(request.getEndpointName(), clientIdentity, securityInfos); } catch (LwM2MAuthException e) {
} else { authorized = false;
authorized = true;
} }
DefaultBootstrapSession session = new DefaultBootstrapSession(request, clientIdentity, authorized); DefaultBootstrapSession session = new DefaultBootstrapSession(request, clientIdentity, authorized);
if (authorized) { if (authorized) {

Loading…
Cancel
Save