Home > Articles > Security > General Security and Privacy

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Overriding the init()

The final addition to this extension class is to build the init() method. As its name suggests, this method is called once during the initialization of the login module. In this method I retrieve the queries that will be used in all the private methods that I have defined so far. I will also retrieve the maximum failed login count. By storing these as variables in the login-config.xml file, it makes the module flexible in case the underlying database tables change. The code for the init() method is as follows:

 public void initialize(Subject subject, CallbackHandler callbackHandler,
             Map sharedState, Map options) {
  super.initialize(subject, callbackHandler, sharedState, options);
  _log.debug("Initializing LoginModule");
  try {
   flag = (String) options.get("maxRetries");
   maxRetries = Integer.valueOf(flag).intValue();

   resetCounterQuery = (String)options.get("resetCounterQuery");
   incrementCounterQuery = (String)options.get("incrementCounterQuery");
   getCounterQuery = (String)options.get("getCounterQuery");
   isLoggedInQuery = (String)options.get("isLoggedInQuery");
   getLoggedInQuery = (String)options.get("getLoggedInQuery");
  } catch (Throwable e) {
   _log.error("Error initializing", e);
  _log.debug("LoginModule initialized");

The init() method is responsible for loading all the parameters defined in the login-config.xml file. Because each of the parent classes of this module also have variables to initialize, I first call the super init method and then retrieve my parameters from the passed in java.util.Map.

  • + Share This
  • 🔖 Save To Your Account