[jboss-cvs] JBossAS SVN: r62957 - projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 10 00:16:04 EDT 2007
Author: anil.saldhana at jboss.com
Date: 2007-05-10 00:16:04 -0400 (Thu, 10 May 2007)
New Revision: 62957
Removed:
projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/DynamicLoginConfig.java
projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/DynamicLoginConfigMBean.java
projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/SunConfigParser.jj
projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/XMLLoginConfig.java
projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/XMLLoginConfigImpl.java
projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/XMLLoginConfigMBean.java
Log:
SECURITY-26: JBAS integration code moved to JBAS trunk
Deleted: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/DynamicLoginConfig.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/DynamicLoginConfig.java 2007-05-10 04:14:37 UTC (rev 62956)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/DynamicLoginConfig.java 2007-05-10 04:16:04 UTC (rev 62957)
@@ -1,279 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.net.URL;
-import java.util.Set;
-import java.util.Iterator;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.security.auth.login.AppConfigurationEntry;
-
-import org.jboss.mx.util.MBeanProxy;
-import org.jboss.security.config.ApplicationPolicy;
-import org.jboss.security.config.PolicyConfig;
-import org.jboss.system.ServiceMBeanSupport;
-import org.jboss.system.server.ServerConfigImplMBean;
-import org.jboss.deployment.DeploymentException;
-
-/** A security config mbean that loads an xml login configuration using the
- XMLLoginConfig.loadConfig(URL config) operation on start, and unloads
- the contained login module configurations on stop.
-
- <server>
- <mbean code="org.jboss.security.auth.login.DynamicLoginConfig"
- name="...">
- <attribute name="AuthConfig">login-config.xml</attribute>
- <!-- The service which supports dynamic processing of login-config.xml
- configurations.
- -->
- <depends optional-attribute-name="LoginConfigService">
- jboss.security:service=XMLLoginConfig
- </depends>
- <!-- Optionally specify the security mgr service to use when
- this service is stopped to flush the auth caches of the domains
- registered by this service.
- -->
- <depends optional-attribute-name="SecurityManagerService">
- jboss.security:service=JaasSecurityManager
- </depends>
- </mbean>
- </server>
-
- @see org.jboss.security.auth.login.XMLLoginConfig
-
- @author Scott.Stark at jboss.org
- @author Anil.Saldhana at jboss.org
- @version $Revision$
- */
-public class DynamicLoginConfig extends ServiceMBeanSupport
- implements DynamicLoginConfigMBean
-{
- /** The JAAS login config file resource to load */
- private String authConf = "login-config.xml";
- /** The name of the XMLLoginConfig to use to load the login configs */
- private ObjectName loginConfigService;
- /** The name of the SecurityMgrService to use for cache flushes */
- private ObjectName securityMgrService;
- /** The names of the login module configs loaded during start */
- private String[] configNames;
- private PolicyConfig config;
-
- public DynamicLoginConfig()
- {
- }
-
- public String getName()
- {
- return "Dynamic JAAS Login Config";
- }
-
- public PolicyConfig getPolicyConfig()
- {
- return config;
- }
- public void setPolicyConfig(PolicyConfig config)
- {
- this.config = config;
- }
-
- public ObjectName getLoginConfigService()
- {
- return loginConfigService;
- }
- /** Get the XMLLoginConfig service to use for loading. This service must
- * support a String[] loadConfig(URL) operation to load the configurations.
- *
- * @param serviceName - the XMLLoginConfig service name.
- */
- public void setLoginConfigService(ObjectName serviceName)
- {
- this.loginConfigService = serviceName;
- }
-
- public ObjectName getSecurityManagerService()
- {
- return securityMgrService;
- }
- /** Set the SecurityManagerService used to flush the registered security
- * domains. This service must support an flushAuthenticationCache(String)
- * operation to flush the case for the argument security domain. Setting
- * this triggers the flush of the authentication caches when the service
- * is stopped.
- * @param serviceName - the SecurityManagerService service name.
- */
- public void setSecurityManagerService(ObjectName serviceName)
- {
- this.securityMgrService = serviceName;
- }
-
- /** Get the resource path to the JAAS login configuration file to use.
- */
- public String getAuthConfig()
- {
- return authConf;
- }
-
- /** Set the resource path to the JAAS login configuration file to use.
- The default is "login-config.xml".
- */
- public void setAuthConfig(String authConf)
- {
- this.authConf = authConf;
- }
-
- /** Go through the registered login config names and flush the auth
- * caches if there is a registered SecurityManagerService.
- *
- * @throws Exception
- */
- public void flushAuthenticationCaches() throws Exception
- {
- if( this.securityMgrService != null && server.isRegistered(securityMgrService))
- {
- int count = configNames == null ? 0 : configNames.length;
- String[] sig = {String.class.getName()};
- for(int n = 0; n < count; n ++)
- {
- Object[] args = {configNames[n]};
- server.invoke(securityMgrService, "flushAuthenticationCache", args, sig);
- log.debug("Flushed domain: "+configNames[n]);
- }
- }
- }
-
- /** Start the service. This entails loading the AuthConf file contents
- * using the LoginConfigService.
- */
- protected void startService() throws Exception
- {
- if( config != null )
- {
- log.debug("Using embedded config");
- Set names = config.getConfigNames();
- Iterator iter = names.iterator();
- MBeanServer server = super.getServer();
- while( iter.hasNext() )
- {
- String name = (String) iter.next();
- ApplicationPolicy aPolicy = config.get(name);
- if(aPolicy == null)
- throw new IllegalStateException("Application Policy is null for "+name);
-
- AuthenticationInfo info = (AuthenticationInfo)aPolicy.getAuthenticationInfo();
- AppConfigurationEntry[] entry = info.getAppConfigurationEntry();
- // addAppConfig(String, AppConfigurationEntry[]);
- //Object[] args = {name, entry};
- //String[] sig = {String.class.getName(), entry.getClass().getName()};
- Object[] args = {name, aPolicy};
- String[] sig = {String.class.getName(), aPolicy.getClass().getName()};
- //server.invoke(loginConfigService, "addAppConfig", args, sig);
- server.invoke(loginConfigService, "addApplicationPolicy", args, sig);
- }
- configNames = new String[names.size()];
- names.toArray(configNames);
- }
- else
- {
- //JBAS-3422: Ensure that the AuthConf is neither null nor default login-config.xml
- if( authConf== null || authConf.length() == 0)
- throw new IllegalStateException("AuthConf is null. Please " +
- "configure an appropriate config resource");
-
- // Look for the authConf as resource
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- URL loginConfig = loader.getResource(authConf);
- if(loginConfig == null)
- {
- try
- {
- //JBAS-3210: Allow an absolute url
- loginConfig = new URL(authConf);
- }
- catch(Exception e)
- {
- loginConfig = null;
- }
- }
- if( loginConfig != null )
- {
- validateAuthConfigURL(loginConfig.toExternalForm());
- log.debug("Using JAAS AuthConfig: "+loginConfig.toExternalForm());
- MBeanServer server = super.getServer();
- Object[] args = {loginConfig};
- String[] sig = {URL.class.getName()};
- configNames = (String[]) server.invoke(loginConfigService,
- "loadConfig", args, sig);
- int count = configNames == null ? 0 : configNames.length;
- for(int n = 0; n < count; n ++)
- {
- log.debug("Loaded config: "+configNames[n]);
- }
- }
- else
- {
- throw new DeploymentException("Failed to find authConf as resource: "+authConf);
- }
- }
- }
-
- /** Start the service. This entails unloading the AuthConf file contents
- * using the LoginConfigService.
- */
- protected void stopService() throws Exception
- {
- MBeanServer server = super.getServer();
- flushAuthenticationCaches();
- if( configNames != null && configNames.length > 0 )
- {
- Object[] args = {configNames};
- String[] sig = {configNames.getClass().getName()};
- server.invoke(loginConfigService, "removeConfigs", args, sig);
- }
- }
-
- /**
- * Ensure that the AuthConfig resource is not defaulting to
- * the default login-config in the conf directory
- * @param url
- * @throws Exception
- */
- private void validateAuthConfigURL(String url) throws Exception
- {
- String msg = "AuthConfig is defaulting to conf/login-config.xml. " +
- "Please check your archive.";
- ServerConfigImplMBean mb = null;
- try
- {
- mb = (ServerConfigImplMBean)MBeanProxy.get(ServerConfigImplMBean.class,
- ServerConfigImplMBean.OBJECT_NAME, server);
- URL serverConfigURL = mb.getServerConfigURL();
- if(url.equalsIgnoreCase(serverConfigURL.toExternalForm() + "login-config.xml"))
- throw new IllegalStateException(msg);
- }
- finally
- {
- //Clear the proxy
- mb = null;
- }
- }
-}
Deleted: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/DynamicLoginConfigMBean.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/DynamicLoginConfigMBean.java 2007-05-10 04:14:37 UTC (rev 62956)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/DynamicLoginConfigMBean.java 2007-05-10 04:16:04 UTC (rev 62957)
@@ -1,88 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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 javax.management.ObjectName;
-
-import org.jboss.system.ServiceMBean;
-import org.jboss.security.config.PolicyConfig;
-
-/** The management interface for the DynamicLoginConfig service.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public interface DynamicLoginConfigMBean
- extends ServiceMBean
-{
- /**
- * Get the embedded PolicyConfig
- * @return the PolicyConfig if it was specified, null otherwise.
- */
- public PolicyConfig getPolicyConfig();
- /**
- * Set the embedded PolicyConfig
- * @param config - the embedded PolicyConfig object
- */
- public void setPolicyConfig(PolicyConfig config);
-
- /** Get the resource path to the JAAS login configuration file to use.
- */
- public String getAuthConfig();
- /** Set the resource path to the JAAS login configuration file to use.
- * @param authConf - the classpath resource to load.
- */
- public void setAuthConfig(String authConf);
-
- /** Get the XMLLoginConfig service to use for loading.
- * @return the XMLLoginConfig service name.
- */
- public ObjectName getLoginConfigService();
- /** Get the XMLLoginConfig service to use for loading. This service must
- * support a String[] loadConfig(URL) operation to load the configurations.
- *
- * @param serviceName - the XMLLoginConfig service name.
- */
- public void setLoginConfigService(ObjectName serviceName);
-
- /** Flush the caches of the security domains that have been registered
- * by this service.
- * @throws Exception
- */
- public void flushAuthenticationCaches() throws Exception;
-
- /** Get the SecurityManagerService used to flush the registered security
- * domains.
- * @return the SecurityManagerService service name.
- */
- public ObjectName getSecurityManagerService();
-
- /** Set the SecurityManagerService used to flush the registered security
- * domains. This service must support an flushAuthenticationCache(String)
- * operation to flush the case for the argument security domain. Setting
- * this triggers the flush of the authentication caches when the service
- * is stopped.
- * @param serviceName - the SecurityManagerService service name.
- */
- public void setSecurityManagerService(ObjectName serviceName);
-
-}
Deleted: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/SunConfigParser.jj
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/SunConfigParser.jj 2007-05-10 04:14:37 UTC (rev 62956)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/SunConfigParser.jj 2007-05-10 04:16:04 UTC (rev 62957)
@@ -1,265 +0,0 @@
-/* JBoss, the OpenSource J2EE WebOS
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-options {
- LOOKAHEAD=1;
- DEBUG_PARSER=true;
- DEBUG_LOOKAHEAD=true;
- DEBUG_TOKEN_MANAGER=false;
-}
-
-PARSER_BEGIN(SunConfigParser)
-
-package org.jboss.security.auth.login;
-
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
-
-/**
- * A JavaCC 2.1 grammar for the default JAAS configuration file provided by Sun.
- * The format of an entry is:
- Application {
- ModuleClass Flag ModuleOptions;
- ModuleClass Flag ModuleOptions;
- ModuleClass Flag ModuleOptions;
- };
-
- * @see http://www.webgain.com/products/metamata/java_doc.html
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class SunConfigParser
-{
- private XMLLoginConfigImpl loginConfig;
-
- public SunConfigParser()
- {
- // keep the parser from feaking out, init using one of
- // the JavaCC generated constructor
- this(new StringReader(""));
- }
-
- public void parse(Reader configFile, XMLLoginConfigImpl loginConfig)
- throws ParseException
- {
- parse(configFile, loginConfig, false);
- }
-
- public void parse(Reader configFile, XMLLoginConfigImpl loginConfig, boolean trace)
- throws ParseException
- {
- ReInit(configFile);
-
- // This will have no effect unless the debugging options are true
- if (trace)
- {
- this.enable_tracing();
- }
- else
- {
- this.disable_tracing();
- }
-
- this.loginConfig = loginConfig;
- this.config();
- }
-
- /**
- * Strip off the leading and trailing (quote) chars from the given string
- * and return it. Does not actually check to make sure they are '\'' chars.
- */
- private String stripQuotes(String image)
- {
- return image.substring(1, image.length() - 1);
- }
-
- public static void doParse(Reader configFile, XMLLoginConfigImpl loginConfig)
- throws ParseException
- {
- doParse(configFile, loginConfig, false);
- }
-
- public static void doParse(Reader configFile, XMLLoginConfigImpl loginConfig, boolean trace)
- throws ParseException
- {
- SunConfigParser parser = new SunConfigParser();
- parser.parse(configFile, loginConfig, trace);
- }
-}
-
-PARSER_END(SunConfigParser)
-
-/* IGNORE WHITESPACE */
-
-SKIP :
-{
- " "
- | "\r"
- | "\t"
- | "\n"
-}
-
-
-SPECIAL_TOKEN : /* COMMENTS */
-{
- <SINGLE_LINE_COMMENT: ("//"|"#") (~["\n","\r"])* ("\n"|"\r"|"\r\n")>
-| <MULTI_LINE_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/">
-}
-
-TOKEN :
-{
- < OPEN_BKT: "{" >
- | < CLOSE_BKT: "}" >
- | < SEMI_COLON: ";" >
- | < EQUALS: "=" >
-
-}
-
-/* Literals */
-
-TOKEN :
-{
- < LONG: ( ["0" - "9"] )+ >
- | < DOUBLE: <FLOAT>
- | <FLOAT> ( ["e","E"] ([ "-","+"])? <LONG> )?
- >
- | < #FLOAT: <LONG> ( "." (<LONG>)? )
- | "." <LONG>
- >
- | < STRING:
- (
- "'"
- ( (~["'","\n","\r"])
- | ("''")
- )*
- "'"
- )
- |
- (
- "\""
- ( (~["\"","\n","\r"])
- | ("\"\"")
- )*
- "\""
- ) >
-}
-
-TOKEN [IGNORE_CASE]:
-{
- <CONTROL_FLAG: "required" | "requisite" | "sufficient" | "optional">
-|
- <IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>|"-"|"_")* >
-|
- <CLASSNAME: <LETTER> (<LETTER>|<DIGIT>)* ("." <LETTER> (<LETTER>|<DIGIT>)*)* >
-|
- <#LETTER: [ "_","$", "a"-"z", "A"-"Z" ] >
-|
- <#DIGIT: ["0" - "9"] >
-|
- <ANY: (<NOTSPACE_EQUALS>)+ >
-|
- <#NOTSPACE_EQUALS: (~[" ","\t","\n","\r","=",";"]) >
-}
-
-/** Start of the grammar */
-
-void config() :
-{
-}
-{
- ( appConfig() )* <EOF>
-}
-
-void appConfig() :
-{
- Token t = null;
- String appName;
- AppConfigurationEntry entry;
- ArrayList entries = new ArrayList();
-}
-{
- t=<IDENTIFIER> { appName = t.image; } <OPEN_BKT>
- (
- entry = loginModuleConfig()
- {
- entries.add(entry);
- }
- ) +
- <CLOSE_BKT> <SEMI_COLON>
- {
- AppConfigurationEntry[] appConfig = new AppConfigurationEntry[entries.size()];
- entries.toArray(appConfig);
- loginConfig.addAppConfig(appName, appConfig);
- }
-}
-
-AppConfigurationEntry loginModuleConfig() :
-{
- Token t = null;
- String loginModuleClassName;
- HashMap options = new HashMap();
- LoginModuleControlFlag controlFlag;
- AppConfigurationEntry entry;
-}
-{
- t=<CLASSNAME> { loginModuleClassName = t.image; }
- controlFlag = controlFlag()
- ( moduleOptions(options) )*
- <SEMI_COLON>
- {
- entry = new AppConfigurationEntry(loginModuleClassName, controlFlag, options);
- return entry;
- }
-}
-
-LoginModuleControlFlag controlFlag() :
-{
- Token t;
- LoginModuleControlFlag flag = null;
-}
-{
- t=<CONTROL_FLAG>
- {
- if( LoginModuleControlFlag.REQUIRED.toString().indexOf(t.image) > 0 )
- flag = LoginModuleControlFlag.REQUIRED;
- else if( LoginModuleControlFlag.REQUISITE.toString().indexOf(t.image) > 0 )
- flag = LoginModuleControlFlag.REQUISITE;
- else if( LoginModuleControlFlag.SUFFICIENT.toString().indexOf(t.image) > 0 )
- flag = LoginModuleControlFlag.SUFFICIENT;
- else if( LoginModuleControlFlag.OPTIONAL.toString().indexOf(t.image) > 0 )
- flag = LoginModuleControlFlag.OPTIONAL;
- return flag;
- }
-}
-
-void moduleOptions(HashMap options) :
-{
- Token t;
- String name, value;
-}
-{
- ( t=<IDENTIFIER> | t=<CLASSNAME> )
- { name = t.image; }
- <EQUALS>
- (
- ( t=<IDENTIFIER> | t=<CLASSNAME> | t=<DOUBLE> | t=<LONG> | t=<ANY> )
- {
- value = t.image;
- options.put(name, value);
- }
- | t=<STRING>
- {
- value = stripQuotes(t.image);
- options.put(name, value);
- }
- )
-}
-
Deleted: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/XMLLoginConfig.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/XMLLoginConfig.java 2007-05-10 04:14:37 UTC (rev 62956)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/XMLLoginConfig.java 2007-05-10 04:16:04 UTC (rev 62957)
@@ -1,198 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.io.IOException;
-import java.net.URL;
-import javax.security.auth.login.Configuration;
-import javax.security.auth.login.AppConfigurationEntry;
-
-import org.jboss.security.config.ApplicationPolicy;
-import org.jboss.system.ServiceMBeanSupport;
-
-/** An MBean for managing a XMLLoginConfigImpl instance.
-
- @author Scott.Stark at jboss.org
- @author Anil.Saldhana at jboss.org
- @version $Revision$
- */
-public class XMLLoginConfig extends ServiceMBeanSupport
- implements XMLLoginConfigMBean
-{
- XMLLoginConfigImpl config;
-
- public XMLLoginConfig()
- {
- config = new XMLLoginConfigImpl();
- }
-
-// --- Begin XMLLoginConfigMBean interface methods
-
- /** Set the URL of the XML login configuration file that should
- be loaded by this mbean on startup.
- */
- public URL getConfigURL()
- {
- return config.getConfigURL();
- }
- /** Set the URL of the XML login configuration file that should
- be loaded by this mbean on startup.
- */
- public void setConfigURL(URL configURL)
- {
- config.setConfigURL(configURL);
- }
-
- /** Set the resource name of the XML login configuration file that should
- be loaded by this mbean on startup.
- */
- public void setConfigResource(String resourceName)
- throws IOException
- {
- config.setConfigResource(resourceName);
- }
-
- /** Get whether the login config xml document is validated againsts its DTD
- */
- public boolean getValidateDTD()
- {
- return config.getValidateDTD();
- }
- /** Set whether the login config xml document is validated againsts its DTD
- */
- public void setValidateDTD(boolean flag)
- {
- config.setValidateDTD(flag);
- }
-
- /**
- * Add an application policy given a security domain name
- */
- public void addApplicationPolicy(String appName, ApplicationPolicy aPolicy)
- {
- config.addApplicationPolicy(appName,aPolicy);
- }
-
- /** Add an application login configuration. Any existing configuration for
- the given appName will be replaced.
- @deprecated
- */
- public void addAppConfig(String appName, AppConfigurationEntry[] entries)
- {
- config.addAppConfig(appName, entries);
- }
-
- /** Remove an application login configuration.
- */
- public void removeAppConfig(String appName)
- {
- config.removeAppConfig(appName);
- }
-
- /**
- * @see XMLLoginConfigMBean#getApplicationPolicy(String)
- */
- public ApplicationPolicy getApplicationPolicy(String domainName)
- {
- return (ApplicationPolicy)config.getApplicationPolicy(domainName);
- }
-
- /** Get the XML based configuration given the Configuration it should
- delegate to when an application cannot be found.
- */
- public Configuration getConfiguration(Configuration prevConfig)
- {
- config.setParentConfig(prevConfig);
- return config;
- }
-
- /** Load the login configuration information from the given config URL.
- * @param configURL A URL to an XML or Sun login config file.
- * @throws Exception on failure to load the configuration
- */
- public String[] loadConfig(URL configURL) throws Exception
- {
- return config.loadConfig(configURL);
- }
-
- public void removeConfigs(String[] appNames)
- {
- int count = appNames == null ? 0 : appNames.length;
- for(int a = 0; a < count; a ++)
- removeAppConfig(appNames[a]);
- }
-
- /** Display the login configuration for the given application.
- */
- public String displayAppConfig(String appName)
- {
- StringBuffer buffer = new StringBuffer("<h2>"+appName+" LoginConfiguration</h2>\n");
- AppConfigurationEntry[] appEntry = config.getAppConfigurationEntry(appName);
- if( appEntry == null )
- buffer.append("No Entry\n");
- else
- {
- for(int c = 0; c < appEntry.length; c ++)
- {
- AppConfigurationEntry entry = appEntry[c];
- buffer.append("LoginModule Class: "+entry.getLoginModuleName());
- buffer.append("\n<br>ControlFlag: "+entry.getControlFlag());
- buffer.append("\n<br>Options:<ul>");
- Map options = entry.getOptions();
- Iterator iter = options.entrySet().iterator();
- while( iter.hasNext() )
- {
- Entry e = (Entry) iter.next();
- buffer.append("<li>");
- buffer.append("name="+e.getKey());
- buffer.append(", value="+e.getValue());
- buffer.append("</li>\n");
- }
- buffer.append("</ul>\n");
- }
- }
- return buffer.toString();
- }
-// --- End XMLLoginConfigMBean interface methods
-
-// --- Begin ServiceMBeanSupport overriden methods
-
- /** Load the configuration
- */
- protected void startService() throws Exception
- {
- config.loadConfig();
- }
-
- /** Clear all configuration entries
- */
- protected void destroyService()
- {
- config.clear();
- }
-
-// --- End ServiceMBeanSupport overriden methods
-
-}
Deleted: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/XMLLoginConfigImpl.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/XMLLoginConfigImpl.java 2007-05-10 04:14:37 UTC (rev 62956)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/XMLLoginConfigImpl.java 2007-05-10 04:16:04 UTC (rev 62957)
@@ -1,419 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Serializable;
-import java.net.MalformedURLException;
-import java.net.URL;
-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 the form:
-
- <policy>
- <application-policy name = "test-domain">
- <authentication>
- <login-module code = "org.jboss.security.plugins.samples.IdentityLoginModule"
- flag = "required">
- <module-option name = "principal">starksm</module-option>
- </login-module>
- </authentication>
- </application-policy>
- </policy>
-
- @see javax.security.auth.login.Configuration
-
- @author Scott.Stark at jboss.org
- @author Anil.Saldhana at jboss.org
- @version $Revision$
- */
-public class XMLLoginConfigImpl extends Configuration implements Serializable, ApplicationPolicyRegistration
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = -8965860493224188277L;
- private static final String DEFAULT_APP_CONFIG_NAME = "other";
- private static final AuthPermission REFRESH_PERM = new AuthPermission("refreshLoginConfiguration");
- private static Logger log = Logger.getLogger(XMLLoginConfigImpl.class);
- /** A mapping of application name to AppConfigurationEntry[]
- protected Map appConfigs = Collections.synchronizedMap(new HashMap());
- */
- PolicyConfig appConfigs = new PolicyConfig();
- /** The URL to the XML or Sun login configuration */
- protected URL loginConfigURL;
- /** The inherited configuration we delegate to */
- protected Configuration parentConfig;
- /** A flag indicating if XML configs should be validated */
- private boolean validateDTD = true;
-
- // --- Begin Configuration method overrrides
- public void refresh()
- {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null)
- sm.checkPermission(REFRESH_PERM);
- if (log.isTraceEnabled())
- log.trace("Begin refresh");
- appConfigs.clear();
- loadConfig();
- if (log.isTraceEnabled())
- log.trace("End refresh");
- }
-
- public AppConfigurationEntry[] getAppConfigurationEntry(String appName)
- {
- if (log.isTraceEnabled())
- log.trace("Begin getAppConfigurationEntry("+appName+"), size="+appConfigs.size());
-
- //Load the config if PolicyConfig is empty
- if(this.appConfigs.size() == 0)
- this.loadConfig();
-
- AppConfigurationEntry[] entry = null;
- ApplicationPolicy aPolicy = this.getApplicationPolicy(appName);
- AuthenticationInfo authInfo = aPolicy != null ? (AuthenticationInfo)aPolicy.getAuthenticationInfo()
- : null;
-
- if (authInfo == null)
- {
- if (log.isTraceEnabled())
- log.trace("getAppConfigurationEntry("+appName+"), no entry in appConfigs, tyring parentCont: "+parentConfig);
- if (parentConfig != null)
- entry = parentConfig.getAppConfigurationEntry(appName);
- if (entry == null)
- {
- if (log.isTraceEnabled())
- log.trace("getAppConfigurationEntry("+appName+"), no entry in parentConfig, trying: "+DEFAULT_APP_CONFIG_NAME);
- }
- ApplicationPolicy defPolicy = (ApplicationPolicy)appConfigs.get(DEFAULT_APP_CONFIG_NAME);
- authInfo = defPolicy != null ?(AuthenticationInfo) defPolicy.getAuthenticationInfo() : null;
- }
-
- if (authInfo != null)
- {
- if (log.isTraceEnabled())
- log.trace("End getAppConfigurationEntry("+appName+"), authInfo=" + authInfo);
- // Make a copy of the authInfo object
- final AuthenticationInfo theAuthInfo = authInfo;
- PrivilegedAction action = new PrivilegedAction()
- {
- public Object run()
- {
- return theAuthInfo.copyAppConfigurationEntry();
- }
- };
- entry = (AppConfigurationEntry[]) AccessController.doPrivileged(action);
- }
- else
- {
- if (log.isTraceEnabled())
- log.trace("End getAppConfigurationEntry("+appName+"), failed to find entry");
- }
-
- return entry;
- }
- // --- End Configuration method overrrides
-
- /** Set the URL of the XML login configuration file that should
- be loaded by this mbean on startup.
- */
- public URL getConfigURL()
- {
- return loginConfigURL;
- }
-
- /** Set the URL of the XML login configuration file that should
- be loaded by this mbean on startup.
- */
- public void setConfigURL(URL loginConfigURL)
- {
- this.loginConfigURL = loginConfigURL;
- }
-
- public void setConfigResource(String resourceName)
- throws IOException
- {
- ClassLoader tcl = Thread.currentThread().getContextClassLoader();
- loginConfigURL = tcl.getResource(resourceName);
- if (loginConfigURL == null)
- throw new IOException("Failed to find resource: " + resourceName);
- }
-
- public void setParentConfig(Configuration parentConfig)
- {
- this.parentConfig = parentConfig;
- }
-
- /** Get whether the login config xml document is validated againsts its DTD
- */
- public boolean getValidateDTD()
- {
- return this.validateDTD;
- }
-
- /** Set whether the login config xml document is validated againsts its DTD
- */
- public void setValidateDTD(boolean flag)
- {
- this.validateDTD = flag;
- }
-
- /**
- * @see ApplicationPolicyRegistration#addApplicationPolicy(String, ApplicationPolicy)
- */
- public void addApplicationPolicy(String appName, ApplicationPolicy aPolicy)
- {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null)
- sm.checkPermission(REFRESH_PERM);
- appConfigs.add(aPolicy);
- SecurityConfiguration.addApplicationPolicy(aPolicy.getName(), aPolicy);
- }
-
- /** Add an application configuration
- */
- public void addAppConfig(String appName, AppConfigurationEntry[] entries)
- {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null)
- sm.checkPermission(REFRESH_PERM);
- AuthenticationInfo authInfo = new AuthenticationInfo(appName);
- authInfo.setAppConfigurationEntry(entries);
- if (log.isTraceEnabled())
- log.trace("addAppConfig("+appName+"), authInfo=" + authInfo);
- ApplicationPolicy aPolicy = new ApplicationPolicy(appName, authInfo);
- appConfigs.add(aPolicy);
- SecurityConfiguration.addApplicationPolicy(aPolicy.getName(), aPolicy);
- }
-
- /**
- * @deprecated
- * @see #removeApplicationPolicy(String)
- * @param appName
- */
- public void removeAppConfig(String appName)
- {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null)
- sm.checkPermission(REFRESH_PERM);
- if (log.isTraceEnabled())
- log.trace("removeAppConfig, appName="+appName);
- appConfigs.remove(appName);
- }
-
-
- /**
- * @see ApplicationPolicyRegistration#getApplicationPolicy(String)
- */
- public ApplicationPolicy getApplicationPolicy(String domainName)
- {
- if(appConfigs == null || appConfigs.size() == 0)
- loadConfig();
- ApplicationPolicy aPolicy = (ApplicationPolicy)appConfigs.get(domainName);
- if(aPolicy != null)
- SecurityConfiguration.addApplicationPolicy(aPolicy.getName(), aPolicy);
- return aPolicy;
- }
-
-
- /**
- * @see ApplicationPolicyRegistration#removeApplicationPolicy(String)
- */
- public boolean removeApplicationPolicy(String appName)
- {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null)
- sm.checkPermission(REFRESH_PERM);
- if (log.isTraceEnabled())
- log.trace("removeAppConfig, appName="+appName);
- appConfigs.remove(appName);
- return true;
- }
-
- /**
- * Method that returns the parsed AuthenticationInfo needed by
- * the JASPI framework until a seperate Configuration mechanism
- * for JASPI is established
- *
- * @return the parsed AuthenticationInfo object
- */
- public BaseAuthenticationInfo getAuthenticationInfo(String domainName)
- {
- ApplicationPolicy aPolicy = getApplicationPolicy( domainName);
- return aPolicy != null ? aPolicy.getAuthenticationInfo() : null;
- }
-
- public void clear()
- {
-
- }
-
- /** Called to try to load the config from the java.security.auth.login.config
- * property value when there is no loginConfigURL.
- */
- public void loadConfig()
- {
- // Try to load the java.security.auth.login.config property
- String loginConfig = System.getProperty("java.security.auth.login.config");
- if (loginConfig == null)
- loginConfig = "login-config.xml";
-
- // If there is no loginConfigURL build it from the loginConfig
- if (loginConfigURL == null)
- {
- try
- {
- // Try as a URL
- loginConfigURL = new URL(loginConfig);
- }
- catch (MalformedURLException e)
- {
- // Try as a resource
- try
- {
- setConfigResource(loginConfig);
- }
- catch (IOException ignore)
- {
- // Try as a file
- File configFile = new File(loginConfig);
- try
- {
- setConfigURL(configFile.toURL());
- }
- catch (MalformedURLException ignore2)
- {
- }
- }
- }
- }
-
- if (loginConfigURL == null)
- {
- log.warn("Failed to find config: " + loginConfig);
- return;
- }
-
- if (log.isTraceEnabled())
- log.trace("Begin loadConfig, loginConfigURL="+loginConfigURL);
- // Try to load the config if found
- try
- {
- loadConfig(loginConfigURL);
- if (log.isTraceEnabled())
- log.trace("End loadConfig, loginConfigURL="+loginConfigURL);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- log.warn("End loadConfig, failed to load config: " + loginConfigURL, e);
- }
- }
-
- protected String[] loadConfig(URL config) throws Exception
- {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null)
- sm.checkPermission(REFRESH_PERM);
-
- ArrayList configNames = new ArrayList();
- log.debug("Try loading config as XML, url=" + config);
- try
- {
- loadXMLConfig(config, configNames);
- }
- catch(Throwable e)
- {
- log.debug("Failed to load config as XML", e);
- log.debug("Try loading config as Sun format, url=" + config);
- loadSunConfig(config, configNames);
- }
- String[] names = new String[configNames.size()];
- configNames.toArray(names);
- return names;
- }
-
- private void loadSunConfig(URL sunConfig, ArrayList configNames)
- throws Exception
- {
- InputStream is = sunConfig.openStream();
- if (is == null)
- throw new IOException("InputStream is null for: " + sunConfig);
-
- InputStreamReader configFile = new InputStreamReader(is);
- boolean trace = log.isTraceEnabled();
- SunConfigParser.doParse(configFile, this, trace);
- }
-
- private void loadXMLConfig(URL loginConfigURL, ArrayList configNames)
- throws IOException, JBossXBException
- {
- 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)
- {
- SecurityConfiguration.addApplicationPolicy(cname, config.get(cname));
- }
- }
-
- 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;
- }
-
-}
Deleted: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/XMLLoginConfigMBean.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/XMLLoginConfigMBean.java 2007-05-10 04:14:37 UTC (rev 62956)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/auth/login/XMLLoginConfigMBean.java 2007-05-10 04:16:04 UTC (rev 62957)
@@ -1,112 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.net.URL;
-
-import javax.management.ObjectName;
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.login.Configuration;
-
-import org.jboss.mx.util.ObjectNameFactory;
-import org.jboss.security.config.ApplicationPolicy;
-import org.jboss.system.ServiceMBean;
-
-/** The managment bean interface for the XML based JAAS login configuration
- object.
-
- at author Scott.Stark at jboss.org
- at version $Revision$
- */
-public interface XMLLoginConfigMBean extends ServiceMBean
-{
- /** Default ObjectName
- */
- public static final ObjectName OBJECT_NAME =
- ObjectNameFactory.create("jboss.security:service=XMLLoginConfig");
-
- /** Set the URL of the XML login configuration file that should
- be loaded by this mbean on startup.
- */
- public URL getConfigURL();
- /** Set the URL of the XML login configuration file that should
- be loaded by this mbean on startup.
- */
- public void setConfigURL(URL configURL);
-
- /** Set the resource name of the XML login configuration file that should
- be loaded by this mbean on startup.
- */
- public void setConfigResource(String resourceName) throws IOException;
-
- /** Get whether the login config xml document is validated againsts its DTD
- */
- public boolean getValidateDTD();
- /** Set whether the login config xml document is validated againsts its DTD
- */
- public void setValidateDTD(boolean flag);
-
- /**
- * Get the Application Policy given the domain name
- */
- public ApplicationPolicy getApplicationPolicy(String domainName);
-
- /** Get the XML based configuration given the Configuration it should
- delegate to when an application cannot be found.
- */
- public Configuration getConfiguration(Configuration prevConfig);
-
- /**
- * Add an Application Policy given a domain name to the configuration
- * @param appName
- * @param aPolicy
- */
- public void addApplicationPolicy(String appName, ApplicationPolicy aPolicy);
-
- /** Add an application login configuration. Any existing configuration for
- the given appName will be replaced.
- @deprecated
- */
- public void addAppConfig(String appName, AppConfigurationEntry[] entries);
- /** Remove an application login configuration.
- */
- public void removeAppConfig(String appName);
-
- /** Load the login configuration information from the given config URL.
- * @param configURL A URL to an XML or Sun login config file.
- * @return An array of the application config names loaded
- * @throws Exception on failure to load the configuration
- */
- public String[] loadConfig(URL configURL) throws Exception;
- /** Remove the given login configurations. This invokes removeAppConfig
- * for each element of appNames.
- *
- * @param appNames the names of the login configurations to remove.
- */
- public void removeConfigs(String[] appNames);
-
- /** Display the login configuration for the given application.
- */
- public String displayAppConfig(String appName);
-}
-
More information about the jboss-cvs-commits
mailing list