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