1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.plus.jaas.spi;
15
16 import java.sql.Connection;
17 import java.sql.DriverManager;
18 import java.util.Map;
19
20 import javax.security.auth.Subject;
21 import javax.security.auth.callback.CallbackHandler;
22
23 import org.eclipse.jetty.util.Loader;
24 import org.eclipse.jetty.util.log.Log;
25 import org.eclipse.jetty.util.log.Logger;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public class JDBCLoginModule extends AbstractDatabaseLoginModule
45 {
46 private static final Logger LOG = Log.getLogger(JDBCLoginModule.class);
47
48 private String dbDriver;
49 private String dbUrl;
50 private String dbUserName;
51 private String dbPassword;
52
53
54
55
56
57
58
59
60 public Connection getConnection ()
61 throws Exception
62 {
63 if (!((dbDriver != null)
64 &&
65 (dbUrl != null)))
66 throw new IllegalStateException ("Database connection information not configured");
67
68 if(LOG.isDebugEnabled())LOG.debug("Connecting using dbDriver="+dbDriver+"+ dbUserName="+dbUserName+", dbPassword="+dbUrl);
69
70 return DriverManager.getConnection (dbUrl,
71 dbUserName,
72 dbPassword);
73 }
74
75
76
77
78
79
80
81
82
83
84
85 public void initialize(Subject subject,
86 CallbackHandler callbackHandler,
87 Map<String,?> sharedState,
88 Map<String,?> options)
89 {
90 try
91 {
92 super.initialize(subject, callbackHandler, sharedState, options);
93
94
95 dbDriver = (String)options.get("dbDriver");
96 dbUrl = (String)options.get("dbUrl");
97 dbUserName = (String)options.get("dbUserName");
98 dbPassword = (String)options.get("dbPassword");
99
100 if (dbUserName == null)
101 dbUserName = "";
102
103 if (dbPassword == null)
104 dbPassword = "";
105
106 if (dbDriver != null)
107 Loader.loadClass(this.getClass(), dbDriver).newInstance();
108 }
109 catch (ClassNotFoundException e)
110 {
111 throw new IllegalStateException (e.toString());
112 }
113 catch (InstantiationException e)
114 {
115 throw new IllegalStateException (e.toString());
116 }
117 catch (IllegalAccessException e)
118 {
119 throw new IllegalStateException (e.toString());
120 }
121 }
122 }