KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > net > server > ClientAuthenticationHandler


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package org.quickserver.net.server;
16
17 import java.io.*;
18 import org.quickserver.net.AppException;
19
20 /**
21  * This interface defines a class that can be used by
22  * QuickServer to authenticate a client when new connection is
23  * made to QuickServer.
24  *
25  * <p>
26  * Recommendations to be followed when implementing ClientAuthenticationHandler
27  * <ul>
28  * <li>Should have a default constructor.
29  * <li>Should be thread safe.
30  * <li>It should not store any data that may is associated with a particular client.
31  * <li>If any client data is need to be saved from the client session,
32  * it should be saved to a {@link ClientData} class, which can be retrieved
33  * using handler.getClientData() method.
34  * </ul>
35  * </p>
36  * <p>
37  * Ex:
38  * <code><BLOCKQUOTE><pre>
39 package echoserver;
40
41 import java.net.*;
42 import java.io.*;
43 import org.quickserver.net.server.ClientAuthenticationHandler;
44 import org.quickserver.net.server.ClientHandler;
45
46 public class EchoAuthenticationHandler
47         implements ClientAuthenticationHandler {
48
49     public AuthStatus askAuthentication(ClientHandler handler)
50         throws IOException, AppException {
51         handler.sendClientMsg("Password :");
52         return null;
53     }
54
55     public AuthStatus handleAuthentication(ClientHandler handler, String data)
56             throws IOException, AppException {
57         if(data.equals("password"))
58             return AuthStatus.SUCCESS;
59         else
60             return AuthStatus.FAILURE;
61     }
62
63     public AuthStatus handleAuthentication(ClientHandler handler, Object data)
64             throws IOException, AppException {
65         if(true) throw new IOException("Object mode not implemented!");
66     }
67
68     public AuthStatus handleAuthentication(ClientHandler handler, byte data[])
69             throws IOException {
70         if(true) throw new IOException("Byte mode not implemented!");
71     }
72 }
73 </pre></BLOCKQUOTE></code></p>
74  * @author Akshathkumar Shetty
75  * @since 1.4.6
76  */

77 public interface ClientAuthenticationHandler {
78     /**
79      * Method called first time after gotConnected() method is caled on
80      * ClientEventHandler, if Authenticator is set.
81      * Should be used to initate a authorisation process, like asking for username.
82      * @exception java.io.IOException if io error in socket
83      * @exception AppException if client socket needs to be closed.
84      * @return AuthStatus that indicates if authorisation states, if null it
85      * is treated as authentication not yet finished.
86      */

87     public AuthStatus askAuthentication(ClientHandler handler)
88             throws IOException, AppException;
89
90     /**
91      * Method called when ever a client sends character/string data
92      * before authentication.
93      * @exception java.io.IOException if io error in socket
94      * @exception AppException if client socket needs to be closed.
95      * @return AuthStatus that indicates if authorisation states, if null it
96      * is treated as authentication not yet finished.
97      */

98     public AuthStatus handleAuthentication(ClientHandler handler, String JavaDoc data)
99             throws IOException, AppException;
100
101     /**
102      * Method called when ever a client sends Object data
103      * before authentication.
104      * @exception java.io.IOException if io error in socket
105      * @exception AppException if client socket needs to be closed.
106      * @return AuthStatus that indicates if authorisation states, if null it
107      * is treated as authentication not yet finished.
108      */

109     public AuthStatus handleAuthentication(ClientHandler handler, Object JavaDoc data)
110             throws IOException, AppException;
111
112     /**
113      * Method called when ever a client sends binary data
114      * before authentication.
115      * @exception java.io.IOException if io error in socket
116      * @exception AppException if client socket needs to be closed.
117      * @return AuthStatus that indicates if authorisation states, if null it
118      * is treated as authentication not yet finished.
119      */

120     public AuthStatus handleAuthentication(ClientHandler handler, byte data[])
121             throws IOException, AppException;
122 }
123
Popular Tags