javax.ws.rs
javax.ws.rs-api
diff --git a/rest/rest-server/src/main/java/org/apache/brooklyn/rest/filter/BrooklynPropertiesSecurityFilter.java b/rest/rest-server/src/main/java/org/apache/brooklyn/rest/filter/BrooklynPropertiesSecurityFilter.java
index 6dd84e0623..c1d2d9f749 100644
--- a/rest/rest-server/src/main/java/org/apache/brooklyn/rest/filter/BrooklynPropertiesSecurityFilter.java
+++ b/rest/rest-server/src/main/java/org/apache/brooklyn/rest/filter/BrooklynPropertiesSecurityFilter.java
@@ -35,6 +35,8 @@
import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
import org.apache.brooklyn.core.mgmt.entitlement.WebEntitlementContext;
import org.apache.brooklyn.rest.BrooklynWebConfig;
+import org.apache.brooklyn.rest.resources.LogoutResource;
+import org.apache.brooklyn.rest.security.jaas.BrooklynLoginModule;
import org.apache.brooklyn.rest.security.provider.DelegatingSecurityProvider;
import org.apache.brooklyn.rest.util.OsgiCompat;
import org.apache.brooklyn.util.text.Strings;
@@ -44,7 +46,10 @@
/**
* Provides basic HTTP authentication.
+ *
+ * @deprecated since 0.9.0, use JAAS authentication instead, see {@link BrooklynLoginModule}, {@link LogoutResource}, {@link EntitlementContextFilter}.
*/
+@Deprecated
public class BrooklynPropertiesSecurityFilter implements Filter {
/**
@@ -53,7 +58,7 @@ public class BrooklynPropertiesSecurityFilter implements Filter {
* the providers may impose additional criteria such as timeouts,
* or a null user (no login) may be permitted)
*/
- public static final String AUTHENTICATED_USER_SESSION_ATTRIBUTE = "brooklyn.user";
+ public static final String AUTHENTICATED_USER_SESSION_ATTRIBUTE = BrooklynLoginModule.AUTHENTICATED_USER_SESSION_ATTRIBUTE;
/**
* The session attribute set to indicate the remote address of the HTTP request.
diff --git a/rest/rest-server/src/main/java/org/apache/brooklyn/rest/filter/HaMasterCheckFilter.java b/rest/rest-server/src/main/java/org/apache/brooklyn/rest/filter/HaMasterCheckFilter.java
index bfb1caf73e..156479d7e9 100644
--- a/rest/rest-server/src/main/java/org/apache/brooklyn/rest/filter/HaMasterCheckFilter.java
+++ b/rest/rest-server/src/main/java/org/apache/brooklyn/rest/filter/HaMasterCheckFilter.java
@@ -44,8 +44,10 @@
*
* Post POSTs and PUTs are assumed to need master state, with the exception of shutdown.
* Requests with {@link #SKIP_CHECK_HEADER} set as a header skip this check.
+ *
+ * @deprecated since 0.9.0. Use JAX-RS {@link HaHotCheckResourceFilter} instead.
*/
-// TODO Merge with HaHotCheckResourceFilter so the functionality is available in Karaf
+@Deprecated
public class HaMasterCheckFilter implements Filter {
private static final Set SAFE_STANDBY_METHODS = Sets.newHashSet("GET", "HEAD");
diff --git a/rest/rest-server/src/main/java/org/apache/brooklyn/rest/filter/RequestTaggingFilter.java b/rest/rest-server/src/main/java/org/apache/brooklyn/rest/filter/RequestTaggingFilter.java
index 3553aaa1b0..85f5bf2f95 100644
--- a/rest/rest-server/src/main/java/org/apache/brooklyn/rest/filter/RequestTaggingFilter.java
+++ b/rest/rest-server/src/main/java/org/apache/brooklyn/rest/filter/RequestTaggingFilter.java
@@ -33,7 +33,7 @@
* Tags each request with a probabilistically unique id. Should be included before other
* filters to make sense.
*/
-//TODO Re-implement as JAX-RS filter
+// TODO Deprecate after porting LoggingFilter
public class RequestTaggingFilter implements Filter {
private static ThreadLocal tag = new ThreadLocal();
@@ -45,6 +45,7 @@ protected static String getTag() {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
String requestId = Identifiers.makeRandomId(6);
+ request.setAttribute(RequestTaggingRsFilter.ATT_REQUEST_ID, requestId);
tag.set(requestId);
try {
chain.doFilter(request, response);
diff --git a/rest/rest-server/src/main/webapp/WEB-INF/web.xml b/rest/rest-server/src/main/webapp/WEB-INF/web.xml
index 7ae55a0cb7..b763b8ee2b 100644
--- a/rest/rest-server/src/main/webapp/WEB-INF/web.xml
+++ b/rest/rest-server/src/main/webapp/WEB-INF/web.xml
@@ -29,15 +29,6 @@
/*
-
- Brooklyn Properties Authentication Filter
- org.apache.brooklyn.rest.filter.BrooklynPropertiesSecurityFilter
-
-
- Brooklyn Properties Authentication Filter
- /*
-
-
Brooklyn Logging Filter
org.apache.brooklyn.rest.filter.LoggingFilter
@@ -47,15 +38,6 @@
/*
-
- Brooklyn HA Master Filter
- org.apache.brooklyn.rest.filter.HaMasterCheckFilter
-
-
- Brooklyn HA Master Filter
- /*
-
-
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 d9f0f1a1b5..afec450817 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
@@ -36,10 +36,13 @@
import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
import org.apache.brooklyn.core.server.BrooklynServerConfig;
import org.apache.brooklyn.core.server.BrooklynServiceAttributes;
-import org.apache.brooklyn.rest.filter.BrooklynPropertiesSecurityFilter;
-import org.apache.brooklyn.rest.filter.HaMasterCheckFilter;
+import org.apache.brooklyn.rest.filter.EntitlementContextFilter;
+import org.apache.brooklyn.rest.filter.HaHotCheckResourceFilter;
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.RolePrincipal;
import org.apache.brooklyn.rest.security.provider.AnyoneSecurityProvider;
import org.apache.brooklyn.rest.security.provider.SecurityProvider;
import org.apache.brooklyn.rest.util.ManagementContextProvider;
@@ -51,6 +54,7 @@
import org.apache.brooklyn.util.net.Networking;
import org.apache.brooklyn.util.os.Os;
import org.apache.brooklyn.util.text.WildcardGlobs;
+import org.eclipse.jetty.jaas.JAASLoginService;
import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
@@ -89,11 +93,9 @@ enum StartMode {
SERVLET, /** web-xml is not fully supported */ @Beta WEB_XML
}
- public static final List> DEFAULT_FILTERS = ImmutableList.of(
+ public static final List> DEFAULT_FILTERS = ImmutableList.>of(
RequestTaggingFilter.class,
- BrooklynPropertiesSecurityFilter.class,
- LoggingFilter.class,
- HaMasterCheckFilter.class);
+ LoggingFilter.class);
private boolean forceUseOfDefaultCatalogWithJavaClassPath = false;
private Class extends SecurityProvider> securityProvider;
@@ -217,8 +219,12 @@ private ContextHandler servletContextHandler(ManagementContext managementContext
installWar(context);
RestApiSetup.installRest(context,
- new ManagementContextProvider(managementContext),
- new ShutdownHandlerProvider(shutdownListener));
+ new ManagementContextProvider(),
+ new ShutdownHandlerProvider(shutdownListener),
+ new RequestTaggingRsFilter(),
+ new NoCacheFilter(),
+ new HaHotCheckResourceFilter(),
+ new EntitlementContextFilter());
RestApiSetup.installServletFilters(context, this.filters);
context.setContextPath("/");
@@ -245,7 +251,6 @@ private void installWar(WebAppContext context) {
/** NB: not fully supported; use one of the other {@link StartMode}s */
private ContextHandler webXmlContextHandler(ManagementContext mgmt) {
RestApiSetup.initSwagger();
- // TODO add security to web.xml
WebAppContext context;
if (findMatchingFile("src/main/webapp")!=null) {
// running in source mode; need to use special classpath
@@ -290,7 +295,9 @@ public static Server startServer(ManagementContext mgmt, ContextHandler context,
@Deprecated
public static Server startServer(ContextHandler context, String summary, InetSocketAddress bindLocation) {
Server server = new Server(bindLocation);
-
+
+ initJaas(server);
+
server.setHandler(context);
try {
server.start();
@@ -303,6 +310,15 @@ public static Server startServer(ContextHandler context, String summary, InetSoc
return server;
}
+ // TODO Why parallel code for server init here and in BrooklynWebServer?
+ private static void initJaas(Server server) {
+ JAASLoginService loginService = new JAASLoginService();
+ loginService.setName("webconsole");
+ loginService.setLoginModuleName("webconsole");
+ loginService.setRoleClassNames(new String[] {RolePrincipal.class.getName()});
+ server.addBean(loginService);
+ }
+
public static BrooklynRestApiLauncher launcher() {
return new BrooklynRestApiLauncher();
}