Search in sources :

Example 1 with DefaultBootstrapSession

use of org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession in project thingsboard by thingsboard.

the class LwM2mDefaultBootstrapSessionManager method nextRequest.

protected BootstrapDownlinkRequest<? extends LwM2mResponse> nextRequest(BootstrapSession bsSession) {
    DefaultBootstrapSession session = (DefaultBootstrapSession) bsSession;
    List<BootstrapDownlinkRequest<? extends LwM2mResponse>> requestsToSend = session.getRequests();
    if (!requestsToSend.isEmpty()) {
        // get next requests
        return requestsToSend.remove(0);
    } else {
        if (session.hasMoreTasks()) {
            BootstrapTaskProvider.Tasks nextTasks = tasksProvider.getTasks(session, session.getResponses());
            if (nextTasks == null) {
                session.setMoreTasks(false);
                return new BootstrapFinishRequest();
            }
            initTasks(session, nextTasks);
            return nextRequest(bsSession);
        } else {
            return new BootstrapFinishRequest();
        }
    }
}
Also used : DefaultBootstrapSession(org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession) BootstrapDownlinkRequest(org.eclipse.leshan.core.request.BootstrapDownlinkRequest) BootstrapTaskProvider(org.eclipse.leshan.server.bootstrap.BootstrapTaskProvider) BootstrapFinishRequest(org.eclipse.leshan.core.request.BootstrapFinishRequest) LwM2mResponse(org.eclipse.leshan.core.response.LwM2mResponse)

Example 2 with DefaultBootstrapSession

use of org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession in project thingsboard by thingsboard.

the class LwM2mDefaultBootstrapSessionManager method initTasks.

protected void initTasks(BootstrapSession bssession, BootstrapTaskProvider.Tasks tasks) {
    DefaultBootstrapSession session = (DefaultBootstrapSession) bssession;
    // set models
    if (tasks.supportedObjects != null)
        session.setModel(modelProvider.getObjectModel(session, tasks.supportedObjects));
    // set Requests to Send
    log.info("tasks.requestsToSend = [{}]", tasks.requestsToSend);
    session.setRequests(tasks.requestsToSend);
    // prepare list where we will store Responses
    session.setResponses(new ArrayList<LwM2mResponse>(tasks.requestsToSend.size()));
    // is last Tasks ?
    session.setMoreTasks(!tasks.last);
}
Also used : DefaultBootstrapSession(org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession) LwM2mResponse(org.eclipse.leshan.core.response.LwM2mResponse)

Example 3 with DefaultBootstrapSession

use of org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession in project thingsboard by thingsboard.

the class LwM2mDefaultBootstrapSessionManager method onResponseError.

@Override
public BootstrapPolicy onResponseError(BootstrapSession bsSession, BootstrapDownlinkRequest<? extends LwM2mResponse> request, LwM2mResponse response) {
    if (!(request instanceof BootstrapFinishRequest)) {
        // store response
        DefaultBootstrapSession session = (DefaultBootstrapSession) bsSession;
        session.getResponses().add(response);
        this.sendLogs(bsSession.getEndpoint(), String.format("%s: %s %s receives error response %s ", LOG_LWM2M_INFO, request.getClass().getSimpleName(), request.getPath().toString(), response.toString()));
        // on response error for NOT bootstrap finish request we continue any sending next request
        return BootstrapPolicy.continueWith(nextRequest(bsSession));
    } else {
        // on response error for bootstrap finish request we stop the session
        this.sendLogs(bsSession.getEndpoint(), String.format("%s: error response for request bootstrap finish. Stop the session: %s", LOG_LWM2M_ERROR, bsSession.toString()));
        return BootstrapPolicy.failed();
    }
}
Also used : DefaultBootstrapSession(org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession) BootstrapFinishRequest(org.eclipse.leshan.core.request.BootstrapFinishRequest)

Example 4 with DefaultBootstrapSession

use of org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession in project thingsboard by thingsboard.

the class LwM2mDefaultBootstrapSessionManager method begin.

@Override
public BootstrapSession begin(BootstrapRequest request, Identity clientIdentity) {
    boolean authorized = true;
    Iterator<SecurityInfo> securityInfos = null;
    try {
        if (bsSecurityStore != null && securityChecker != null) {
            if (clientIdentity.isPSK()) {
                SecurityInfo securityInfo = bsSecurityStore.getByIdentity(clientIdentity.getPskIdentity());
                securityInfos = Collections.singletonList(securityInfo).iterator();
            } else if (!clientIdentity.isX509()) {
                securityInfos = bsSecurityStore.getAllByEndpoint(request.getEndpointName());
            }
            authorized = this.checkSecurityInfo(request.getEndpointName(), clientIdentity, securityInfos);
        }
    } catch (LwM2MAuthException e) {
        authorized = false;
    }
    DefaultBootstrapSession session = new DefaultBootstrapSession(request, clientIdentity, authorized);
    if (authorized) {
        this.sendLogs(request.getEndpointName(), String.format("%s: Bootstrap session started...", LOG_LWM2M_INFO, request.getEndpointName()));
    }
    return session;
}
Also used : DefaultBootstrapSession(org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession) LwM2MAuthException(org.thingsboard.server.transport.lwm2m.server.client.LwM2MAuthException) SecurityInfo(org.eclipse.leshan.server.security.SecurityInfo)

Example 5 with DefaultBootstrapSession

use of org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession in project thingsboard by thingsboard.

the class LwM2mDefaultBootstrapSessionManager method onResponseSuccess.

@Override
public BootstrapPolicy onResponseSuccess(BootstrapSession bsSession, BootstrapDownlinkRequest<? extends LwM2mResponse> request, LwM2mResponse response) {
    if (!(request instanceof BootstrapFinishRequest)) {
        // store response
        DefaultBootstrapSession session = (DefaultBootstrapSession) bsSession;
        session.getResponses().add(response);
        String msg = String.format("%s: receives success response for:  %s  %s %s", LOG_LWM2M_INFO, request.getClass().getSimpleName(), request.getPath().toString(), response.toString());
        this.sendLogs(bsSession.getEndpoint(), msg);
        // on success for NOT bootstrap finish request we send next request
        return BootstrapPolicy.continueWith(nextRequest(bsSession));
    } else {
        // on success for bootstrap finish request we stop the session
        this.sendLogs(bsSession.getEndpoint(), String.format("%s: receives success response for bootstrap finish.", LOG_LWM2M_INFO));
        return BootstrapPolicy.finished();
    }
}
Also used : DefaultBootstrapSession(org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession) BootstrapFinishRequest(org.eclipse.leshan.core.request.BootstrapFinishRequest)

Aggregations

DefaultBootstrapSession (org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession)5 BootstrapFinishRequest (org.eclipse.leshan.core.request.BootstrapFinishRequest)3 LwM2mResponse (org.eclipse.leshan.core.response.LwM2mResponse)2 BootstrapDownlinkRequest (org.eclipse.leshan.core.request.BootstrapDownlinkRequest)1 BootstrapTaskProvider (org.eclipse.leshan.server.bootstrap.BootstrapTaskProvider)1 SecurityInfo (org.eclipse.leshan.server.security.SecurityInfo)1 LwM2MAuthException (org.thingsboard.server.transport.lwm2m.server.client.LwM2MAuthException)1