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
19 package org.itracker.services.authentication;
20
21 import org.itracker.services.ConfigurationService;
22 import org.itracker.services.UserService;
23 import org.itracker.services.exceptions.AuthenticatorException;
24 import org.itracker.core.AuthenticationConstants;
25
26 import java.util.Map;
27
28 // TODO: Rewrite Javadocs here: we don't have session beans or EJBs anymore
29
30 /**
31 * This class provides a skeleton implementation of the PluggableAuthenticator interface.
32 * It can be extended to provide a new authentication module for ITracker reducing the amount
33 * of effort to implement the PluggableAuthenticator interface.
34 */
35 public abstract class AbstractPluggableAuthenticator
36 implements PluggableAuthenticator, AuthenticationConstants {
37
38 // private final Logger logger;
39 private UserService userService = null;
40 private ConfigurationService configurationService = null;
41
42
43 /**
44 * This method is called after creating a new instance of the Authenticator. It supplies
45 * some default EJB objects that the authenticator can use.
46 */
47 public void initialize(Map<?, ?> values) {
48 if (values != null) {
49 Object userService = values.get("userService");
50 Object configurationService = values.get("configurationService");
51
52 if (userService instanceof UserService) {
53 this.userService = (UserService) userService;
54 }
55 if (configurationService instanceof ConfigurationService) {
56 this.configurationService = (ConfigurationService) configurationService;
57 }
58 }
59 }
60
61 /**
62 * Returns a UserService session bean that can be used to call needed methods such
63 * as retrieving a user.
64 *
65 * @return userService
66 * @throws AuthenticatorException an exception if an error occur
67 */
68 public UserService getUserService() throws AuthenticatorException {
69 if (userService == null || !(userService instanceof UserService)) {
70 throw new AuthenticatorException(AuthenticatorException.SYSTEM_ERROR);
71 }
72
73 return userService;
74 }
75
76 /**
77 * Returns an ConfigurationService session bean that can be used to retreive properties
78 * that have been set in the system. These properties can be used to provide any
79 * needed configuration for the authenticator.
80 *
81 * @return configurationService
82 * @throws AuthenticatorException an exception if an error occur
83 */
84 public ConfigurationService getConfigurationService() throws AuthenticatorException {
85 if (configurationService == null || !(configurationService instanceof ConfigurationService)) {
86 throw new AuthenticatorException(AuthenticatorException.SYSTEM_ERROR);
87 }
88
89 return configurationService;
90 }
91
92 }