This is an automated email from the ASF dual-hosted git repository.

duncangrant pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


The following commit(s) were added to refs/heads/master by this push:
     new aae4b8d  Improve extra header name, cleanup NPE
     new ece0a6f  Merge pull request #1182 from duncangrant/fix-login-form
aae4b8d is described below

commit aae4b8d520b05646bdde323035fac9932205c6ce
Author: Duncan Grant <[email protected]>
AuthorDate: Mon Jun 7 13:39:35 2021 +0100

    Improve extra header name, cleanup NPE
    
    Additional header for when using login form now uses X_ to show it is
    non-standard.
    
    Handles NPE when server still starting.
---
 .../rest/filter/BrooklynSecurityProviderFilterJavax.java     | 12 +++++++++++-
 .../rest/filter/BrooklynSecurityProviderFilterJersey.java    |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git 
a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/filter/BrooklynSecurityProviderFilterJavax.java
 
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/filter/BrooklynSecurityProviderFilterJavax.java
index 0856f38..552fb23 100644
--- 
a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/filter/BrooklynSecurityProviderFilterJavax.java
+++ 
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/filter/BrooklynSecurityProviderFilterJavax.java
@@ -38,6 +38,7 @@ import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.rest.BrooklynWebConfig;
 import 
org.apache.brooklyn.rest.security.provider.SecurityProvider.SecurityProviderDeniedAuthentication;
 import org.apache.brooklyn.rest.util.ManagementContextProvider;
+import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.text.Strings;
 import org.eclipse.jetty.http.HttpHeader;
 import org.slf4j.Logger;
@@ -66,7 +67,7 @@ public class BrooklynSecurityProviderFilterJavax implements 
Filter {
         try {
             log.trace("BrooklynSecurityProviderFilterJavax.doFilter {}", 
request);
             ManagementContext mgmt = new 
ManagementContextProvider(request.getServletContext()).getManagementContext();
-            loginPage =  mgmt.getConfig().getConfig(LOGIN_FORM);
+            loginPage = getLoginPageFromContext(mgmt);
 
             Preconditions.checkNotNull(mgmt, "Brooklyn management context not 
available; cannot authenticate");
             new 
BrooklynSecurityProviderFilterHelper().run((HttpServletRequest)request, mgmt);
@@ -101,6 +102,15 @@ public class BrooklynSecurityProviderFilterJavax 
implements Filter {
         }
     }
 
+    /**
+     * While starting the management context can be null which will throw an 
NPE and looks
+     * bad although there would still be no available functionality
+     */
+    private String getLoginPageFromContext(ManagementContext mgmt) {
+        if (mgmt == null) return "";
+        return mgmt.getConfig() == null ? "" : 
mgmt.getConfig().getConfig(LOGIN_FORM);
+    }
+
     @Override
     public void destroy() {
         // no clean-up needed
diff --git 
a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/filter/BrooklynSecurityProviderFilterJersey.java
 
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/filter/BrooklynSecurityProviderFilterJersey.java
index 73c964e..75e890f 100644
--- 
a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/filter/BrooklynSecurityProviderFilterJersey.java
+++ 
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/filter/BrooklynSecurityProviderFilterJersey.java
@@ -44,7 +44,7 @@ import org.slf4j.LoggerFactory;
 public class BrooklynSecurityProviderFilterJersey implements 
ContainerRequestFilter {
 
     private static final Logger log = 
LoggerFactory.getLogger(BrooklynSecurityProviderFilterJersey.class);
-    public static final String LOGIN_PAGE_HEADER = "LOGIN_PAGE";
+    public static final String LOGIN_PAGE_HEADER = "X_BROOKLYN_LOGIN_PAGE";
 
     @Context
     HttpServletRequest webRequest;

Reply via email to