Added the ability for the ATS to re-configure itself at given intervals.

This commit is contained in:
Juan Carlos Luciani 2006-06-01 22:43:28 +00:00
parent af93081d2e
commit 24a8d44e2c
3 changed files with 159 additions and 37 deletions

View File

@ -67,6 +67,7 @@ Thhe following is an example svc.settings file:
<SessionTokenLifetime>43200</SessionTokenLifetime> <SessionTokenLifetime>43200</SessionTokenLifetime>
<LifetimeShorter>10</LifetimeShorter> <LifetimeShorter>10</LifetimeShorter>
<IAConfigFile>/home/jluciani/jakarta-tomcat-5.0.28/webapps/CasaAuthTokenSvc/WEB-INF/conf/iaRealms.xml</IAConfigFile> <IAConfigFile>/home/jluciani/jakarta-tomcat-5.0.28/webapps/CasaAuthTokenSvc/WEB-INF/conf/iaRealms.xml</IAConfigFile>
<ReconfigureInterval>60</ReconfigureInterval>
<startSearchContext>o=novell</startSearchContext> <startSearchContext>o=novell</startSearchContext>
</settings> </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 the different realms (contexts) that the ATS can utilize to authenticate
entities and resolve identities. In the future the configuration of this entities and resolve identities. In the future the configuration of this
settng will be optional. 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 - The startSearchContext setting specifies the begin location for initiating
context searches. The absence of this setting will result in searches ocurring context searches. The absence of this setting will result in searches ocurring

View File

@ -46,21 +46,133 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
{ {
private static final long serialVersionUID = -8264027868130334613L; private static final long serialVersionUID = -8264027868130334613L;
private EnabledSvcsConfig m_enabledSvcsConfig; private String m_appFolderPath = null;
private Map m_methodsMap; 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. * Constructor.
*/ */
public Rpc() public Rpc ()
{ {
super(); 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. * init() implementation.
*/ */
public void init(ServletConfig config) throws ServletException public void init (ServletConfig config) throws ServletException
{ {
super.init(config); 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 // Get the path to our configuration folder
// //
// First check if it has been specified via a system property // First check if it has been specified via a system property
String configFolder;
ServletContext context = config.getServletContext(); ServletContext context = config.getServletContext();
configFolder = System.getProperty("com.novell.casa.authtoksvc.config"); m_appFolderPath = context.getRealPath(File.separator);
if (configFolder == null) 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 // 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 // property, assume that it's location is off the WEB-INF folder for
// our web application. // our web application.
configFolder = context.getRealPath(File.separator) + "WEB-INF/conf"; m_configFolderPath = m_appFolderPath + "WEB-INF/conf";
} }
// Read service configuration // Configure ourselves
SvcConfig svcConfig = new SvcConfig(context.getRealPath(File.separator), configFolder); configureServlet();
// Read enabled services configuration // Check if we must start a thread to periodically reconfigure ourselves
EnabledSvcsConfig enabledSvcsConfig = new EnabledSvcsConfig(configFolder); if (m_reconfigureInterval != 0)
{
// Create a map to keep track of the Rpc methods m_reconfigureThread = new ReconfigureThread(this);
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);
} }
catch (Exception e) catch (Exception e)
{ {
@ -114,17 +213,23 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
/* /*
* destroy() implementation. * destroy() implementation.
*/ */
public void destroy() public void destroy ()
{ {
super.destroy(); super.destroy();
System.err.println("Rpc.destroy()"); System.err.println("Rpc.destroy()");
// Stop our re-configure thread
if (m_reconfigureThread != null)
{
m_reconfigureThread.stop();
}
} }
/* /*
* doGet() implementation. * 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); doPost(request, response);
} }
@ -132,7 +237,7 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
/* /*
* doPost() implementation. * 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 // Get ready to send back a reply
response.setContentType("text/html"); response.setContentType("text/html");

View File

@ -52,10 +52,12 @@ public class SvcConfig
public final static String StartSearchContext = "startSearchContext"; public final static String StartSearchContext = "startSearchContext";
public final static String ConfigFolderPath = "ConfigFolderPath"; public final static String ConfigFolderPath = "ConfigFolderPath";
public final static String AppRootPath = "AppRootPath"; public final static String AppRootPath = "AppRootPath";
public final static String ReconfigureInterval = "ReconfigureInterval";
// Default configuration values // Default configuration values
private String m_defaultSessionTokenLifetimeValue = "43200"; // Seconds public final static String DefaultSessionTokenLifetimeValue = "43200"; // Seconds
private String m_defaultLifetimeShorterValue = "5"; // Seconds public final static String DefaultLifetimeShorterValue = "5"; // Seconds
public final static String DefaultReconfigureIntervalValue = "60"; // Seconds
private static final String m_svcSettingsFileName = "svc.settings"; private static final String m_svcSettingsFileName = "svc.settings";
private Map m_svcSettingsMap; private Map m_svcSettingsMap;
@ -255,19 +257,27 @@ public class SvcConfig
// which we have defaults. // which we have defaults.
if (settingName.equals(SessionTokenLifetime) == true) if (settingName.equals(SessionTokenLifetime) == true)
{ {
value = m_defaultSessionTokenLifetimeValue; value = DefaultSessionTokenLifetimeValue;
System.err.println("SvcConfig.getSetting()- Assigning default value " + value); System.err.println("SvcConfig.getSetting()- Assigning default value " + value);
// Add the key to the map so that it can be found quicker next time // 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) else if (settingName.equals(LifetimeShorter) == true)
{ {
value = m_defaultLifetimeShorterValue; value = DefaultLifetimeShorterValue;
System.err.println("SvcConfig.getSetting()- Assigning default value " + value); System.err.println("SvcConfig.getSetting()- Assigning default value " + value);
// Add the key to the map so that it can be found quicker next time // 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) else if (settingName.equals(IdentityAbstractionConfigFile) == true)
{ {