lwm2m - authorization in Bootstrap session

This commit is contained in:
nickAS21 2021-11-02 13:31:17 +02:00
parent e04ba2d61c
commit 2d10409042

View File

@ -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,6 +82,7 @@ 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;
try {
if (bsSecurityStore != null && securityChecker != null) { if (bsSecurityStore != null && securityChecker != null) {
if (clientIdentity.isSecure() && clientIdentity.isPSK()) { if (clientIdentity.isSecure() && clientIdentity.isPSK()) {
securityInfos = bsSecurityStore.getAllByEndpoint(clientIdentity.getPskIdentity()); securityInfos = bsSecurityStore.getAllByEndpoint(clientIdentity.getPskIdentity());
@ -91,6 +93,9 @@ public class LwM2mDefaultBootstrapSessionManager extends DefaultBootstrapSession
} else { } else {
authorized = true; authorized = true;
} }
} catch (LwM2MAuthException e) {
authorized = false;
}
DefaultBootstrapSession session = new DefaultBootstrapSession(request, clientIdentity, authorized); DefaultBootstrapSession session = new DefaultBootstrapSession(request, clientIdentity, authorized);
if (authorized) { if (authorized) {
this.sendLogs (request.getEndpointName(), this.sendLogs (request.getEndpointName(),