KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > auth > OnlineUserFactory


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/auth/OnlineUserFactory.java,v 1.11 2006/04/14 17:05:26 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.11 $
5  * $Date: 2006/04/14 17:05:26 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Minh Nguyen
39  * @author: Mai Nguyen
40  */

41 package com.mvnforum.auth;
42
43 import javax.servlet.http.HttpServletRequest JavaDoc;
44 import javax.servlet.http.HttpServletResponse JavaDoc;
45
46 import net.myvietnam.mvncore.exception.AssertionException;
47 import net.myvietnam.mvncore.exception.DatabaseException;
48 import net.myvietnam.mvncore.web.GenericRequest;
49 import net.myvietnam.mvncore.web.GenericResponse;
50
51 public interface OnlineUserFactory {
52
53     /**
54      * Authenticate the user given its login and password (maybe in
55      * encrypted form) and returns some basic information about it.
56      * Optionally, some information can be stored in the request or
57      * session to track that the user has been logged.
58      *
59      * @param request useful to retrieve additional information to
60      * authenticate the user.
61      * @param response a <code>HttpServletResponse</code> value
62      * @param loginName a <code>String</code> value
63      * @param password a <code>String</code> value
64      * @param isEncodedPassword indicate if the password to validate is
65      * already encoded. Note that some backends may not support to
66      * validate against an encrypted password.
67      * @return an <code>OnlineUser</code> value
68      * @exception AuthenticationException if the pair login, password
69      * is not valid. Note that this method will call the
70      * {@link #validatePassword(String, String, boolean)}
71      * @exception DatabaseException if an error occurs
72      * @exception AssertionException if an error occurs
73      * @see #validatePassword(String, String, boolean)
74      */

75     public OnlineUser getAuthenticatedUser(HttpServletRequest JavaDoc request,
76                                            HttpServletResponse JavaDoc response,
77                                            String JavaDoc loginName, String JavaDoc password,
78                                            boolean isEncodedPassword)
79         throws AuthenticationException, DatabaseException, AssertionException;
80
81     public OnlineUser getAuthenticatedUser(GenericRequest request,
82                                            GenericResponse response,
83                                            String JavaDoc loginName, String JavaDoc password,
84                                            boolean isEncodedPassword)
85         throws AuthenticationException, DatabaseException, AssertionException;
86     /**
87      * This method is called after user have logined successfully.
88      * This method could be used to implement functions prepared for that user.
89      *
90      * @param request a <code>HttpServletRequest</code> value
91      * @param response a <code>HttpServletResponse</code> value
92      * @param onlineUser a <code>OnlineUser</code> that have justed been authenticated
93      */

94     public void postLogin(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, OnlineUser onlineUser)
95         throws DatabaseException;
96
97     /**
98      * <code>Logout</code> the user from the system.
99      *
100      * @param request a <code>HttpServletRequest</code> value
101      * @param response a <code>HttpServletResponse</code> value
102      */

103     public void logout(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response);
104
105     /**
106      * <code>Logout</code> the user from the system.
107      *
108      * @param request a <code>GenericRequest</code> value
109      * @param response a <code>GenericResponse</code> value
110      */

111     public void logout(GenericRequest request, GenericResponse response);
112
113     /**
114      * Validate if the given login password pair is valid, in that
115      * case <code>true</code> will be returned. If the password is not
116      * correct, <code>false</code> will be returned. If the user does
117      * not exist or in case of any error, an exception will be thrown.
118      *
119      * @param loginName a <code>String</code> value
120      * @param password a <code>String</code> value
121      * @param isEncodedPassword indicate if the password to validate is
122      * already encoded. Note that some backends may not support to
123      * validate against an encrypted password.
124      * @return a <code>boolean</code> value
125      * @exception AuthenticationException if an error occurs
126      */

127     public boolean validatePassword(String JavaDoc loginName, String JavaDoc password, boolean isEncodedPassword)
128         throws AuthenticationException;
129
130     /**
131      * Ensure the login/password pair is correct.
132      * If password is correct, nothing happen. However, if the
133      * password is not correct, an AuthenticationException will be thrown
134      *
135      * @param loginName a <code>String</code> value
136      * @param password a <code>String</code> value
137      * @param isEncodedPassword indicate if the password to validate is
138      * already encoded. Note that some backends may not support to
139      * validate against an encrypted password.
140      * @exception AuthenticationException if an error occurs
141      */

142     public void ensureCorrectPassword(String JavaDoc loginName, String JavaDoc password, boolean isEncodedPassword)
143         throws AuthenticationException;
144
145     /**
146      * Get an encoded version of the user password. This can be
147      * useful to store that password in a cookie, for example. Note
148      * that not all backends will return encrypted passwords as this
149      * can be considered an insecure practice.
150      *
151      * @param loginName a <code>String</code> value
152      * @param password a <code>String</code> value
153      * @return the encoded password of the user or <code>null</code>
154      * if the backend does not support returning stored passwords.
155      */

156     public String JavaDoc getEncodedPassword(String JavaDoc loginName, String JavaDoc password);
157
158     /**
159      * Get the anonymous user of the system. The request is used to
160      * check some parameters about the user, as its language.
161      *
162      * @param request a <code>HttpServletRequest</code> value
163      * @return an <code>OnlineUser</code> value
164      * @exception DatabaseException if an error occurs
165      * @exception AssertionException if an error occurs
166      */

167     public OnlineUser getAnonymousUser(HttpServletRequest JavaDoc request)
168         throws DatabaseException, AssertionException;
169
170     public OnlineUser getAnonymousUser(GenericRequest request)
171         throws DatabaseException, AssertionException;
172 }
173
Popular Tags