View Javadoc

1   /* (c) Copyright 2003 Caleigo AB, All rights reserved. 
2    * 
3    * This library is free software; you can redistribute it and/or
4    * modify it under the terms of the GNU Lesser General Public
5    * License as published by the Free Software Foundation; either
6    * version 2.1 of the License, or (at your option) any later version.
7    * 
8    * This library is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   * Lesser General Public License for more details.
12   * 
13   * You should have received a copy of the GNU Lesser General Public
14   * License along with this library; if not, write to the Free Software
15   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16   *  
17   */
18  
19  package org.caleigo.security;
20  
21  /*** Service that is used to handle the verification of users. There are three
22   * login methods which can be used. 
23   *
24   * @author  Mattias Hagstrand
25   * @version 1.00
26   *
27   *//*
28    *
29    * WHEN        WHO               WHY & WHAT
30    * -----------------------------------------------------------------------------
31    * 2002-10-18  Mattias Hagstrand    Creation
32    */
33  public interface ILoginService extends org.caleigo.service.IService
34  {    
35      /*** Registers an <I>ILoginInfoProvider</I> to use to provide login
36       * information to the login() method.
37       */
38      public void setLoginInfoProvider(ILoginInfoProvider provider);
39      
40      /*** Add a login handler to the loginInfo class. This handler will then
41       * be used to authenticate a user when the login(loginInfo) method is
42       * called with a parameter of the specific class.
43       */
44      public void addLoginHandler(Class loginInfoClass, ILoginHandler loginHandler);
45  
46      /*** Removes a login handler
47       */
48      public void removeLoginHandler(Class loginInfoClass);
49      
50      /*** Tries to log in a user without supplying any login information. This
51       * method preferably uses descendants of <I>ILoginInfoProvider</I> to
52       * figure out the login information for the user. Returns <code>null</code>
53       * if the login was canceled.
54       */
55      public UserInfo login();
56      /*** This method takes login information supplied in the <I>loginInfo</I> 
57       * object. There should be a corresponding <I>ILoginHandler</I> that 
58       * is registered to handle the specific <I>loginInfo</I> class. Returns <code>null</code>
59       * if the login was canceled.
60       */
61      public UserInfo login(Object loginInfo);
62      /*** This is a helper method that logs in a user based on the supplied 
63       * username-password pair. Returns <code>null</code>
64       * if the login was canceled.
65       */
66      public UserInfo login(String username, String password);
67      
68      public boolean logout(UserInfo userInfo);
69      
70      /*** Updates an UserInfo object that represents an allready logged in user with
71       * relevante user information.
72       */
73      public void updateUserInfo(UserInfo userInfo);
74      
75      public void handleError(String message);
76      
77      /*** Returns the maximum number of times a user is allowed to try to login
78       * before the application exits.
79       */
80      public int getMaximumNumberOfLoginTries();
81  
82      // Nested classes ----------------------------------------------------------
83      public static class UserLoginInfo
84      {
85          // Data members --------------------------------------------------------
86          private String username;
87          private String password;
88          
89          public UserLoginInfo(String username, String password)
90          {
91              this.username = username;
92              this.password = password;
93          }
94          
95          public String getUsername()
96          {
97              return username;
98          }
99          
100         public String getPassword()
101         {
102             return password;
103         }
104     }
105     
106     public static class LoginMessage implements java.io.Serializable
107     {
108         // Data members --------------------------------------------------------
109         protected String mUserID;
110         protected String mPassword;
111         
112         // Constructors --------------------------------------------------------
113         public LoginMessage(String userID, String password)
114         {
115             mUserID = userID;
116             mPassword = password;
117         }
118         
119         // Access methods ------------------------------------------------------
120         public String getUserID()
121         {
122             return mUserID;
123         }
124         
125         public String getPassword()
126         {
127             return mPassword;
128         }
129     }
130     
131     public static class LogoutMessage implements java.io.Serializable
132     {
133         // Data members --------------------------------------------------------
134         protected UserInfo mUserInfo;
135         protected int mSessionID;
136         
137         // Constructors --------------------------------------------------------
138         public LogoutMessage(UserInfo userInfo, int sessionID)
139         {
140             mUserInfo = userInfo;
141             mSessionID = sessionID;
142         }
143         
144         // Access methods ------------------------------------------------------
145         public UserInfo getUserInfo()
146         {
147             return mUserInfo;
148         }
149         
150         public int getSessionID()
151         {
152             return mSessionID;
153         }
154     }
155     
156     public static class LoginServiceReturnMessage implements java.io.Serializable
157     {
158         // Data members --------------------------------------------------------
159         protected UserInfo mUserInfo;
160         protected boolean mResult;
161         protected Throwable mException;
162         
163         // Constructors --------------------------------------------------------
164         public LoginServiceReturnMessage(UserInfo userInfo, boolean result, Throwable exception)
165         {
166             mUserInfo = userInfo;
167             mResult = result;
168             mException = exception;
169         }
170         
171         // Access methods ------------------------------------------------------
172         public UserInfo getUserInfo()
173         {
174             return mUserInfo;
175         }
176         
177         public boolean getResult()
178         {
179             return mResult;
180         }
181         
182         public Throwable getException()
183         {
184             return mException;
185         }
186     }
187 }