qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oru...@apache.org
Subject svn commit: r1524063 - in /qpid/trunk/qpid/java/broker-plugins/management-http/src: main/java/org/apache/qpid/server/management/plugin/ main/java/org/apache/qpid/server/management/plugin/servlet/rest/ test/java/org/apache/qpid/server/management/plugin/
Date Tue, 17 Sep 2013 14:27:09 GMT
Author: orudyy
Date: Tue Sep 17 14:27:08 2013
New Revision: 1524063

URL: http://svn.apache.org/r1524063
Log:
QPID-5138: Change http management to use AuthenticationProvider for getting references to
SubjectCreator and PreferencesProvider

Modified:
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementUtil.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/UserPreferencesServlet.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementTest.java

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java?rev=1524063&r1=1524062&r2=1524063&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java
(original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java
Tue Sep 17 14:27:08 2013
@@ -23,8 +23,6 @@ package org.apache.qpid.server.managemen
 import java.lang.reflect.Type;
 import java.net.SocketAddress;
 import java.security.GeneralSecurityException;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumSet;
@@ -78,7 +76,6 @@ import org.apache.qpid.server.model.User
 import org.apache.qpid.server.model.VirtualHost;
 import org.apache.qpid.server.model.adapter.AbstractPluginAdapter;
 import org.apache.qpid.server.plugin.PluginFactory;
-import org.apache.qpid.server.security.SubjectCreator;
 import org.apache.qpid.server.util.MapValueConverter;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.DispatcherType;
@@ -431,9 +428,9 @@ public class HttpManagement extends Abst
     }
 
     @Override
-    public SubjectCreator getSubjectCreator(SocketAddress localAddress)
+    public AuthenticationProvider getAuthenticationProvider(SocketAddress localAddress)
     {
-        return getBroker().getSubjectCreator(localAddress);
+        return getBroker().getAuthenticationProvider(localAddress);
     }
 
     @Override

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java?rev=1524063&r1=1524062&r2=1524063&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java
(original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java
Tue Sep 17 14:27:08 2013
@@ -22,7 +22,7 @@ package org.apache.qpid.server.managemen
 
 import java.net.SocketAddress;
 
-import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.model.AuthenticationProvider;
 
 public interface HttpManagementConfiguration
 {
@@ -34,5 +34,5 @@ public interface HttpManagementConfigura
 
     boolean isHttpBasicAuthenticationEnabled();
 
-    SubjectCreator getSubjectCreator(SocketAddress localAddress);
+    AuthenticationProvider getAuthenticationProvider(SocketAddress localAddress);
 }

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementUtil.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementUtil.java?rev=1524063&r1=1524062&r2=1524063&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementUtil.java
(original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementUtil.java
Tue Sep 17 14:27:08 2013
@@ -168,7 +168,7 @@ public class HttpManagementUtil
     {
         Subject subject = null;
         SocketAddress localAddress = getSocketAddress(request);
-        SubjectCreator subjectCreator = managementConfig.getSubjectCreator(localAddress);
+        SubjectCreator subjectCreator = managementConfig.getAuthenticationProvider(localAddress).getSubjectCreator();
         String remoteUser = request.getRemoteUser();
 
         if (remoteUser != null || subjectCreator.isAnonymousAuthenticationAllowed())

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java?rev=1524063&r1=1524062&r2=1524063&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java
(original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java
Tue Sep 17 14:27:08 2013
@@ -14,7 +14,6 @@ import javax.servlet.http.HttpServletRes
 
 import org.apache.qpid.server.management.plugin.HttpManagementUtil;
 import org.apache.qpid.server.model.AuthenticationProvider;
-import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.model.PreferencesProvider;
 import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
 import org.codehaus.jackson.map.ObjectMapper;
@@ -28,6 +27,11 @@ public class PreferencesServlet extends 
             ServletException
     {
         PreferencesProvider preferencesProvider = getPreferencesProvider(request);
+        if (preferencesProvider == null)
+        {
+            response.sendError(HttpServletResponse.SC_NOT_FOUND, "Preferences provider is
not configured");
+            return;
+        }
         String userName = getAuthenticatedUserName(request);
         Map<String, Object> preferences = preferencesProvider.getPreferences(userName);
         if (preferences == null)
@@ -45,6 +49,11 @@ public class PreferencesServlet extends 
             throws ServletException, IOException
     {
         PreferencesProvider preferencesProvider = getPreferencesProvider(request);
+        if (preferencesProvider == null)
+        {
+            response.sendError(HttpServletResponse.SC_NOT_FOUND, "Preferences provider is
not configured");
+            return;
+        }
         String userName = getAuthenticatedUserName(request);
 
         ObjectMapper mapper = new ObjectMapper();
@@ -69,6 +78,10 @@ public class PreferencesServlet extends 
             throws ServletException, IOException
     {
         PreferencesProvider preferencesProvider = getPreferencesProvider(request);
+        if (preferencesProvider == null)
+        {
+            throw new IllegalStateException("Preferences provider is not configured");
+        }
         String userName = getAuthenticatedUserName(request);
 
         ObjectMapper mapper = new ObjectMapper();
@@ -90,20 +103,14 @@ public class PreferencesServlet extends 
         return principal.getName();
     }
 
-    private AuthenticationProvider getAuthenticationProvider(HttpServletRequest request)
-    {
-        Broker broker = getBroker();
-        SocketAddress localAddress = HttpManagementUtil.getSocketAddress(request);
-        return broker.getAuthenticationProvider(localAddress);
-    }
-
     private PreferencesProvider getPreferencesProvider(HttpServletRequest request)
     {
-        PreferencesProvider preferencesProvider = getAuthenticationProvider(request).getPreferencesProvider();
-        if (preferencesProvider == null)
+        SocketAddress localAddress = HttpManagementUtil.getSocketAddress(request);
+        AuthenticationProvider authenticationProvider = getManagementConfiguration().getAuthenticationProvider(localAddress);
+        if (authenticationProvider == null)
         {
-            throw new IllegalStateException("Preferences provider is not configured");
+            throw new IllegalStateException("Authentication provider is not found");
         }
-        return preferencesProvider;
+        return authenticationProvider.getPreferencesProvider();
     }
 }

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java?rev=1524063&r1=1524062&r2=1524063&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
(original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
Tue Sep 17 14:27:08 2013
@@ -278,7 +278,7 @@ public class SaslServlet extends Abstrac
     private SubjectCreator getSubjectCreator(HttpServletRequest request)
     {
         SocketAddress localAddress = HttpManagementUtil.getSocketAddress(request);
-        return HttpManagementUtil.getManagementConfiguration(getServletContext()).getSubjectCreator(localAddress);
+        return HttpManagementUtil.getManagementConfiguration(getServletContext()).getAuthenticationProvider(localAddress).getSubjectCreator();
     }
 
     @Override

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/UserPreferencesServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/UserPreferencesServlet.java?rev=1524063&r1=1524062&r2=1524063&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/UserPreferencesServlet.java
(original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/UserPreferencesServlet.java
Tue Sep 17 14:27:08 2013
@@ -47,15 +47,14 @@ public class UserPreferencesServlet exte
             throws IOException
     {
         Map<String, Object> preferences = null;
-        try
+        PreferencesProvider preferencesProvider = getPreferencesProvider(authenticationProviderName);
+        if (preferencesProvider == null)
         {
-            preferences = getUserPreferences(authenticationProviderName, userId);
-        }
-        catch (Exception e)
-        {
-            LOGGER.debug("Bad preferences request", e);
-            response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
+            response.sendError(HttpServletResponse.SC_NOT_FOUND, "Preferences provider is
not configured");
+            return;
         }
+        preferences =  preferencesProvider.getPreferences(userId);
+
         sendJsonResponse(preferences, response);
     }
 
@@ -74,7 +73,7 @@ public class UserPreferencesServlet exte
         sendJsonResponse(users, response);
     }
 
-    private Map<String, Object> getUserPreferences(String authenticationProviderName,
String userId)
+    private PreferencesProvider getPreferencesProvider(String authenticationProviderName)
     {
         AuthenticationProvider authenticationProvider = getAuthenticationProvider(authenticationProviderName);
         if (authenticationProvider == null)
@@ -83,12 +82,7 @@ public class UserPreferencesServlet exte
                     authenticationProviderName));
         }
         PreferencesProvider preferencesProvider = authenticationProvider.getPreferencesProvider();
-        if (preferencesProvider == null)
-        {
-            throw new IllegalStateException(String.format(
-                    "Preferences provider is not set for authentication provider '%s'", authenticationProviderName));
-        }
-        return preferencesProvider.getPreferences(userId);
+        return preferencesProvider;
     }
 
     private AuthenticationProvider getAuthenticationProvider(String authenticationProviderName)

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementTest.java?rev=1524063&r1=1524062&r2=1524063&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementTest.java
(original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementTest.java
Tue Sep 17 14:27:08 2013
@@ -29,6 +29,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 
+import org.apache.qpid.server.model.AuthenticationProvider;
 import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.security.SubjectCreator;
 import org.apache.qpid.test.utils.QpidTestCase;
@@ -88,13 +89,13 @@ public class HttpManagementTest extends 
                 _management.isHttpBasicAuthenticationEnabled());
     }
 
-    public void testGetSubjectCreator()
+    public void testGetAuthenticationProvider()
     {
         SocketAddress localAddress = InetSocketAddress.createUnresolved("localhost", 8080);
-        SubjectCreator subjectCreator = mock(SubjectCreator.class);
-        when(_broker.getSubjectCreator(localAddress)).thenReturn(subjectCreator);
-        SubjectCreator httpManagementSubjectCreator = _management.getSubjectCreator(localAddress);
-        assertEquals("Unexpected subject creator", subjectCreator, httpManagementSubjectCreator);
+        AuthenticationProvider brokerAuthenticationProvider = mock(AuthenticationProvider.class);
+        when(_broker.getAuthenticationProvider(localAddress)).thenReturn(brokerAuthenticationProvider);
+        AuthenticationProvider authenticationProvider = _management.getAuthenticationProvider(localAddress);
+        assertEquals("Unexpected subject creator", brokerAuthenticationProvider, authenticationProvider);
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message