diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/BootstrapIntegrationTestHelper.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/BootstrapIntegrationTestHelper.java index b162de6e56..ea1b71b895 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/BootstrapIntegrationTestHelper.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/BootstrapIntegrationTestHelper.java @@ -131,12 +131,11 @@ private LeshanBootstrapServerBuilder createBootstrapBuilder(BootstrapSecuritySto } LeshanBootstrapServerBuilder builder = new LeshanBootstrapServerBuilder(); - builder.setConfigStore(bootstrapStore); - builder.setSecurityStore(securityStore); builder.setLocalAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); builder.setLocalSecureAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); builder.setPrivateKey(bootstrapServerPrivateKey); builder.setPublicKey(bootstrapServerPublicKey); + builder.setSecurityStore(securityStore); builder.setSessionManager(new DefaultBootstrapSessionManager(securityStore, bootstrapStore) { @Override diff --git a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/bootstrap/LeshanBootstrapServer.java b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/bootstrap/LeshanBootstrapServer.java index af5e1ae150..ce0e36738a 100644 --- a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/bootstrap/LeshanBootstrapServer.java +++ b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/bootstrap/LeshanBootstrapServer.java @@ -29,13 +29,11 @@ import org.eclipse.leshan.core.node.codec.LwM2mNodeDecoder; import org.eclipse.leshan.core.node.codec.LwM2mNodeEncoder; import org.eclipse.leshan.core.util.Validate; -import org.eclipse.leshan.server.bootstrap.BootstrapConfigStore; 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.LwM2mBootstrapRequestSender; import org.eclipse.leshan.server.californium.RootResource; -import org.eclipse.leshan.server.security.BootstrapSecurityStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,10 +50,6 @@ public class LeshanBootstrapServer { private final CoapEndpoint unsecuredEndpoint; private final CoapEndpoint securedEndpoint; - // LWM2M attributes - private final BootstrapConfigStore bsStore; - private final BootstrapSecurityStore bsSecurityStore; - private LwM2mBootstrapRequestSender requestSender; /** @@ -65,8 +59,6 @@ public class LeshanBootstrapServer { * * @param unsecuredEndpoint CoAP endpoint used for coap:// communication. * @param securedEndpoint CoAP endpoint used for coaps:// communication. - * @param bsStore the store containing bootstrap configuration to apply during a bootstrap session. - * @param bsSecurityStore the store containing security information needed to authenticate a client. * @param bsSessionManager manages life cycle of a bootstrap process * @param bsHandlerFactory responsible to create the {@link BootstrapHandler} * @param coapConfig the CoAP {@link NetworkConfig}. @@ -74,17 +66,13 @@ public class LeshanBootstrapServer { * @param decoder decoder used to decode response payload. */ public LeshanBootstrapServer(CoapEndpoint unsecuredEndpoint, CoapEndpoint securedEndpoint, - BootstrapConfigStore bsStore, BootstrapSecurityStore bsSecurityStore, BootstrapSessionManager bsSessionManager, BootstrapHandlerFactory bsHandlerFactory, NetworkConfig coapConfig, LwM2mNodeEncoder encoder, LwM2mNodeDecoder decoder) { - 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(coapConfig, "coapConfig must not be null"); - this.bsStore = bsStore; - this.bsSecurityStore = bsSecurityStore; this.coapApi = new CoapAPI(); // init CoAP server @@ -124,25 +112,6 @@ protected CoapResource createBootstrapResource(BootstrapHandler handler) { return new BootstrapResource(handler); } - /** - * Security store used for DTLS authentication on the bootstrap resource. - * - * @return the {@link BootstrapSecurityStore} containing data used to authenticate devices. - */ - public BootstrapSecurityStore getBootstrapSecurityStore() { - return bsSecurityStore; - } - - /** - * Access to the bootstrap configuration store. It's used for sending configuration to the devices initiating a - * bootstrap. - * - * @return the {@link BootstrapConfigStore} containing configuration to apply to each devices. - */ - public BootstrapConfigStore getBoostrapStore() { - return bsStore; - } - /** * Starts the server and binds it to the specified port. */ diff --git a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/bootstrap/LeshanBootstrapServerBuilder.java b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/bootstrap/LeshanBootstrapServerBuilder.java index 6f856c8b7a..e937a2960f 100644 --- a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/bootstrap/LeshanBootstrapServerBuilder.java +++ b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/bootstrap/LeshanBootstrapServerBuilder.java @@ -42,6 +42,7 @@ import org.eclipse.leshan.core.node.codec.LwM2mNodeEncoder; import org.eclipse.leshan.server.bootstrap.BootstrapConfig; import org.eclipse.leshan.server.bootstrap.BootstrapConfigStore; +import org.eclipse.leshan.server.bootstrap.BootstrapConfigStoreTaskProvider; import org.eclipse.leshan.server.bootstrap.BootstrapHandler; import org.eclipse.leshan.server.bootstrap.BootstrapHandlerFactory; import org.eclipse.leshan.server.bootstrap.BootstrapSessionManager; @@ -49,7 +50,6 @@ import org.eclipse.leshan.server.bootstrap.DefaultBootstrapSessionManager; import org.eclipse.leshan.server.bootstrap.InMemoryBootstrapConfigStore; import org.eclipse.leshan.server.bootstrap.LwM2mBootstrapRequestSender; -import org.eclipse.leshan.server.bootstrap.BootstrapConfigStoreTaskProvider; import org.eclipse.leshan.server.model.LwM2mBootstrapModelProvider; import org.eclipse.leshan.server.model.StandardBootstrapModelProvider; import org.eclipse.leshan.server.security.BootstrapSecurityStore; @@ -397,9 +397,6 @@ public NetworkConfig createDefaultNetworkConfig() { public LeshanBootstrapServer build() { if (localAddress == null) localAddress = new InetSocketAddress(LwM2m.DEFAULT_COAP_PORT); - if (configStore == null) - configStore = new InMemoryBootstrapConfigStore(); - if (bootstrapHandlerFactory == null) bootstrapHandlerFactory = new BootstrapHandlerFactory() { @Override @@ -408,11 +405,21 @@ public BootstrapHandler create(LwM2mBootstrapRequestSender sender, return new DefaultBootstrapHandler(sender, sessionManager); } }; - if (modelProvider == null) + if (configStore == null) { + configStore = new InMemoryBootstrapConfigStore(); + } else if (sessionManager != null) { + LOG.warn("configStore is set but you also provide a custom SessionManager so this store will not be used"); + } + if (modelProvider == null) { modelProvider = new StandardBootstrapModelProvider(); - if (sessionManager == null) + } else if (sessionManager != null) { + LOG.warn( + "modelProvider is set but you also provide a custom SessionManager so this provider will not be used"); + } + if (sessionManager == null) { sessionManager = new DefaultBootstrapSessionManager(securityStore, new SecurityChecker(), new BootstrapConfigStoreTaskProvider(configStore), modelProvider); + } if (coapConfig == null) { coapConfig = createDefaultNetworkConfig(); } @@ -562,8 +569,8 @@ public BootstrapHandler create(LwM2mBootstrapRequestSender sender, "All CoAP enpoints are deactivated, at least one endpoint should be activated"); } - return createBootstrapServer(unsecuredEndpoint, securedEndpoint, configStore, securityStore, sessionManager, - bootstrapHandlerFactory, coapConfig, encoder, decoder); + return createBootstrapServer(unsecuredEndpoint, securedEndpoint, sessionManager, bootstrapHandlerFactory, + coapConfig, encoder, decoder); } /** @@ -582,8 +589,6 @@ protected boolean shouldTryToCreateSecureEndpoint() { * * @param unsecuredEndpoint CoAP endpoint used for coap:// communication. * @param securedEndpoint CoAP endpoint used for coaps:// communication. - * @param bsStore the bootstrap configuration store. - * @param bsSecurityStore the security store used to authenticate devices. * @param bsSessionManager the manager responsible to handle bootstrap session. * @param bsHandlerFactory the factory used to create {@link BootstrapHandler}. * @param coapConfig the CoAP configuration. @@ -592,10 +597,9 @@ protected boolean shouldTryToCreateSecureEndpoint() { * @return the LWM2M Bootstrap server. */ protected LeshanBootstrapServer createBootstrapServer(CoapEndpoint unsecuredEndpoint, CoapEndpoint securedEndpoint, - BootstrapConfigStore bsStore, BootstrapSecurityStore bsSecurityStore, BootstrapSessionManager bsSessionManager, BootstrapHandlerFactory bsHandlerFactory, NetworkConfig coapConfig, LwM2mNodeEncoder encoder, LwM2mNodeDecoder decoder) { - return new LeshanBootstrapServer(unsecuredEndpoint, securedEndpoint, bsStore, bsSecurityStore, bsSessionManager, - bsHandlerFactory, coapConfig, encoder, decoder); + return new LeshanBootstrapServer(unsecuredEndpoint, securedEndpoint, bsSessionManager, bsHandlerFactory, + coapConfig, encoder, decoder); } } diff --git a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/bootstrap/LeshanBootstrapServerBuilderTest.java b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/bootstrap/LeshanBootstrapServerBuilderTest.java index a6186ed448..c3fe6e83d8 100644 --- a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/bootstrap/LeshanBootstrapServerBuilderTest.java +++ b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/bootstrap/LeshanBootstrapServerBuilderTest.java @@ -70,7 +70,6 @@ public Iterator getAllByEndpoint(String endpoint) { assertNotNull(server.getSecuredAddress()); assertNotNull(server.getUnsecuredAddress()); - assertNotNull(server.getBootstrapSecurityStore()); } @Test diff --git a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapSessionManager.java b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapSessionManager.java index 0f211d889a..444610470a 100644 --- a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapSessionManager.java +++ b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapSessionManager.java @@ -70,6 +70,7 @@ public DefaultBootstrapSessionManager(BootstrapSecurityStore bsSecurityStore, Bo public DefaultBootstrapSessionManager(BootstrapSecurityStore bsSecurityStore, SecurityChecker securityChecker, BootstrapTaskProvider tasksProvider, LwM2mBootstrapModelProvider modelProvider) { Validate.notNull(tasksProvider); + Validate.notNull(modelProvider); this.bsSecurityStore = bsSecurityStore; this.securityChecker = securityChecker; this.tasksProvider = tasksProvider; @@ -79,7 +80,7 @@ public DefaultBootstrapSessionManager(BootstrapSecurityStore bsSecurityStore, Se @Override public BootstrapSession begin(BootstrapRequest request, Identity clientIdentity) { boolean authorized; - if (bsSecurityStore != null) { + if (bsSecurityStore != null && securityChecker != null) { Iterator securityInfos = bsSecurityStore.getAllByEndpoint(request.getEndpointName()); authorized = securityChecker.checkSecurityInfos(request.getEndpointName(), clientIdentity, securityInfos); } else { @@ -87,6 +88,7 @@ public BootstrapSession begin(BootstrapRequest request, Identity clientIdentity) } DefaultBootstrapSession session = new DefaultBootstrapSession(request, clientIdentity, authorized); LOG.trace("Bootstrap session started : {}", session); + return session; }