You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/03/30 15:59:46 UTC
[09/50] brooklyn-server git commit: [BROOKLYN-183] Deprecate setting
a security filter in the launcher
[BROOKLYN-183] Deprecate setting a security filter in the launcher
Instead add a new property skipSecurity corresponding to the "--noConsoleSecurity" cli option.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/9b318cd9
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/9b318cd9
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/9b318cd9
Branch: refs/heads/master
Commit: 9b318cd920a3da411bd2db02168fb3337c620111
Parents: 857fd21
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Sun Feb 28 15:49:51 2016 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Thu Mar 17 15:25:45 2016 +0200
----------------------------------------------------------------------
.../brooklyn/launcher/BrooklynLauncher.java | 5 +-
.../brooklyn/launcher/BrooklynWebServer.java | 37 +++++++++++++-
.../brooklyn/launcher/NopSecurityHandler.java | 34 +++++++++++++
launcher/src/main/resources/web-security.xml | 51 ++++++++++++++++++++
.../BrooklynEntityMirrorIntegrationTest.java | 4 +-
5 files changed, 124 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9b318cd9/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
----------------------------------------------------------------------
diff --git a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
index 476c897..75bd90e 100644
--- a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
+++ b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
@@ -45,7 +45,6 @@ import org.apache.brooklyn.launcher.common.BasicLauncher;
import org.apache.brooklyn.launcher.common.BrooklynPropertiesFactoryHelper;
import org.apache.brooklyn.launcher.config.StopWhichAppsOnShutdown;
import org.apache.brooklyn.rest.BrooklynWebConfig;
-import org.apache.brooklyn.rest.filter.BrooklynPropertiesSecurityFilter;
import org.apache.brooklyn.rest.security.provider.BrooklynUserWithRandomPasswordSecurityProvider;
import org.apache.brooklyn.rest.util.ShutdownHandler;
import org.apache.brooklyn.util.exceptions.Exceptions;
@@ -308,9 +307,7 @@ public class BrooklynLauncher extends BasicLauncher<BrooklynLauncher> {
if (useHttps!=null) webServer.setHttpsEnabled(useHttps);
webServer.setShutdownHandler(shutdownHandler);
webServer.putAttributes(brooklynProperties);
- if (skipSecurityFilter != Boolean.TRUE) {
- webServer.setSecurityFilter(BrooklynPropertiesSecurityFilter.class);
- }
+ webServer.skipSecurity(Boolean.TRUE.equals(skipSecurityFilter));
for (WebAppContextProvider webapp : webApps) {
webServer.addWar(webapp);
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9b318cd9/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java
----------------------------------------------------------------------
diff --git a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java
index 449c0f4..4049b01 100644
--- a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java
+++ b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java
@@ -34,6 +34,7 @@ import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
+import javax.security.auth.spi.LoginModule;
import org.apache.brooklyn.api.location.PortRange;
import org.apache.brooklyn.api.mgmt.ManagementContext;
@@ -49,11 +50,12 @@ import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocati
import org.apache.brooklyn.rest.BrooklynWebConfig;
import org.apache.brooklyn.rest.RestApiSetup;
import org.apache.brooklyn.rest.filter.BrooklynPropertiesSecurityFilter;
+import org.apache.brooklyn.rest.filter.EntitlementContextFilter;
import org.apache.brooklyn.rest.filter.HaHotCheckResourceFilter;
-import org.apache.brooklyn.rest.filter.HaMasterCheckFilter;
import org.apache.brooklyn.rest.filter.LoggingFilter;
import org.apache.brooklyn.rest.filter.NoCacheFilter;
import org.apache.brooklyn.rest.filter.RequestTaggingFilter;
+import org.apache.brooklyn.rest.filter.RequestTaggingRsFilter;
import org.apache.brooklyn.rest.security.jaas.BrooklynLoginModule;
import org.apache.brooklyn.rest.security.jaas.BrooklynLoginModule.RolePrincipal;
import org.apache.brooklyn.rest.security.jaas.JaasUtils;
@@ -78,6 +80,7 @@ import org.apache.brooklyn.util.text.Identifiers;
import org.apache.brooklyn.util.text.Strings;
import org.apache.brooklyn.util.web.ContextHandlerCollectionHotSwappable;
import org.eclipse.jetty.http.HttpVersion;
+import org.eclipse.jetty.jaas.JAASLoginService;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
@@ -194,7 +197,16 @@ public class BrooklynWebServer {
private File webappTempDir;
+ /**
+ * @deprecated since 0.9.0, use {@link #consoleSecurity} to disable security or
+ * register an alternative JAAS {@link LoginModule}.
+ * {@link BrooklynLoginModule} used by default.
+ */
+ @Deprecated
private Class<BrooklynPropertiesSecurityFilter> securityFilterClazz;
+
+ @SetFromFlag
+ private boolean skipSecurity = false;
private ShutdownHandler shutdownHandler;
@@ -226,10 +238,16 @@ public class BrooklynWebServer {
this(MutableMap.of("port", port, "war", warUrl), managementContext);
}
+ /** @deprecated since 0.9.0, use {@link #skipSecurity} or {@link BrooklynLoginModule} */
+ @Deprecated
public void setSecurityFilter(Class<BrooklynPropertiesSecurityFilter> filterClazz) {
this.securityFilterClazz = filterClazz;
}
+ public void skipSecurity(boolean skipSecurity) {
+ this.skipSecurity = skipSecurity;
+ }
+
public void setShutdownHandler(@Nullable ShutdownHandler shutdownHandler) {
this.shutdownHandler = shutdownHandler;
}
@@ -613,10 +631,27 @@ public class BrooklynWebServer {
*/
public WebAppContext deploy(WebAppContextProvider contextProvider) {
WebAppContext context = contextProvider.get(managementContext, attributes, ignoreWebappDeploymentFailures);
+ initSecurity(context);
deploy(context);
return context;
}
+ private void initSecurity(WebAppContext context) {
+ if (skipSecurity) {
+ // Could add <security-constraint> in an override web.xml here
+ // instead of relying on the war having it (useful for downstream).
+ // context.addOverrideDescriptor("override-web.xml");
+ // But then should do the same in OSGi. For now require the web.xml
+ // to have security pre-configured and ignore it if noConsoleSecurity used.
+ //
+ // Ignore security config in web.xml.
+ context.setDefaultSecurityHandlerClass(NopSecurityHandler.class);
+ } else {
+ // Cover for downstream projects which don't have the changes.
+ context.addOverrideDescriptor(getClass().getResource("/web-security.xml").toExternalForm());
+ }
+ }
+
public void deploy(WebAppContext context) {
try {
handlers.updateHandler(context);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9b318cd9/launcher/src/main/java/org/apache/brooklyn/launcher/NopSecurityHandler.java
----------------------------------------------------------------------
diff --git a/launcher/src/main/java/org/apache/brooklyn/launcher/NopSecurityHandler.java b/launcher/src/main/java/org/apache/brooklyn/launcher/NopSecurityHandler.java
new file mode 100644
index 0000000..88b2a27
--- /dev/null
+++ b/launcher/src/main/java/org/apache/brooklyn/launcher/NopSecurityHandler.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.launcher;
+
+import org.eclipse.jetty.security.ConstraintMapping;
+import org.eclipse.jetty.security.ConstraintSecurityHandler;
+
+/**
+ * Ignores <security-constraint> elements from web.xml, so
+ * we can skip configuration even if requested by web app.
+ */
+public class NopSecurityHandler extends ConstraintSecurityHandler {
+
+ @Override
+ public void addConstraintMapping(ConstraintMapping mapping) {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9b318cd9/launcher/src/main/resources/web-security.xml
----------------------------------------------------------------------
diff --git a/launcher/src/main/resources/web-security.xml b/launcher/src/main/resources/web-security.xml
new file mode 100644
index 0000000..2311458
--- /dev/null
+++ b/launcher/src/main/resources/web-security.xml
@@ -0,0 +1,51 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
+ version="3.1">
+
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>Logout</web-resource-name>
+ <url-pattern>/v1/logout</url-pattern>
+ </web-resource-collection>
+ </security-constraint>
+
+ <!-- Ignored programmatically if noConsoleSecurity -->
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>All</web-resource-name>
+ <url-pattern>/</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>webconsole</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>webconsole</realm-name>
+ </login-config>
+
+ <security-role>
+ <role-name>webconsole</role-name>
+ </security-role>
+
+</web-app>
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9b318cd9/launcher/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java b/launcher/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java
index c3c94bc..524e752 100644
--- a/launcher/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java
@@ -83,13 +83,13 @@ public class BrooklynEntityMirrorIntegrationTest {
protected void setUpServer() {
setUpServer(new LocalManagementContextForTests(), false);
}
- protected void setUpServer(ManagementContext mgmt, boolean useSecurityFilter) {
+ protected void setUpServer(ManagementContext mgmt, boolean skipSecurity) {
try {
if (serverMgmt!=null) throw new IllegalStateException("server already set up");
serverMgmt = mgmt;
server = new BrooklynWebServer(mgmt);
- if (useSecurityFilter) server.setSecurityFilter(BrooklynPropertiesSecurityFilter.class);
+ server.skipSecurity(skipSecurity);
server.start();
serverMgmt.getHighAvailabilityManager().disabled();