1 package edu.internet2.middleware.shibboleth.hs
5 import javax.servlet.http.*;
7 public class ClubShibSQLHandleRepository extends HandleRepositoryFactory{
9 private Connection con;
15 final static String db = "HandleService";
17 public ClubShibSQLHandleRepository(HttpServlet HS)
18 throws HandleException
20 DBdriver = HS.getInitParameter("DBdriver");
21 DBuser = HS.getInitParameter("DBuser");
22 DBpass = HS.getInitParameter("DBpass");
23 DBdomain = HS.getInitParameter("DBdomain");
24 DBurl = "jdbc:mysql://"+DBdomain+"/shib"+
25 "?user="+DBuser+"&password="+DBpass+"&autoReconnect=true";
28 Class.forName(DBdriver);
30 catch (Exception ex) {
31 throw new HandleException(HandleException.SQL, ex.getMessage());
34 con = DriverManager.getConnection(DBurl);
36 catch (Exception ex) {
37 throw new HandleException(HandleException.SQL, ex.getMessage());
42 public HandleEntry getHandleEntry( String handle )
43 throws HandleException
45 HandleEntry he = null;
48 throw new HandleException(HandleException.ERR, "ClubShibSQLHandleRepository() requires handle");
52 Statement st = con.createStatement();
53 String query = "SELECT * FROM "+db+" WHERE handle=\""+handle+"\"";
54 ResultSet rs = st.executeQuery(query);
57 throw new HandleException(HandleException.ERR, "null result set for handle: "+handle);
60 he = new HandleEntry( rs.getString("handle"),
61 rs.getString("username"),
62 rs.getString("authType"),
63 rs.getLong("authInstant"),
64 rs.getLong("expInstant"));
68 catch (SQLException e) {
69 throw new HandleException(HandleException.SQL, e.getMessage());
72 throw new HandleException(HandleException.ERR, "getHandleEntry() cannot find matching record for handle: "+handle);
78 public void insertHandleEntry( HandleEntry he )
79 throws HandleException
82 throw new HandleException(HandleException.ERR, "InsertHandle() requires HandleEntry arg");
85 String handle = he.getHandle();
86 String username = he.getUsername();
87 String authType = he.getAuthType();
88 long authInstant = he.getAuthInstant();
89 long expInstant = he.getExpInstant();
92 Statement st = con.createStatement();
93 String update = "INSERT INTO " +db+
94 " VALUES ( \"" + handle +"\", \""+username+"\", \""+
95 authType+"\", \""+ authInstant +"\", \""+
97 st.executeUpdate(update);
100 catch (SQLException e) {
101 throw new HandleException(HandleException.SQL, e.getMessage());
105 public String toHTMLString()
106 throws HandleException
108 String HTMLString = new String();
111 Statement st = con.createStatement();
112 String query = "SELECT * FROM "+db;
113 ResultSet rs = st.executeQuery(query);
114 HTMLString = "Server = "+DBdomain+"<br>"+
115 "<table><tr><td><b>handle</b></td>"+
116 "<td><b>username</b></td>"+
117 "<td><b>authType</b></td>"+
118 "<td><b>authInstant</b></td>"+
119 "<td><b>expInstant</b></td></tr>";
121 String han = rs.getString(1);
122 String uid = rs.getString(2);
123 String authtype = rs.getString(3);
124 String date_in = rs.getString(4);
125 String date_exp = rs.getString(5);
127 HTMLString += "<tr><td>"+han+"</td><td>"+uid+"</td>" +
128 "<td>"+authtype+"</td>"+
129 "<td>"+date_in+"</td>"+
130 "<td>"+date_exp+"</td></tr>";
134 HTMLString += "</table>";
136 catch (SQLException e) {
137 throw new HandleException(HandleException.SQL, e.getMessage());
142 public void destroy()
143 throws HandleException
148 catch (SQLException e) {
149 throw new HandleException(HandleException.SQL, e.getMessage());