Added the ability for the ATS to re-configure itself at given intervals.
This commit is contained in:
parent
af93081d2e
commit
24a8d44e2c
@ -67,6 +67,7 @@ Thhe following is an example svc.settings file:
|
||||
<SessionTokenLifetime>43200</SessionTokenLifetime>
|
||||
<LifetimeShorter>10</LifetimeShorter>
|
||||
<IAConfigFile>/home/jluciani/jakarta-tomcat-5.0.28/webapps/CasaAuthTokenSvc/WEB-INF/conf/iaRealms.xml</IAConfigFile>
|
||||
<ReconfigureInterval>60</ReconfigureInterval>
|
||||
<startSearchContext>o=novell</startSearchContext>
|
||||
</settings>
|
||||
|
||||
@ -89,6 +90,12 @@ Note the following about the sample svc.settings file:
|
||||
the different realms (contexts) that the ATS can utilize to authenticate
|
||||
entities and resolve identities. In the future the configuration of this
|
||||
settng will be optional.
|
||||
|
||||
- The ReconfigureInterval setting specifies how often the ATS should refresh its
|
||||
configuration. The default value for this setting is 60 seconds. A ReconfigureInterval
|
||||
value of 0 means that the ATS will not refresh its configuration once it has been
|
||||
initialized, thus requiring that the servlet be re-initialized to make configuration
|
||||
changes take effect.
|
||||
|
||||
- The startSearchContext setting specifies the begin location for initiating
|
||||
context searches. The absence of this setting will result in searches ocurring
|
||||
|
@ -46,21 +46,133 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
{
|
||||
private static final long serialVersionUID = -8264027868130334613L;
|
||||
|
||||
private EnabledSvcsConfig m_enabledSvcsConfig;
|
||||
private Map m_methodsMap;
|
||||
private String m_appFolderPath = null;
|
||||
private String m_configFolderPath = null;
|
||||
|
||||
protected ReconfigureThread m_reconfigureThread = null;
|
||||
protected int m_reconfigureInterval; // seconds
|
||||
|
||||
private Map m_methodsMap;
|
||||
|
||||
/*
|
||||
* Reconfigure Thread Class.
|
||||
*
|
||||
* This class implements a runnable thread that reconfigures an Rpc Servlet instance.
|
||||
*
|
||||
*/
|
||||
private class ReconfigureThread implements Runnable
|
||||
{
|
||||
private Rpc m_rpc;
|
||||
private Thread m_thread;
|
||||
|
||||
/*
|
||||
* Constructor.
|
||||
*/
|
||||
public ReconfigureThread (Rpc rpc)
|
||||
{
|
||||
m_rpc = rpc;
|
||||
m_thread = new Thread(this);
|
||||
m_thread.start();
|
||||
}
|
||||
|
||||
/*
|
||||
* run() implementation.
|
||||
*/
|
||||
public void run ()
|
||||
{
|
||||
System.err.println("ReconfigureThread.run()- Running");
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Sleep an ammount equal the reconfigure interval for the Rpc
|
||||
try
|
||||
{
|
||||
m_thread.sleep(m_rpc.m_reconfigureInterval * 1000);
|
||||
}
|
||||
catch (InterruptedException e) { /* nothing to do */ }
|
||||
|
||||
// Re-configure the Rpc servlet.
|
||||
try
|
||||
{
|
||||
m_rpc.configureServlet();
|
||||
|
||||
// Check if it is no longer necessary to re-configure the servlet
|
||||
if (m_rpc.m_reconfigureInterval == 0)
|
||||
{
|
||||
System.err.println("ReconfigureTask.run()- Configuration changed to no longer perform timed re-configuration");
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("ReconfigureTask.run()- Exception caught during re-configure process, " + e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* stop() implementation.
|
||||
*/
|
||||
public void stop ()
|
||||
{
|
||||
m_thread.stop();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor.
|
||||
*/
|
||||
public Rpc()
|
||||
public Rpc ()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/*
|
||||
* configureServlet() implementation.
|
||||
*/
|
||||
protected void configureServlet () throws Exception
|
||||
{
|
||||
// Read service configuration
|
||||
SvcConfig svcConfig = new SvcConfig(m_appFolderPath, m_configFolderPath);
|
||||
|
||||
// Get the reconfigure interval
|
||||
try
|
||||
{
|
||||
m_reconfigureInterval = Integer.parseInt(svcConfig.getSetting(SvcConfig.ReconfigureInterval));
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
System.err.println("Rpc.configureServlet()- Invalid reconfigure interval value format");
|
||||
m_reconfigureInterval = Integer.parseInt(SvcConfig.DefaultReconfigureIntervalValue);
|
||||
}
|
||||
|
||||
// Read enabled services configuration
|
||||
EnabledSvcsConfig enabledSvcsConfig = new EnabledSvcsConfig(m_configFolderPath);
|
||||
|
||||
// Create a map to keep track of the Rpc methods
|
||||
Map methodsMap = new HashMap();
|
||||
|
||||
// Instantiate the Rpc Methods
|
||||
RpcMethod getAuthPolicy = new GetAuthPolicy();
|
||||
getAuthPolicy.init(svcConfig, enabledSvcsConfig);
|
||||
methodsMap.put(getAuthPolicy.getId(), getAuthPolicy);
|
||||
|
||||
RpcMethod authenticate = new Authenticate();
|
||||
authenticate.init(svcConfig, enabledSvcsConfig);
|
||||
methodsMap.put(authenticate.getId(), authenticate);
|
||||
|
||||
RpcMethod getAuthToken = new GetAuthToken();
|
||||
getAuthToken.init(svcConfig, enabledSvcsConfig);
|
||||
methodsMap.put(getAuthToken.getId(), getAuthToken);
|
||||
|
||||
// Set the map as the methods map used by the servlet
|
||||
m_methodsMap = methodsMap;
|
||||
}
|
||||
|
||||
/*
|
||||
* init() implementation.
|
||||
*/
|
||||
public void init(ServletConfig config) throws ServletException
|
||||
public void init (ServletConfig config) throws ServletException
|
||||
{
|
||||
super.init(config);
|
||||
|
||||
@ -71,38 +183,25 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
// Get the path to our configuration folder
|
||||
//
|
||||
// First check if it has been specified via a system property
|
||||
String configFolder;
|
||||
ServletContext context = config.getServletContext();
|
||||
configFolder = System.getProperty("com.novell.casa.authtoksvc.config");
|
||||
if (configFolder == null)
|
||||
m_appFolderPath = context.getRealPath(File.separator);
|
||||
m_configFolderPath = System.getProperty("com.novell.casa.authtoksvc.config");
|
||||
if (m_configFolderPath == null)
|
||||
{
|
||||
// The path to the svc config folder was not specified via a system
|
||||
// property, assume that it's location is off the WEB-INF folder for
|
||||
// our web application.
|
||||
configFolder = context.getRealPath(File.separator) + "WEB-INF/conf";
|
||||
m_configFolderPath = m_appFolderPath + "WEB-INF/conf";
|
||||
}
|
||||
|
||||
// Read service configuration
|
||||
SvcConfig svcConfig = new SvcConfig(context.getRealPath(File.separator), configFolder);
|
||||
// Configure ourselves
|
||||
configureServlet();
|
||||
|
||||
// Read enabled services configuration
|
||||
EnabledSvcsConfig enabledSvcsConfig = new EnabledSvcsConfig(configFolder);
|
||||
|
||||
// Create a map to keep track of the Rpc methods
|
||||
m_methodsMap = new HashMap();
|
||||
|
||||
// Instantiate the Rpc Methods
|
||||
RpcMethod getAuthPolicy = new GetAuthPolicy();
|
||||
getAuthPolicy.init(svcConfig, enabledSvcsConfig);
|
||||
m_methodsMap.put(getAuthPolicy.getId(), getAuthPolicy);
|
||||
|
||||
RpcMethod authenticate = new Authenticate();
|
||||
authenticate.init(svcConfig, enabledSvcsConfig);
|
||||
m_methodsMap.put(authenticate.getId(), authenticate);
|
||||
|
||||
RpcMethod getAuthToken = new GetAuthToken();
|
||||
getAuthToken.init(svcConfig, enabledSvcsConfig);
|
||||
m_methodsMap.put(getAuthToken.getId(), getAuthToken);
|
||||
// Check if we must start a thread to periodically reconfigure ourselves
|
||||
if (m_reconfigureInterval != 0)
|
||||
{
|
||||
m_reconfigureThread = new ReconfigureThread(this);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -114,17 +213,23 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
/*
|
||||
* destroy() implementation.
|
||||
*/
|
||||
public void destroy()
|
||||
public void destroy ()
|
||||
{
|
||||
super.destroy();
|
||||
|
||||
System.err.println("Rpc.destroy()");
|
||||
|
||||
// Stop our re-configure thread
|
||||
if (m_reconfigureThread != null)
|
||||
{
|
||||
m_reconfigureThread.stop();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* doGet() implementation.
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
doPost(request, response);
|
||||
}
|
||||
@ -132,7 +237,7 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
/*
|
||||
* doPost() implementation.
|
||||
*/
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
// Get ready to send back a reply
|
||||
response.setContentType("text/html");
|
||||
|
@ -52,10 +52,12 @@ public class SvcConfig
|
||||
public final static String StartSearchContext = "startSearchContext";
|
||||
public final static String ConfigFolderPath = "ConfigFolderPath";
|
||||
public final static String AppRootPath = "AppRootPath";
|
||||
public final static String ReconfigureInterval = "ReconfigureInterval";
|
||||
|
||||
// Default configuration values
|
||||
private String m_defaultSessionTokenLifetimeValue = "43200"; // Seconds
|
||||
private String m_defaultLifetimeShorterValue = "5"; // Seconds
|
||||
public final static String DefaultSessionTokenLifetimeValue = "43200"; // Seconds
|
||||
public final static String DefaultLifetimeShorterValue = "5"; // Seconds
|
||||
public final static String DefaultReconfigureIntervalValue = "60"; // Seconds
|
||||
|
||||
private static final String m_svcSettingsFileName = "svc.settings";
|
||||
private Map m_svcSettingsMap;
|
||||
@ -255,19 +257,27 @@ public class SvcConfig
|
||||
// which we have defaults.
|
||||
if (settingName.equals(SessionTokenLifetime) == true)
|
||||
{
|
||||
value = m_defaultSessionTokenLifetimeValue;
|
||||
value = DefaultSessionTokenLifetimeValue;
|
||||
System.err.println("SvcConfig.getSetting()- Assigning default value " + value);
|
||||
|
||||
// Add the key to the map so that it can be found quicker next time
|
||||
m_svcSettingsMap.put(SessionTokenLifetime, m_defaultSessionTokenLifetimeValue);
|
||||
m_svcSettingsMap.put(SessionTokenLifetime, DefaultSessionTokenLifetimeValue);
|
||||
}
|
||||
else if (settingName.equals(LifetimeShorter) == true)
|
||||
{
|
||||
value = m_defaultLifetimeShorterValue;
|
||||
value = DefaultLifetimeShorterValue;
|
||||
System.err.println("SvcConfig.getSetting()- Assigning default value " + value);
|
||||
|
||||
// Add the key to the map so that it can be found quicker next time
|
||||
m_svcSettingsMap.put(LifetimeShorter, m_defaultLifetimeShorterValue);
|
||||
m_svcSettingsMap.put(LifetimeShorter, DefaultLifetimeShorterValue);
|
||||
}
|
||||
else if (settingName.equals(ReconfigureInterval) == true)
|
||||
{
|
||||
value = DefaultReconfigureIntervalValue;
|
||||
System.err.println("SvcConfig.getSetting()- Assigning default value " + value);
|
||||
|
||||
// Add the key to the map so that it can be found quicker next time
|
||||
m_svcSettingsMap.put(ReconfigureInterval, DefaultReconfigureIntervalValue);
|
||||
}
|
||||
else if (settingName.equals(IdentityAbstractionConfigFile) == true)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user