AbstractPluggableAuthenticator.java

  1. /*
  2.  * This software was designed and created by Jason Carroll.
  3.  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
  4.  * The author can be reached at jcarroll@cowsultants.com
  5.  * ITracker website: http://www.cowsultants.com
  6.  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it only under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  */

  18. package org.itracker.services.authentication;

  19. import org.itracker.services.ConfigurationService;
  20. import org.itracker.services.UserService;
  21. import org.itracker.services.exceptions.AuthenticatorException;
  22. import org.itracker.core.AuthenticationConstants;

  23. import java.util.Map;

  24. // TODO: Rewrite Javadocs here: we don't have session beans or EJBs anymore

  25. /**
  26.  * This class provides a skeleton implementation of the PluggableAuthenticator interface.
  27.  * It can be extended to provide a new authentication module for ITracker reducing the amount
  28.  * of effort to implement the PluggableAuthenticator interface.
  29.  */
  30. public abstract class AbstractPluggableAuthenticator
  31.         implements PluggableAuthenticator, AuthenticationConstants {

  32.     //    private final Logger logger;
  33.     private UserService userService = null;
  34.     private ConfigurationService configurationService = null;


  35.     /**
  36.      * This method is called after creating a new instance of the Authenticator.  It supplies
  37.      * some default EJB objects that the authenticator can use.
  38.      */
  39.     public void initialize(Map<?, ?> values) {
  40.         if (values != null) {
  41.             Object userService = values.get("userService");
  42.             Object configurationService = values.get("configurationService");

  43.             if (userService instanceof UserService) {
  44.                 this.userService = (UserService) userService;
  45.             }
  46.             if (configurationService instanceof ConfigurationService) {
  47.                 this.configurationService = (ConfigurationService) configurationService;
  48.             }
  49.         }
  50.     }

  51.     /**
  52.      * Returns a UserService session bean that can be used to call needed methods such
  53.      * as retrieving a user.
  54.      *
  55.      * @return userService
  56.      * @throws AuthenticatorException an exception if an error occur
  57.      */
  58.     public UserService getUserService() throws AuthenticatorException {
  59.         if (userService == null || !(userService instanceof UserService)) {
  60.             throw new AuthenticatorException(AuthenticatorException.SYSTEM_ERROR);
  61.         }

  62.         return userService;
  63.     }

  64.     /**
  65.      * Returns an ConfigurationService session bean that can be used to retreive properties
  66.      * that have been set in the system.  These properties can be used to provide any
  67.      * needed configuration for the authenticator.
  68.      *
  69.      * @return configurationService
  70.      * @throws AuthenticatorException an exception if an error occur
  71.      */
  72.     public ConfigurationService getConfigurationService() throws AuthenticatorException {
  73.         if (configurationService == null || !(configurationService instanceof ConfigurationService)) {
  74.             throw new AuthenticatorException(AuthenticatorException.SYSTEM_ERROR);
  75.         }

  76.         return configurationService;
  77.     }

  78. }