You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2016/11/16 22:33:09 UTC

[5/7] brooklyn-server git commit: Don't lose the security provider configured in tests on reload

Don't lose the security provider configured in tests on reload


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/bfdf522c
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/bfdf522c
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/bfdf522c

Branch: refs/heads/master
Commit: bfdf522c452df262b3b4bb55cd567ddf45b31fa7
Parents: 819f725
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Mon Nov 14 14:43:28 2016 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Mon Nov 14 14:49:52 2016 +0200

----------------------------------------------------------------------
 .../apache/brooklyn/rest/BrooklynRestApiLauncher.java | 14 +++++++++++---
 .../entitlement/AbstractRestApiEntitlementsTest.java  |  3 ++-
 2 files changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bfdf522c/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncher.java
----------------------------------------------------------------------
diff --git a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncher.java b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncher.java
index b600159..910ee8f 100644
--- a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncher.java
+++ b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncher.java
@@ -120,6 +120,9 @@ public class BrooklynRestApiLauncher {
         return this;
     }
 
+    /**
+     * Note: Lost on brooklyn.properties reload
+     */
     public BrooklynRestApiLauncher securityProvider(Class<? extends SecurityProvider> securityProvider) {
         this.securityProvider = securityProvider;
         return this;
@@ -191,10 +194,15 @@ public class BrooklynRestApiLauncher {
                     : "from custom context";
         }
 
-        if (securityProvider != null && securityProvider != AnyoneSecurityProvider.class) {
-            ((BrooklynProperties) mgmt.getConfig()).put(
-                    BrooklynWebConfig.SECURITY_PROVIDER_CLASSNAME, securityProvider.getName());
+        Maybe<Object> configSecurityProvider = mgmt.getConfig().getConfigLocalRaw(BrooklynWebConfig.SECURITY_PROVIDER_CLASSNAME);
+        boolean hasConfigSecurityProvider = configSecurityProvider.isPresent();
+        boolean hasOverrideSecurityProvider = (securityProvider != null && securityProvider != AnyoneSecurityProvider.class);
+        if (hasOverrideSecurityProvider || hasConfigSecurityProvider) {
             ((WebAppContext)context).addOverrideDescriptor(getClass().getResource("/web-security.xml").toExternalForm());
+            if (hasOverrideSecurityProvider) {
+                ((BrooklynProperties) mgmt.getConfig()).put(
+                        BrooklynWebConfig.SECURITY_PROVIDER_CLASSNAME, securityProvider.getName());
+            }
         } else if (context instanceof WebAppContext) {
             ((WebAppContext)context).setSecurityHandler(new NopSecurityHandler());
         }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bfdf522c/rest/rest-server/src/test/java/org/apache/brooklyn/rest/entitlement/AbstractRestApiEntitlementsTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/entitlement/AbstractRestApiEntitlementsTest.java b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/entitlement/AbstractRestApiEntitlementsTest.java
index c858799..a750d89 100644
--- a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/entitlement/AbstractRestApiEntitlementsTest.java
+++ b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/entitlement/AbstractRestApiEntitlementsTest.java
@@ -35,6 +35,7 @@ import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.rest.BrooklynRestApiLauncher;
 import org.apache.brooklyn.rest.BrooklynRestApiLauncherTestFixture;
+import org.apache.brooklyn.rest.BrooklynWebConfig;
 import org.apache.brooklyn.util.http.HttpAsserts;
 import org.apache.brooklyn.util.http.HttpTool;
 import org.apache.brooklyn.util.http.HttpTool.HttpClientBuilder;
@@ -65,6 +66,7 @@ public abstract class AbstractRestApiEntitlementsTest extends BrooklynRestApiLau
         props.put(PerUserEntitlementManager.PER_USER_ENTITLEMENTS_CONFIG_PREFIX+".myMinimal", "minimal");
         props.put(PerUserEntitlementManager.PER_USER_ENTITLEMENTS_CONFIG_PREFIX+".myUser", "user");
         props.put(PerUserEntitlementManager.PER_USER_ENTITLEMENTS_CONFIG_PREFIX+".myCustom", StaticDelegatingEntitlementManager.class.getName());
+        props.put(BrooklynWebConfig.SECURITY_PROVIDER_CLASSNAME, AuthenticateAnyoneSecurityProvider.class.getName());
         
         mgmt = LocalManagementContextForTests.builder(false).useProperties(props).build();
         app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)
@@ -75,7 +77,6 @@ public abstract class AbstractRestApiEntitlementsTest extends BrooklynRestApiLau
         useServerForTest(BrooklynRestApiLauncher.launcher()
                 .managementContext(mgmt)
                 .forceUseOfDefaultCatalogWithJavaClassPath(true)
-                .securityProvider(AuthenticateAnyoneSecurityProvider.class)
                 .start());
     }