/*
* 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.message.config;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.message.AuthException;
import javax.security.auth.message.AuthParam;
import javax.security.auth.message.config.ServerAuthConfig;
import javax.security.auth.message.config.ServerAuthContext;
import org.jboss.mx.util.MBeanServerLocator;
import org.jboss.security.SecurityConstants;
//$Id: JBossServerAuthConfig.java 45183 2006-05-23 20:23:05Z asaldhana $
/**
* Provides configuration for the server side
* @author <a href="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
* @since May 15, 2006
* @version $Revision: 45183 $
*/
public class JBossServerAuthConfig implements ServerAuthConfig
{
private String layer;
private String contextId;
private CallbackHandler callbackHandler;
private List modules = new ArrayList();
private Map contextProperties;
/**
* Create a new JBossServerAuthConfig.
*
* @param layer Message Layer
* @param appContext Application Context
* @param handler Callback Handler that will be passed to the modules
* @param properties Context Properties
*/
public JBossServerAuthConfig(String layer, String appContext,
CallbackHandler handler, Map properties)
{
this.layer = layer;
this.contextId = appContext;
this.callbackHandler = handler;
this.contextProperties = properties;
}
/**
* @see ServerAuthConfig#getAuthContext(String, Map)
*/
public ServerAuthContext getAuthContext(String operation, Map properties)
throws AuthException
{
MBeanServer server = MBeanServerLocator.locateJBoss();
ServerAuthContext sc = null;
if(layer.equals(SecurityConstants.SERVLET_LAYER))
{
try
{
ObjectName oname = new ObjectName("jboss.security:service=JASPISecurityManager");
String securityDomain = (String)server.invoke(oname,"getSecurityDomain",
new Object[] {contextId}, new String[]{"java.lang.String"});
sc = (ServerAuthContext)server.invoke(oname,
"getSecurityManager",
new Object[] {securityDomain}, new String[]{"java.lang.String"});
}
catch(JMException jme)
{
throw new AuthException(jme.toString());
}
}
return sc;
}
/**
* @see AuthConfig#getContextID()
*/
public String getContextID()
{
return this.contextId;
}
/**
* @see AuthConfig#getMessageLayer()
*/
public String getMessageLayer()
{
return this.layer;
}
/**
* @see AuthConfig#getOperation(AuthParam)
*/
public String getOperation(AuthParam authParam)
{
return null;
}
/**
* @see AuthConfig#refresh()
*/
public void refresh() throws AuthException, SecurityException
{
}
//Custom Methods
public List getServerAuthModules()
{
return this.modules ;
}
}