[jboss-cvs] JBossAS SVN: r73917 - projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/login.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jun 2 09:25:30 EDT 2008


Author: anil.saldhana at jboss.com
Date: 2008-06-02 09:25:30 -0400 (Mon, 02 Jun 2008)
New Revision: 73917

Added:
   projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/login/JBossXBParsingUtil.java
Modified:
   projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/login/XMLLoginConfigImpl.java
Log:
SECURITY-229: extract xb processing out

Added: projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/login/JBossXBParsingUtil.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/login/JBossXBParsingUtil.java	                        (rev 0)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/login/JBossXBParsingUtil.java	2008-06-02 13:25:30 UTC (rev 73917)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.security.auth.login;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Set;
+
+import org.jboss.security.auth.spi.UsersObjectModelFactory;
+import org.jboss.security.authorization.config.SecurityConfigObjectModelFactory;
+import org.jboss.security.config.ApplicationPolicy;
+import org.jboss.security.config.PolicyConfig;
+import org.jboss.security.config.SecurityConfiguration;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+
+/**
+ * Parsing utility using JBossXB
+ * @author Anil.Saldhana at redhat.com
+ * @since May 30, 2008
+ */
+public class JBossXBParsingUtil
+{
+   private XMLLoginConfigImpl xmlConfig = XMLLoginConfigImpl.getInstance();
+   
+   public void parse(URL loginConfigURL, ArrayList<String> configNames) throws Exception
+   {
+      LoginConfigObjectModelFactory lcomf = new SecurityConfigObjectModelFactory();
+      UsersObjectModelFactory uomf = new UsersObjectModelFactory();
+
+      InputStreamReader xmlReader = loadURL(loginConfigURL);
+      Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+      unmarshaller.mapFactoryToNamespace(uomf, "http://www.jboss.org/j2ee/schemas/XMLLoginModule");
+      Object root = null;
+      PolicyConfig config = (PolicyConfig) unmarshaller.unmarshal(xmlReader, lcomf, root);
+      Set<String> cnames = config.getConfigNames();
+      configNames.addAll(cnames);
+      xmlConfig.copy(config); 
+      
+      // Add the config to SecurityConfiguration
+      for (String cname : cnames)
+      {
+         ApplicationPolicy ap = config.get(cname);
+         SecurityConfiguration.addApplicationPolicy(ap);
+         handleJASPIDelegation(ap);
+      }
+
+   }
+   
+   private void handleJASPIDelegation(ApplicationPolicy aPolicy)
+   {
+      BaseAuthenticationInfo bai = aPolicy.getAuthenticationInfo();
+      if (bai instanceof JASPIAuthenticationInfo)
+      {
+         JASPIAuthenticationInfo jai = (JASPIAuthenticationInfo) bai;
+         LoginModuleStackHolder[] lmsharr = jai.getLoginModuleStackHolder();
+         for (LoginModuleStackHolder lmsh : lmsharr)
+         {
+            xmlConfig.addAppConfig(lmsh.getName(), lmsh.getAppConfigurationEntry());
+         }
+      }
+   }
+   
+   private InputStreamReader loadURL(URL configURL) throws IOException
+   {
+      InputStream is = configURL.openStream();
+      if (is == null)
+         throw new IOException("Failed to obtain InputStream from url: " + configURL);
+      InputStreamReader xmlReader = new InputStreamReader(is);
+      return xmlReader;
+   }
+}
\ No newline at end of file

Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/login/XMLLoginConfigImpl.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/login/XMLLoginConfigImpl.java	2008-06-02 13:23:58 UTC (rev 73916)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/login/XMLLoginConfigImpl.java	2008-06-02 13:25:30 UTC (rev 73917)
@@ -31,22 +31,16 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
-import java.util.Set;
 
 import javax.security.auth.AuthPermission;
 import javax.security.auth.login.AppConfigurationEntry;
 import javax.security.auth.login.Configuration;
 
 import org.jboss.logging.Logger;
-import org.jboss.security.auth.spi.UsersObjectModelFactory;
-import org.jboss.security.authorization.config.SecurityConfigObjectModelFactory;
 import org.jboss.security.config.ApplicationPolicy;
 import org.jboss.security.config.ApplicationPolicyRegistration;
 import org.jboss.security.config.PolicyConfig;
 import org.jboss.security.config.SecurityConfiguration;
-import org.jboss.xb.binding.JBossXBException;
-import org.jboss.xb.binding.Unmarshaller;
-import org.jboss.xb.binding.UnmarshallerFactory;
 
 /**
  * An concrete implementation of the javax.security.auth.login.Configuration class that parses an xml configuration of
@@ -259,6 +253,11 @@
       appConfigs.add(aPolicy);
       SecurityConfiguration.addApplicationPolicy(aPolicy);
    }
+   
+   public void copy(PolicyConfig policyConfig)
+   {
+      this.appConfigs.copy(policyConfig);
+   }
 
    /**
     * @deprecated
@@ -440,35 +439,9 @@
    }
 
    @SuppressWarnings("unchecked")
-   private void loadXMLConfig(URL loginConfigURL, ArrayList configNames) throws IOException, JBossXBException
+   private void loadXMLConfig(URL loginConfigURL, ArrayList configNames) throws Exception
    {
-      LoginConfigObjectModelFactory lcomf = new SecurityConfigObjectModelFactory();
-      UsersObjectModelFactory uomf = new UsersObjectModelFactory();
-
-      InputStreamReader xmlReader = loadURL(loginConfigURL);
-      Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
-      unmarshaller.mapFactoryToNamespace(uomf, "http://www.jboss.org/j2ee/schemas/XMLLoginModule");
-      Object root = null;
-      PolicyConfig config = (PolicyConfig) unmarshaller.unmarshal(xmlReader, lcomf, root);
-      Set<String> cnames = config.getConfigNames();
-      configNames.addAll(cnames);
-      appConfigs.copy(config);
-      // Add the config to SecurityConfiguration
-      for (String cname : cnames)
-      {
-         ApplicationPolicy ap = config.get(cname);
-         SecurityConfiguration.addApplicationPolicy(ap);
-         handleJASPIDelegation(ap);
-      }
-   }
-
-   private InputStreamReader loadURL(URL configURL) throws IOException
-   {
-      InputStream is = configURL.openStream();
-      if (is == null)
-         throw new IOException("Failed to obtain InputStream from url: " + configURL);
-      InputStreamReader xmlReader = new InputStreamReader(is);
-      return xmlReader;
-   }
-
+      JBossXBParsingUtil xbUtil = new JBossXBParsingUtil();
+      xbUtil.parse(loginConfigURL, configNames); 
+   }  
 }




More information about the jboss-cvs-commits mailing list