Cleanup exception handling
[remote/remote-ws.git] / src / authentication / AbstractAuthenticator.java
blob105068030f8cf2980d9acac69a04a61079025a90
1 package authentication;
3 import util.SQLHelper;
5 /** This is an abstract class with the generic code for the session
6 * authentication web service. To integrate authentication for a user
7 * account system, this class should be inherited. The abstract methods
8 * should be implemented with the business logic applicable to the user
9 * account system.
11 * @author Esben Zeuthen
13 public abstract class AbstractAuthenticator {
15 /** This function should be implemented to return an array of
16 * empty credential fields applicable for the user account
17 * system used.
19 * @return Array of credential objects defining the credentials
20 * needed for authentication.
22 abstract public Credential[] getEmptyCredentials() throws Exception;
24 public boolean authenticate(String session_id, Credential[] credentials) throws Exception
26 if (!checkCredentials(session_id, credentials))
27 return false;
29 SQLHelper sql = null;
31 try {
32 String auth = "update session set auth=1 where id=" + session_id;
34 sql = new SQLHelper();
35 sql.openDB();
36 return sql.update(auth) == 1;
38 } finally {
39 sql.closeDB();
43 /** This method should be implemented to check the credentials
44 * used for client authentication.
46 * This is the integration point for custom user account
47 * systems. It is also one of the places to perform integration
48 * between the user account system and the mote reservation
49 * system.
51 * @param session_id ID of the session object; for use with
52 * custom session attributes
53 * @param credentials The credentials supplied by the client
55 * @return authentication success or failure.
57 abstract protected boolean checkCredentials(String session_id, Credential[] credentials) throws Exception;