[jboss-cvs] JBossAS SVN: r74649 - in trunk/security/src: main/org/jboss/security/plugins and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jun 16 20:11:50 EDT 2008
Author: sguilhen at redhat.com
Date: 2008-06-16 20:11:50 -0400 (Mon, 16 Jun 2008)
New Revision: 74649
Modified:
trunk/security/src/etc/deploy/security-beans.xml
trunk/security/src/main/org/jboss/security/plugins/SecurityConfig.java
Log:
JBAS-5204: Changed SecurityConfig to allow for the injection of the XMLLoginConfig bean.
Modified: trunk/security/src/etc/deploy/security-beans.xml
===================================================================
--- trunk/security/src/etc/deploy/security-beans.xml 2008-06-16 22:33:15 UTC (rev 74648)
+++ trunk/security/src/etc/deploy/security-beans.xml 2008-06-17 00:11:50 UTC (rev 74649)
@@ -11,8 +11,7 @@
<bean name="SecurityConfig" class="org.jboss.security.plugins.SecurityConfig">
<property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
- <property name="loginConfig">jboss.security:service=XMLLoginConfig</property>
- <depends>jboss.security:service=XMLLoginConfig</depends>
+ <property name="defaultLoginConfig"><inject bean="XMLLoginConfig"/></property>
</bean>
<!-- JNDI Object Factory to establish SecurityDomainContext objects -->
Modified: trunk/security/src/main/org/jboss/security/plugins/SecurityConfig.java
===================================================================
--- trunk/security/src/main/org/jboss/security/plugins/SecurityConfig.java 2008-06-16 22:33:15 UTC (rev 74648)
+++ trunk/security/src/main/org/jboss/security/plugins/SecurityConfig.java 2008-06-17 00:11:50 UTC (rev 74649)
@@ -1,169 +1,221 @@
/*
-* 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.
-*/
+ * 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.plugins;
-
+
import java.util.Stack;
+
import javax.management.JMException;
+import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
-import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.security.auth.login.Configuration;
import org.jboss.aop.microcontainer.aspects.jmx.JMX;
+import org.jboss.security.auth.login.XMLLoginConfig;
import org.jboss.system.ServiceMBeanSupport;
-/** The SecurityConfigMBean implementation. This class needs the
- javax.security.auth.AuthPermission("setLoginConfiguration") to install
- the javax.security.auth.login.Configuration when running with a security
- manager.
-
- @author Scott.Stark at jboss.org
- @version $Revision: 58710 $
+/**
+ * The SecurityConfigMBean implementation. This class needs the
+ * javax.security.auth.AuthPermission("setLoginConfiguration") to install the javax.security.auth.login.Configuration
+ * when running with a security manager.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 58710 $
*/
- at JMX(name="jboss.security:service=SecurityConfig", exposedInterface=SecurityConfigMBean.class)
+ at JMX(name = "jboss.security:service=SecurityConfig", exposedInterface = SecurityConfigMBean.class)
public class SecurityConfig extends ServiceMBeanSupport implements SecurityConfigMBean
{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
/** The default Configuration mbean name */
private String loginConfigName;
+
+ /** The default configuration bean */
+ private XMLLoginConfig defaultLoginConfig;
+
/** The stack of Configuration mbeans that are active */
- private Stack loginConfigStack = new Stack();
+ private final Stack<Configuration> loginConfigStack = new Stack<Configuration>();
+
/** The MBeanServer */
private MBeanServer mbeanServer;
- static class ConfigInfo
- {
- ObjectName name;
- Configuration config;
- ConfigInfo(ObjectName name, Configuration config)
- {
- this.name = name;
- this.config = config;
- }
- }
-
- public SecurityConfig()
- {
- }
-
- public String getName()
- {
- return "SecurityIntialization";
- }
-
- /** Get the name of the mbean that provides the default JAAS login configuration
+ /**
+ * Get the name of the mbean that provides the default JAAS login configuration
*/
public String getLoginConfig()
{
return loginConfigName;
}
- /** Set the name of the mbean that provides the default JAAS login configuration
+ /**
+ * Set the name of the mbean that provides the default JAAS login configuration
*/
public void setLoginConfig(String name) throws MalformedObjectNameException
{
this.loginConfigName = name;
}
+ /**
+ * <p>
+ * Obtains a reference to the {@code MBeanServer} instance.
+ * </p>
+ *
+ * @return the {@code MBeanServer} that has been injected into this class.
+ */
public MBeanServer getMbeanServer()
{
+ if (this.mbeanServer == null)
+ return super.getServer();
return this.mbeanServer;
}
+ /**
+ * <p>
+ * Injects the {@code MBeanServer} instance that must be used by this class.
+ * </p>
+ *
+ * @param server a reference to the {@code MBeanServer} to be used.
+ */
public void setMbeanServer(MBeanServer server)
{
this.mbeanServer = server;
}
- /** Start the configuration service by pushing the mbean given by the
- LoginConfig onto the configuration stack.
+ /**
+ * <p>
+ * Obtains a reference to the default login configuration bean.
+ * </p>
+ *
+ * @return a reference to the default login configuration bean.
*/
+ public XMLLoginConfig getDefaultLoginConfig()
+ {
+ return defaultLoginConfig;
+ }
+
+ /**
+ * <p>
+ * Injects the default login configuration bean.
+ * </p>
+ *
+ * @param defaulLoginConfig a reference to the login configuration bean to be used.
+ */
+ public void setDefaultLoginConfig(XMLLoginConfig defaultLoginConfig)
+ {
+ this.defaultLoginConfig = defaultLoginConfig;
+ }
+
+ /**
+ * Start the configuration service by pushing the mbean given by the LoginConfig onto the configuration stack.
+ */
+ @Override
public void startService() throws Exception
{
- pushLoginConfig(loginConfigName);
+ if (this.defaultLoginConfig != null)
+ pushLoginConfig(this.defaultLoginConfig);
+ else
+ pushLoginConfig(this.loginConfigName);
}
- /** Start the configuration service by poping the top of the
- configuration stack.
+ /**
+ * Stop the configuration service by poping the top of the configuration stack.
*/
+ @Override
public void stopService() throws Exception
{
- if( loginConfigStack.empty() == false )
+ if (this.loginConfigStack.empty() == false)
popLoginConfig();
}
- /** Push an mbean onto the login configuration stack and install its
- Configuration as the current instance.
- @see javax.security.auth.login.Configuration
+ /**
+ * <p>
+ * Push the configuration obtained from the specified {@code XMLLoginConfig} onto the stack.
+ * </p>
+ *
+ * @param loginConfig a reference to the {@code XMLLoginConfig} instance.
*/
- public synchronized void pushLoginConfig(String objectName)
- throws JMException, MalformedObjectNameException
+ public synchronized void pushLoginConfig(XMLLoginConfig loginConfig)
{
- ObjectName name = new ObjectName(objectName);
Configuration prevConfig = null;
- if( loginConfigStack.empty() == false )
- {
- ConfigInfo prevInfo = (ConfigInfo) loginConfigStack.peek();
- prevConfig = prevInfo.config;
- }
+ if (!this.loginConfigStack.empty())
+ prevConfig = this.loginConfigStack.peek();
+ Configuration configuration = loginConfig.getConfiguration(prevConfig);
+ Configuration.setConfiguration(configuration);
+ this.loginConfigStack.push(configuration);
+ log.debug("Installed JAAS configuration: " + configuration);
+ }
- ConfigInfo info = installConfig(name, prevConfig);
- loginConfigStack.push(info);
- }
- /** Pop the current mbean from the login configuration stack and install
- the previous Configuration as the current instance.
- @see javax.security.auth.login.Configuration
+ /**
+ * Push an mbean onto the login configuration stack and install its Configuration as the current instance.
+ *
+ * @see javax.security.auth.login.Configuration
*/
- public synchronized void popLoginConfig()
- throws JMException
+ public synchronized void pushLoginConfig(String objectName) throws JMException, MalformedObjectNameException
{
- ConfigInfo info = (ConfigInfo) loginConfigStack.pop();
+ ObjectName name = new ObjectName(objectName);
Configuration prevConfig = null;
- if( loginConfigStack.empty() == false )
- {
- ConfigInfo prevInfo = (ConfigInfo) loginConfigStack.peek();
- prevConfig = prevInfo.config;
- }
+ if (!this.loginConfigStack.empty())
+ prevConfig = this.loginConfigStack.peek();
- installConfig(info.name, prevConfig);
+ this.loginConfigStack.push(installConfig(name, prevConfig));
}
- /** Obtain the Configuration from the named mbean using its getConfiguration
- operation and install it as the current Configuration.
+ /**
+ * Pop the current mbean from the login configuration stack and install the previous Configuration as the current
+ * instance.
+ *
+ * @see javax.security.auth.login.Configuration
+ */
+ public synchronized void popLoginConfig() throws JMException
+ {
+ // remove the current configuration from the stack.
+ this.loginConfigStack.pop();
+ // if there is a previous configuration, install it as the current instance.
+ if (!loginConfigStack.empty())
+ Configuration.setConfiguration(this.loginConfigStack.peek());
+ }
- @see Configuration.setConfiguration(javax.security.auth.login.Configuration)
+ /**
+ * Obtain the Configuration from the named mbean using its getConfiguration operation and install it as the current
+ * Configuration.
+ *
+ * @see Configuration.setConfiguration(javax.security.auth.login.Configuration)
*/
- private ConfigInfo installConfig(ObjectName name, Configuration prevConfig)
- throws JMException
+ private Configuration installConfig(ObjectName name, Configuration prevConfig) throws JMException
{
Object[] args = {prevConfig};
String[] signature = {"javax.security.auth.login.Configuration"};
- Configuration config = (Configuration) this.mbeanServer.invoke(name,
- "getConfiguration", args, signature);
+ Configuration config = (Configuration) this.getMbeanServer().invoke(name, "getConfiguration", args, signature);
Configuration.setConfiguration(config);
- ConfigInfo info = new ConfigInfo(name, config);
- log.debug("Installed JAAS Configuration service="+name+", config="+config);
- return info;
+ log.debug("Installed JAAS Configuration service=" + name + ", config=" + config);
+ return config;
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.system.ServiceMBeanSupport#getName()
+ */
+ @Override
+ public String getName()
+ {
+ return "SecurityIntialization";
+ }
}
More information about the jboss-cvs-commits
mailing list