From ae71aa7102a41735e49ec5c98409bc69fffd9a8f Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Wed, 30 Apr 2014 01:22:13 +0000 Subject: QPID-5578 : [Java Broker] Use annotation to allow registration of all ConfiguredObject types at startup. Use this meta data for REST servlets. Remove unnecessary pluggable factory interfaces git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1591170 13f79535-47bb-0310-9956-ffa450edef68 --- .../management/plugin/HttpManagementUtil.java | 5 +- .../action/AbstractSpecialisedAttributeLister.java | 77 ++++++++++++++++++++++ .../ListAccessControlProviderAttributes.java | 47 ++----------- .../ListAuthenticationProviderAttributes.java | 46 ++----------- .../rest/action/ListGroupProviderAttributes.java | 46 ++----------- 5 files changed, 92 insertions(+), 129 deletions(-) create mode 100644 qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/AbstractSpecialisedAttributeLister.java (limited to 'qpid/java/broker-plugins/management-http/src') diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementUtil.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementUtil.java index 0ed97ac3a0..1937ee8744 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementUtil.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementUtil.java @@ -34,6 +34,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.commons.codec.binary.Base64; + import org.apache.qpid.server.management.plugin.servlet.ServletConnectionPrincipal; import org.apache.qpid.server.management.plugin.session.LoginLogoutReporter; import org.apache.qpid.server.model.AuthenticationProvider; @@ -44,7 +45,7 @@ import org.apache.qpid.server.security.auth.AuthenticatedPrincipal; import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; import org.apache.qpid.server.security.auth.SubjectAuthenticationResult; import org.apache.qpid.server.security.auth.UsernamePrincipal; -import org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManagerFactory; +import org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManager; import org.apache.qpid.transport.network.security.ssl.SSLUtil; public class HttpManagementUtil @@ -162,7 +163,7 @@ public class HttpManagementUtil { principal = certificates[0].getSubjectX500Principal(); - if(!Boolean.valueOf(String.valueOf(authenticationProvider.getAttribute(ExternalAuthenticationManagerFactory.ATTRIBUTE_USE_FULL_DN)))) + if(!Boolean.valueOf(String.valueOf(authenticationProvider.getAttribute(ExternalAuthenticationManager.ATTRIBUTE_USE_FULL_DN)))) { String username; String dn = ((X500Principal) principal).getName(X500Principal.RFC2253); diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/AbstractSpecialisedAttributeLister.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/AbstractSpecialisedAttributeLister.java new file mode 100644 index 0000000000..173e4fce66 --- /dev/null +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/AbstractSpecialisedAttributeLister.java @@ -0,0 +1,77 @@ +/* + * + * 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.qpid.server.management.plugin.servlet.rest.action; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.apache.qpid.server.management.plugin.servlet.rest.Action; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.ConfiguredObjectAttribute; +import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; + +abstract class AbstractSpecialisedAttributeLister implements Action +{ + + + private static final String ATTRIBUTES = "attributes"; + private static final String DESCRIPTIONS = "descriptions"; + + @Override + final public Object perform(Map request, Broker broker) + { + Collection> groupProviderTypes = + ConfiguredObjectTypeRegistry.getTypeSpecialisations(getCategoryClass()); + + Map attributes = new TreeMap(); + + for (Class groupProviderType : groupProviderTypes) + { + Collection> typeSpecificAttributes = + ConfiguredObjectTypeRegistry.getTypeSpecificAttributes(groupProviderType); + + Map data = new HashMap(); + + Collection attributeNames = new TreeSet<>(); + Map descriptions = new HashMap<>(); + for(ConfiguredObjectAttribute attr : typeSpecificAttributes) + { + attributeNames.add(attr.getName()); + if(!"".equals(attr.getAnnotation().description())) + { + descriptions.put(attr.getName(), attr.getAnnotation().description()); + } + } + data.put(ATTRIBUTES, attributeNames); + data.put(DESCRIPTIONS, descriptions); + + attributes.put(ConfiguredObjectTypeRegistry.getType(groupProviderType), data); + } + return attributes; + } + + abstract Class getCategoryClass(); + +} diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListAccessControlProviderAttributes.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListAccessControlProviderAttributes.java index 84d05997b5..1eb3f9a9ac 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListAccessControlProviderAttributes.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListAccessControlProviderAttributes.java @@ -20,32 +20,10 @@ */ package org.apache.qpid.server.management.plugin.servlet.rest.action; -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; +import org.apache.qpid.server.model.AccessControlProvider; -import org.apache.qpid.server.management.plugin.servlet.rest.Action; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.plugin.AccessControlProviderFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; - -public class ListAccessControlProviderAttributes implements Action +public class ListAccessControlProviderAttributes extends AbstractSpecialisedAttributeLister { - private static final String ATTRIBUTES = "attributes"; - private static final String DESCRIPTIONS = "descriptions"; - private Map _factories; - - public ListAccessControlProviderAttributes() - { - _factories = new TreeMap(); - Iterable factories = new QpidServiceLoader() - .instancesOf(AccessControlProviderFactory.class); - for (AccessControlProviderFactory factory : factories) - { - _factories.put(factory.getType(), factory); - } - } - @Override public String getName() { @@ -53,25 +31,8 @@ public class ListAccessControlProviderAttributes implements Action } @Override - public Object perform(Map request, Broker broker) + Class getCategoryClass() { - Map attributes = new TreeMap(); - for (String providerType : _factories.keySet()) - { - AccessControlProviderFactory factory = _factories.get(providerType); - - Map data = new HashMap(); - // TODO RG - fix - // data.put(ATTRIBUTES, factory.getAttributeNames()); - Map resources = factory.getAttributeDescriptions(); - if (resources != null) - { - data.put(DESCRIPTIONS, resources); - } - - attributes.put(factory.getType(), data); - } - return attributes; + return AccessControlProvider.class; } - } diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListAuthenticationProviderAttributes.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListAuthenticationProviderAttributes.java index 5c629587e0..3e006a705a 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListAuthenticationProviderAttributes.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListAuthenticationProviderAttributes.java @@ -20,32 +20,10 @@ */ package org.apache.qpid.server.management.plugin.servlet.rest.action; -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; +import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.management.plugin.servlet.rest.Action; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.plugin.AuthenticationManagerFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; - -public class ListAuthenticationProviderAttributes implements Action +public class ListAuthenticationProviderAttributes extends AbstractSpecialisedAttributeLister { - private static final String ATTRIBUTES = "attributes"; - private static final String DESCRIPTIONS = "descriptions"; - private Map _factories; - - public ListAuthenticationProviderAttributes() - { - _factories = new TreeMap(); - Iterable factories = new QpidServiceLoader() - .instancesOf(AuthenticationManagerFactory.class); - for (AuthenticationManagerFactory factory : factories) - { - _factories.put(factory.getType(), factory); - } - } - @Override public String getName() { @@ -53,24 +31,8 @@ public class ListAuthenticationProviderAttributes implements Action } @Override - public Object perform(Map request, Broker broker) + Class getCategoryClass() { - Map attributes = new TreeMap(); - for (String providerType : _factories.keySet()) - { - AuthenticationManagerFactory factory = _factories.get(providerType); - - Map data = new HashMap(); - data.put(ATTRIBUTES, factory.getAttributeNames()); - Map resources = factory.getAttributeDescriptions(); - if (resources != null) - { - data.put(DESCRIPTIONS, resources); - } - - attributes.put(factory.getType(), data); - } - return attributes; + return AuthenticationProvider.class; } - } diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListGroupProviderAttributes.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListGroupProviderAttributes.java index d1414faa71..ecb4320f1f 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListGroupProviderAttributes.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListGroupProviderAttributes.java @@ -20,32 +20,10 @@ */ package org.apache.qpid.server.management.plugin.servlet.rest.action; -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; +import org.apache.qpid.server.model.GroupProvider; -import org.apache.qpid.server.management.plugin.servlet.rest.Action; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.plugin.GroupManagerFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; - -public class ListGroupProviderAttributes implements Action +public class ListGroupProviderAttributes extends AbstractSpecialisedAttributeLister { - private static final String ATTRIBUTES = "attributes"; - private static final String DESCRIPTIONS = "descriptions"; - private Map _factories; - - public ListGroupProviderAttributes() - { - _factories = new TreeMap(); - Iterable factories = new QpidServiceLoader() - .instancesOf(GroupManagerFactory.class); - for (GroupManagerFactory factory : factories) - { - _factories.put(factory.getType(), factory); - } - } - @Override public String getName() { @@ -53,24 +31,8 @@ public class ListGroupProviderAttributes implements Action } @Override - public Object perform(Map request, Broker broker) + Class getCategoryClass() { - Map attributes = new TreeMap(); - for (String providerType : _factories.keySet()) - { - GroupManagerFactory factory = _factories.get(providerType); - - Map data = new HashMap(); - data.put(ATTRIBUTES, factory.getAttributeNames()); - Map resources = factory.getAttributeDescriptions(); - if (resources != null) - { - data.put(DESCRIPTIONS, resources); - } - - attributes.put(factory.getType(), data); - } - return attributes; + return GroupProvider.class; } - } -- cgit v1.2.1