Skip to content

Commit

Permalink
Add a way to use a custom bootstrap handler
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Apr 2, 2019
1 parent e0d0ead commit 1d8fdd7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
import org.eclipse.leshan.core.californium.Lwm2mEndpointContextMatcher;
import org.eclipse.leshan.core.model.LwM2mModel;
import org.eclipse.leshan.core.model.ObjectLoader;
import org.eclipse.leshan.server.bootstrap.BootstrapHandler;
import org.eclipse.leshan.server.bootstrap.BootstrapHandlerFactory;
import org.eclipse.leshan.server.bootstrap.BootstrapSessionManager;
import org.eclipse.leshan.server.bootstrap.BootstrapStore;
import org.eclipse.leshan.server.bootstrap.LwM2mBootstrapRequestSender;
import org.eclipse.leshan.server.bootstrap.LwM2mBootstrapServer;
import org.eclipse.leshan.server.californium.impl.LeshanBootstrapServer;
import org.eclipse.leshan.server.californium.impl.LwM2mBootstrapPskStore;
Expand All @@ -59,6 +62,8 @@ public class LeshanBootstrapServerBuilder {
private BootstrapStore configStore;
private BootstrapSecurityStore securityStore;
private BootstrapSessionManager sessionManager;
private BootstrapHandlerFactory bootstrapHandlerFactory;

private LwM2mModel model;
private NetworkConfig coapConfig;
private Builder dtlsConfigBuilder;
Expand Down Expand Up @@ -192,6 +197,11 @@ public LeshanBootstrapServerBuilder setSessionManager(BootstrapSessionManager se
return this;
}

public LeshanBootstrapServerBuilder setBootstrapHandlerFactory(BootstrapHandlerFactory bootstrapHandlerFactory) {
this.bootstrapHandlerFactory = bootstrapHandlerFactory;
return this;
}

public LeshanBootstrapServerBuilder setModel(LwM2mModel model) {
this.model = model;
return this;
Expand Down Expand Up @@ -254,6 +264,14 @@ public LeshanBootstrapServer build() {

if (sessionManager == null)
sessionManager = new DefaultBootstrapSessionManager(securityStore);
if (bootstrapHandlerFactory == null)
bootstrapHandlerFactory = new BootstrapHandlerFactory() {
@Override
public BootstrapHandler create(BootstrapStore store, LwM2mBootstrapRequestSender sender,
BootstrapSessionManager sessionManager) {
return new BootstrapHandler(store, sender, sessionManager);
}
};
if (model == null)
model = new LwM2mModel(ObjectLoader.loadDefault());
if (coapConfig == null) {
Expand Down Expand Up @@ -395,6 +413,6 @@ public LeshanBootstrapServer build() {
}

return new LeshanBootstrapServer(unsecuredEndpoint, securedEndpoint, configStore, securityStore, sessionManager,
model, coapConfig);
bootstrapHandlerFactory, model, coapConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.californium.core.network.CoapEndpoint;
import org.eclipse.californium.core.network.config.NetworkConfig;
import org.eclipse.leshan.core.model.LwM2mModel;
import org.eclipse.leshan.server.bootstrap.BootstrapHandler;
import org.eclipse.leshan.server.bootstrap.BootstrapHandlerFactory;
import org.eclipse.leshan.server.bootstrap.BootstrapSessionManager;
import org.eclipse.leshan.server.bootstrap.BootstrapStore;
import org.eclipse.leshan.server.bootstrap.LwM2mBootstrapRequestSender;
Expand All @@ -46,11 +46,12 @@ public class LeshanBootstrapServer implements LwM2mBootstrapServer {
private final BootstrapSecurityStore bsSecurityStore;

public LeshanBootstrapServer(CoapEndpoint unsecuredEndpoint, CoapEndpoint securedEndpoint, BootstrapStore bsStore,
BootstrapSecurityStore bsSecurityStore, BootstrapSessionManager bsSessionManager, LwM2mModel model,
NetworkConfig coapConfig) {
BootstrapSecurityStore bsSecurityStore, BootstrapSessionManager bsSessionManager,
BootstrapHandlerFactory bsHandlerFactory, LwM2mModel model, NetworkConfig coapConfig) {

Validate.notNull(bsStore, "bootstrap store must not be null");
Validate.notNull(bsSessionManager, "session manager must not be null");
Validate.notNull(bsHandlerFactory, "BootstrapHandler factory must not be null");
Validate.notNull(model, "model must not be null");
Validate.notNull(coapConfig, "coapConfig must not be null");

Expand All @@ -73,7 +74,7 @@ public LeshanBootstrapServer(CoapEndpoint unsecuredEndpoint, CoapEndpoint secure
unsecuredEndpoint, model);

BootstrapResource bsResource = new BootstrapResource(
new BootstrapHandler(bsStore, requestSender, bsSessionManager));
bsHandlerFactory.create(bsStore, requestSender, bsSessionManager));
coapServer.add(bsResource);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2019 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Sierra Wireless - initial API and implementation
*******************************************************************************/
package org.eclipse.leshan.server.bootstrap;

public interface BootstrapHandlerFactory {
BootstrapHandler create(BootstrapStore store, LwM2mBootstrapRequestSender sender,
BootstrapSessionManager sessionManager);
}

0 comments on commit 1d8fdd7

Please sign in to comment.