Repository: eclipse/leshan
Pull request #721 (2019-07-19 14:52:28)

 Add BootstrapSession param to BootstrapConfigStore.get()
It could make sense to store data in a session at `BootstrapSessionManager.begin(String, Identity)` to reuse it in `BootstrapConfigStore.get()`


Patch:
diff --git a/leshan-bsserver-demo/src/main/java/org/eclipse/leshan/server/bootstrap/demo/BootstrapConfigSecurityStore.java b/leshan-bsserver-demo/src/main/java/org/eclipse/leshan/server/bootstrap/demo/BootstrapConfigSecurityStore.java
index c1f2db6e..d55f18a6 100644
--- a/leshan-bsserver-demo/src/main/java/org/eclipse/leshan/server/bootstrap/demo/BootstrapConfigSecurityStore.java
+++ b/leshan-bsserver-demo/src/main/java/org/eclipse/leshan/server/bootstrap/demo/BootstrapConfigSecurityStore.java
@@ -81,7 +81,7 @@ public class BootstrapConfigSecurityStore implements BootstrapSecurityStore {
     @Override
     public List<SecurityInfo> getAllByEndpoint(String endpoint) {
 
-        BootstrapConfig bsConfig = bootstrapConfigStore.get(endpoint, null);
+        BootstrapConfig bsConfig = bootstrapConfigStore.get(endpoint, null, null);
 
         if (bsConfig == null || bsConfig.security == null)
             return null;
diff --git a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/BootstrapConfigStore.java b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/BootstrapConfigStore.java
index 57a011c6..c808d98c 100644
--- a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/BootstrapConfigStore.java
+++ b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/BootstrapConfigStore.java
@@ -27,7 +27,8 @@ public interface BootstrapConfigStore {
      * 
      * @param endpoint the endpoint of the device.
      * @param deviceIdentity the {@link Identity} the device.
+     * @param session the current {@link BootstrapSession}.
      * @return the {@link BootstrapConfig} to apply.
      */
-    BootstrapConfig get(String endpoint, Identity deviceIdentity);
+    BootstrapConfig get(String endpoint, Identity deviceIdentity, BootstrapSession session);
 }
diff --git a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapHandler.java b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapHandler.java
index 0012ae8d..1946f2e9 100644
--- a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapHandler.java
+++ b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapHandler.java
@@ -116,7 +116,7 @@ public class DefaultBootstrapHandler implements BootstrapHandler {
 
         try {
             // Get the desired bootstrap config for the endpoint
-            final BootstrapConfig cfg = store.get(endpoint, sender);
+            final BootstrapConfig cfg = store.get(endpoint, sender, session);
             if (cfg == null) {
                 LOG.debug("No bootstrap config for {}", session);
                 stopSession(session, NO_BOOTSTRAP_CONFIG);
diff --git a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/InMemoryBootstrapConfigStore.java b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/InMemoryBootstrapConfigStore.java
index 6d853391..513ce5ca 100644
--- a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/InMemoryBootstrapConfigStore.java
+++ b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/InMemoryBootstrapConfigStore.java
@@ -30,7 +30,7 @@ public class InMemoryBootstrapConfigStore implements EditableBootstrapConfigStor
     protected final Map<String, BootstrapConfig> bootstrapByEndpoint = new ConcurrentHashMap<>();
 
     @Override
-    public BootstrapConfig get(String endpoint, Identity deviceIdentity) {
+    public BootstrapConfig get(String endpoint, Identity deviceIdentity, BootstrapSession session) {
         return bootstrapByEndpoint.get(endpoint);
     }
 


Test patch:
diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/BootstrapIntegrationTestHelper.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/BootstrapIntegrationTestHelper.java
index 561554b6..734188d6 100644
--- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/BootstrapIntegrationTestHelper.java
+++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/BootstrapIntegrationTestHelper.java
@@ -48,6 +48,7 @@ import org.eclipse.leshan.server.bootstrap.BootstrapConfig.ACLConfig;
 import org.eclipse.leshan.server.bootstrap.BootstrapConfig.ServerConfig;
 import org.eclipse.leshan.server.bootstrap.BootstrapConfig.ServerSecurity;
 import org.eclipse.leshan.server.bootstrap.BootstrapConfigStore;
+import org.eclipse.leshan.server.bootstrap.BootstrapSession;
 import org.eclipse.leshan.server.californium.LeshanBootstrapServerBuilder;
 import org.eclipse.leshan.server.californium.impl.LeshanBootstrapServer;
 import org.eclipse.leshan.server.security.BootstrapSecurityStore;
@@ -233,7 +234,7 @@ public class BootstrapIntegrationTestHelper extends SecureIntegrationTestHelper
         return new BootstrapConfigStore() {
 
             @Override
-            public BootstrapConfig get(String endpoint, Identity deviceIdentity) {
+            public BootstrapConfig get(String endpoint, Identity deviceIdentity, BootstrapSession session) {
 
                 BootstrapConfig bsConfig = new BootstrapConfig();
 
@@ -277,7 +278,7 @@ public class BootstrapIntegrationTestHelper extends SecureIntegrationTestHelper
         return new BootstrapConfigStore() {
 
             @Override
-            public BootstrapConfig get(String endpoint, Identity deviceIdentity) {
+            public BootstrapConfig get(String endpoint, Identity deviceIdentity, BootstrapSession session) {
 
                 BootstrapConfig bsConfig = new BootstrapConfig();
                 bsConfig.toDelete = Arrays.asList(pathToDelete);
@@ -290,7 +291,7 @@ public class BootstrapIntegrationTestHelper extends SecureIntegrationTestHelper
         return new BootstrapConfigStore() {
 
             @Override
-            public BootstrapConfig get(String endpoint, Identity deviceIdentity) {
+            public BootstrapConfig get(String endpoint, Identity deviceIdentity, BootstrapSession session) {
 
                 BootstrapConfig bsConfig = new BootstrapConfig();
 
@@ -341,7 +342,7 @@ public class BootstrapIntegrationTestHelper extends SecureIntegrationTestHelper
         return new BootstrapConfigStore() {
 
             @Override
-            public BootstrapConfig get(String endpoint, Identity deviceIdentity) {
+            public BootstrapConfig get(String endpoint, Identity deviceIdentity, BootstrapSession session) {
 
                 BootstrapConfig bsConfig = new BootstrapConfig();
 
@@ -378,7 +379,7 @@ public class BootstrapIntegrationTestHelper extends SecureIntegrationTestHelper
         return new BootstrapConfigStore() {
 
             @Override
-            public BootstrapConfig get(String endpoint, Identity deviceIdentity) {
+            public BootstrapConfig get(String endpoint, Identity deviceIdentity, BootstrapSession session) {
 
                 BootstrapConfig bsConfig = new BootstrapConfig();
 
diff --git a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/LeshanBootstrapServerBuilderTest.java b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/LeshanBootstrapServerBuilderTest.java
index 0f03235e..31a02710 100644
--- a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/LeshanBootstrapServerBuilderTest.java
+++ b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/LeshanBootstrapServerBuilderTest.java
@@ -22,6 +22,7 @@ import java.util.List;
 import org.eclipse.leshan.core.request.Identity;
 import org.eclipse.leshan.server.bootstrap.BootstrapConfig;
 import org.eclipse.leshan.server.bootstrap.BootstrapConfigStore;
+import org.eclipse.leshan.server.bootstrap.BootstrapSession;
 import org.eclipse.leshan.server.californium.impl.LeshanBootstrapServer;
 import org.eclipse.leshan.server.security.BootstrapSecurityStore;
 import org.eclipse.leshan.server.security.SecurityInfo;
@@ -38,7 +39,7 @@ public class LeshanBootstrapServerBuilderTest {
         builder = new LeshanBootstrapServerBuilder();
         builder.setConfigStore(new BootstrapConfigStore() {
             @Override
-            public BootstrapConfig get(String endpoint, Identity deviceIdentity) {
+            public BootstrapConfig get(String endpoint, Identity deviceIdentity, BootstrapSession session) {
                 return null;
             }
         });