geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r676690 - in /geronimo/components/jaspi/trunk/geronimo-jaspi/src: main/java/org/apache/geronimo/components/jaspi/ main/java/org/apache/geronimo/components/jaspi/model/ test/java/org/apache/geronimo/components/jaspi/
Date Mon, 14 Jul 2008 19:00:26 GMT
Author: djencks
Date: Mon Jul 14 12:00:26 2008
New Revision: 676690

URL: http://svn.apache.org/viewvc?rev=676690&view=rev
Log:
use jaxb magic to just have a map of ConfigProviderTypes

Added:
    geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderMapAdapter.java
  (with props)
Modified:
    geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/AuthConfigFactoryImpl.java
    geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderType.java
    geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/JaspiType.java
    geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/JaspiXmlUtil.java
    geronimo/components/jaspi/trunk/geronimo-jaspi/src/test/java/org/apache/geronimo/components/jaspi/AuthConfigFactoryImplTest.java

Modified: geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/AuthConfigFactoryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/AuthConfigFactoryImpl.java?rev=676690&r1=676689&r2=676690&view=diff
==============================================================================
--- geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/AuthConfigFactoryImpl.java
(original)
+++ geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/AuthConfigFactoryImpl.java
Mon Jul 14 12:00:26 2008
@@ -21,7 +21,6 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -45,7 +44,6 @@
 public class AuthConfigFactoryImpl extends AuthConfigFactory {
 
     private static ClassLoader contextClassLoader;
-    private final Map<String, ConfigProviderType> registrations = new HashMap<String,
ConfigProviderType>();
     private JaspiType jaspiType = new JaspiType();
 
     private final ClassLoaderLookup classLoaderLookup;
@@ -63,6 +61,7 @@
     }
 
     public AuthConfigFactoryImpl(ClassLoaderLookup classLoaderLookup, File configFile) throws
AuthException {
+        JaspiXmlUtil.registerClassLoaderLookup(classLoaderLookup);
         this.classLoaderLookup = classLoaderLookup;
         this.configFile = configFile;
         loadConfig();
@@ -83,7 +82,7 @@
             sm.checkPermission(new AuthPermission("detachAuthListener"));
         }
         List<String> ids = new ArrayList<String>();
-        for (Map.Entry<String, ConfigProviderType> entry : registrations.entrySet())
{
+        for (Map.Entry<String, ConfigProviderType> entry : getRegistrations().entrySet())
{
             ConfigProviderType ctx = entry.getValue();
             if ((layer == null || layer.equals(ctx.getMessageLayer())) &&
                     (appContext == null || appContext.equals(ctx.getAppContext()))) {
@@ -95,6 +94,10 @@
         return ids.toArray(new String[ids.size()]);
     }
 
+    private Map<String, ConfigProviderType> getRegistrations() {
+        return jaspiType.getConfigProvider();
+    }
+
     public synchronized AuthConfigProvider getConfigProvider(String layer, String appContext,
RegistrationListener listener) {
         if (layer == null) {
             throw new NullPointerException("messageLayer");
@@ -102,15 +105,15 @@
         if (appContext == null) {
             throw new NullPointerException("appContext");
         }
-        ConfigProviderType ctx = registrations.get(getRegistrationKey(layer, appContext));
+        ConfigProviderType ctx = getRegistrations().get(ConfigProviderType.getRegistrationKey(layer,
appContext));
         if (ctx == null) {
-            ctx = registrations.get(getRegistrationKey(null, appContext));
+            ctx = getRegistrations().get(ConfigProviderType.getRegistrationKey(null, appContext));
         }
         if (ctx == null) {
-            ctx = registrations.get(getRegistrationKey(layer, null));
+            ctx = getRegistrations().get(ConfigProviderType.getRegistrationKey(layer, null));
         }
         if (ctx == null) {
-            ctx = registrations.get(getRegistrationKey(null, null));
+            ctx = getRegistrations().get(ConfigProviderType.getRegistrationKey(null, null));
         }
         if (ctx != null) {
             if (listener != null) {
@@ -122,12 +125,12 @@
     }
 
     public synchronized RegistrationContext getRegistrationContext(String registrationID)
{
-        return registrations.get(registrationID);
+        return getRegistrations().get(registrationID);
     }
 
     public synchronized String[] getRegistrationIDs(AuthConfigProvider provider) {
         List<String> ids = new ArrayList<String>();
-        for (Map.Entry<String, ConfigProviderType> entry : registrations.entrySet())
{
+        for (Map.Entry<String, ConfigProviderType> entry : getRegistrations().entrySet())
{
             ConfigProviderType ctx = entry.getValue();
             if (provider == null ||
                     provider.getClass().getName().equals(ctx.getProvider().getClass().getName()))
{
@@ -164,11 +167,12 @@
     }
 
     private String registerConfigProvider(AuthConfigProvider provider, String layer, String
appContext, String description, boolean persistent, Map<String, String> constructorParam,
String className) throws AuthException {
-        String key = getRegistrationKey(layer, appContext);
+        String key = ConfigProviderType.getRegistrationKey(layer, appContext);
         // Get or create context
-        ConfigProviderType ctx = registrations.get(key);
+        ConfigProviderType ctx = getRegistrations().get(key);
         if (ctx == null) {
             ctx = new ConfigProviderType(layer, appContext, persistent);
+            getRegistrations().put(key, ctx);
         } else {
             if (persistent != ctx.isPersistent()) {
                 throw new IllegalArgumentException("Cannot change the persistence state");
@@ -176,7 +180,6 @@
         }
         // Create provider
         ctx.setDescription(description);
-        registrations.put(key, ctx);
         if (persistent) {
             if (provider != null) {
                 throw new IllegalStateException("Config provider supplied but should be created");
@@ -184,9 +187,6 @@
             ctx.setClassName(className);
             ctx.setProperties(constructorParam);
             ctx.createAuthConfigProvider(classLoaderLookup);
-            if (!jaspiType.getConfigProvider().contains(ctx)) {
-                jaspiType.getConfigProvider().add(ctx);
-            }
         } else {
             if (provider == null) {
                 throw new IllegalStateException("No config provider to set");
@@ -208,8 +208,7 @@
         if (sm != null) {
             sm.checkPermission(new AuthPermission("removeAuthRegistration"));
         }
-        ConfigProviderType ctx = registrations.remove(registrationID);
-        jaspiType.getConfigProvider().remove(ctx);
+        ConfigProviderType ctx = getRegistrations().remove(registrationID);
         try {
             saveConfig();
         } catch (AuthException e) {
@@ -225,20 +224,11 @@
         return false;
     }
     
-    private String getRegistrationKey(String layer, String appContext) {
-        return layer + "/" + appContext;
-    }
-    
     private void loadConfig() throws AuthException {
         try {
             FileReader in = new FileReader(configFile);
             try {
                 jaspiType = JaspiXmlUtil.loadJaspi(in);
-                for (ConfigProviderType configProviderType: jaspiType.getConfigProvider())
{
-                    String key = getRegistrationKey(configProviderType.getMessageLayer(),
configProviderType.getAppContext());
-                    configProviderType.createAuthConfigProvider(classLoaderLookup);
-                    registrations.put(key, configProviderType);
-                }
             } finally {
                 in.close();
             }

Added: geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderMapAdapter.java
URL: http://svn.apache.org/viewvc/geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderMapAdapter.java?rev=676690&view=auto
==============================================================================
--- geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderMapAdapter.java
(added)
+++ geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderMapAdapter.java
Mon Jul 14 12:00:26 2008
@@ -0,0 +1,73 @@
+/*
+ * 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.geronimo.components.jaspi.model;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+import org.apache.geronimo.components.jaspi.ClassLoaderLookup;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class ConfigProviderMapAdapter extends XmlAdapter<ConfigProviderType[], Map<String,
ConfigProviderType>> {
+
+    private final ClassLoaderLookup classLoaderLookup;
+
+    public ConfigProviderMapAdapter(ClassLoaderLookup classLoaderLookup) {
+        this.classLoaderLookup = classLoaderLookup;
+    }
+
+    public ConfigProviderMapAdapter() {
+        ClassLoader testLoader = Thread.currentThread().getContextClassLoader();
+        final ClassLoader cl = testLoader == null? ConfigProviderMapAdapter.class.getClassLoader():
testLoader;
+        classLoaderLookup = new ClassLoaderLookup() {
+
+            public ClassLoader getClassLoader(String name) {
+                return cl;
+            }
+        };
+    }
+
+    public Map<String, ConfigProviderType> unmarshal(ConfigProviderType[] configProviderTypes)
throws Exception {
+        Map<String, ConfigProviderType> map = new HashMap<String, ConfigProviderType>();
+        for (ConfigProviderType configProviderType: configProviderTypes) {
+            String key = configProviderType.getRegistrationKey();
+            map.put(key, configProviderType);
+            configProviderType.createAuthConfigProvider(classLoaderLookup);
+        }
+        return map;
+    }
+
+    public ConfigProviderType[] marshal(Map<String, ConfigProviderType> stringConfigProviderTypeMap)
throws Exception {
+        List<ConfigProviderType> list = new ArrayList<ConfigProviderType>();
+        for (ConfigProviderType configProviderType: stringConfigProviderTypeMap.values())
{
+            if (configProviderType.isPersistent()) {
+                list.add(configProviderType);
+            }
+        }
+        return list.toArray(new ConfigProviderType[stringConfigProviderTypeMap.size()]);
+    }
+}

Propchange: geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderMapAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderMapAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderMapAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderType.java
URL: http://svn.apache.org/viewvc/geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderType.java?rev=676690&r1=676689&r2=676690&view=diff
==============================================================================
--- geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderType.java
(original)
+++ geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/ConfigProviderType.java
Mon Jul 14 12:00:26 2008
@@ -285,4 +285,13 @@
         }
 
     }
+
+    public static String getRegistrationKey(String layer, String appContext) {
+        return layer + "/" + appContext;
+    }
+
+    public String getRegistrationKey() {
+        return getRegistrationKey(getMessageLayer(), getAppContext());
+    }
+
 }

Modified: geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/JaspiType.java
URL: http://svn.apache.org/viewvc/geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/JaspiType.java?rev=676690&r1=676689&r2=676690&view=diff
==============================================================================
--- geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/JaspiType.java
(original)
+++ geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/JaspiType.java
Mon Jul 14 12:00:26 2008
@@ -11,9 +11,13 @@
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
 import org.apache.geronimo.components.jaspi.model.ConfigProviderType;
 
@@ -46,7 +50,9 @@
 {
 
     private final static long serialVersionUID = 12343L;
-    protected List<ConfigProviderType> configProvider;
+
+    @XmlJavaTypeAdapter(ConfigProviderMapAdapter.class)
+    protected Map<String, ConfigProviderType> configProvider;
 
     /**
      * Gets the value of the configProvider property.
@@ -70,9 +76,9 @@
      * 
      * 
      */
-    public List<ConfigProviderType> getConfigProvider() {
+    public Map<String, ConfigProviderType> getConfigProvider() {
         if (configProvider == null) {
-            configProvider = new ArrayList<ConfigProviderType>();
+            configProvider = new HashMap<String, ConfigProviderType>();
         }
         return this.configProvider;
     }

Modified: geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/JaspiXmlUtil.java
URL: http://svn.apache.org/viewvc/geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/JaspiXmlUtil.java?rev=676690&r1=676689&r2=676690&view=diff
==============================================================================
--- geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/JaspiXmlUtil.java
(original)
+++ geronimo/components/jaspi/trunk/geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/model/JaspiXmlUtil.java
Mon Jul 14 12:00:26 2008
@@ -35,13 +35,15 @@
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.xml.sax.SAXException;
+import org.apache.geronimo.components.jaspi.ClassLoaderLookup;
 
 /**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  */
 public class JaspiXmlUtil {
     public static final XMLInputFactory XMLINPUT_FACTORY = XMLInputFactory.newInstance();
     public static final JAXBContext JASPI_CONTEXT;
+    private static ConfigProviderMapAdapter configProviderMapAdapter = new ConfigProviderMapAdapter();
 
     static {
         try {
@@ -51,8 +53,13 @@
         }
     }
 
+    public static void registerClassLoaderLookup(ClassLoaderLookup classLoaderLookup) {
+        configProviderMapAdapter = new ConfigProviderMapAdapter();
+    }
+
     public static void writeJaspi(JaspiType metadata, Writer out) throws XMLStreamException,
JAXBException {
         Marshaller marshaller = JASPI_CONTEXT.createMarshaller();
+        marshaller.setAdapter(configProviderMapAdapter);
         marshaller.setProperty("jaxb.formatted.output", true);
         JAXBElement<JaspiType> element = new ObjectFactory().createJaspi(metadata);
         marshaller.marshal(element, out);
@@ -66,6 +73,7 @@
 
     public static JaspiType loadJaspi(XMLStreamReader in) throws ParserConfigurationException,
IOException, SAXException, JAXBException, XMLStreamException {
         Unmarshaller unmarshaller = JASPI_CONTEXT.createUnmarshaller();
+        unmarshaller.setAdapter(configProviderMapAdapter);
         JAXBElement<JaspiType> element = unmarshaller.unmarshal(in, JaspiType.class);
         JaspiType rbac = element.getValue();
         return rbac;

Modified: geronimo/components/jaspi/trunk/geronimo-jaspi/src/test/java/org/apache/geronimo/components/jaspi/AuthConfigFactoryImplTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/jaspi/trunk/geronimo-jaspi/src/test/java/org/apache/geronimo/components/jaspi/AuthConfigFactoryImplTest.java?rev=676690&r1=676689&r2=676690&view=diff
==============================================================================
--- geronimo/components/jaspi/trunk/geronimo-jaspi/src/test/java/org/apache/geronimo/components/jaspi/AuthConfigFactoryImplTest.java
(original)
+++ geronimo/components/jaspi/trunk/geronimo-jaspi/src/test/java/org/apache/geronimo/components/jaspi/AuthConfigFactoryImplTest.java
Mon Jul 14 12:00:26 2008
@@ -89,7 +89,6 @@
         assertNotNull(factory.getConfigProvider("layer4", "appContext4", null));
         assertNull(factory.getConfigProvider("layer4", "bad", null));
         assertNull(factory.getConfigProvider("bad", "appContext4", null));
-//        assertNull(factory.getConfigProvider(null, null, null));
         factory.removeRegistration(registrationID);
         assertNull(factory.getRegistrationContext(registrationID));
     }
@@ -99,10 +98,8 @@
         String registrationID = factory.registerConfigProvider(DummyProvider.class.getName(),
null, "layer5", null, "description");
 
         assertNotNull(factory.getConfigProvider("layer5", "appContext5", null));
-//        assertNotNull(factory.getConfigProvider("layer5", null, null));
         assertNotNull(factory.getConfigProvider("layer5", "bad", null));
         assertNull(factory.getConfigProvider("bad", "appContext5", null));
-//        assertNull(factory.getConfigProvider(null, null, null));
         factory.removeRegistration(registrationID);
         assertNull(factory.getRegistrationContext(registrationID));
     }
@@ -112,10 +109,8 @@
         String registrationID = factory.registerConfigProvider(DummyProvider.class.getName(),
null, null, "appContext6", "description");
 
         assertNotNull(factory.getConfigProvider("layer6", "appContext6", null));
-//        assertNull(factory.getConfigProvider("layer6", null, null));
         assertNull(factory.getConfigProvider("layer6", "bad", null));
         assertNotNull(factory.getConfigProvider("bad", "appContext6", null));
-//        assertNull(factory.getConfigProvider(null, null, null));
         factory.removeRegistration(registrationID);
         assertNull(factory.getRegistrationContext(registrationID));
     }
@@ -125,7 +120,6 @@
         String registrationID = factory.registerConfigProvider(DummyProvider.class.getName(),
null, null, null, "description");
 
         assertNotNull(factory.getConfigProvider("layer7", "appContext7", null));
-//        assertNotNull(factory.getConfigProvider("layer7", null, null));
         assertNotNull(factory.getConfigProvider("layer7", "bad", null));
         assertNotNull(factory.getConfigProvider("bad", "appContext7", null));
         assertNotNull(factory.getConfigProvider("bad", "bad", null));



Mime
View raw message