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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class JDBCLoginModule extends AbstractDatabaseLoginModule
48 {
49 private String dbDriver;
50 private String dbUrl;
51 private String dbUserName;
52 private String dbPassword;
53
54
55
56
57
58
59
60
61
62
63
64
65 public Connection getConnection ()
66 throws Exception
67 {
68 if (!((dbDriver != null)
69 &&
70 (dbUrl != null)))
71 throw new IllegalStateException ("Database connection information not configured");
72
73 if(Log.isDebugEnabled())Log.debug("Connecting using dbDriver="+dbDriver+"+ dbUserName="+dbUserName+", dbPassword="+dbUrl);
74
75 return DriverManager.getConnection (dbUrl,
76 dbUserName,
77 dbPassword);
78 }
79
80
81
82
83
84
85
86
87
88
89
90 public void initialize(Subject subject,
91 CallbackHandler callbackHandler,
92 Map sharedState,
93 Map options)
94 {
95 try
96 {
97 super.initialize(subject, callbackHandler, sharedState, options);
98
99
100 dbDriver = (String)options.get("dbDriver");
101 dbUrl = (String)options.get("dbUrl");
102 dbUserName = (String)options.get("dbUserName");
103 dbPassword = (String)options.get("dbPassword");
104
105 if (dbUserName == null)
106 dbUserName = "";
107
108 if (dbPassword == null)
109 dbPassword = "";
110
111 if (dbDriver != null)
112 Loader.loadClass(this.getClass(), dbDriver).newInstance();
113 }
114 catch (ClassNotFoundException e)
115 {
116 throw new IllegalStateException (e.toString());
117 }
118 catch (InstantiationException e)
119 {
120 throw new IllegalStateException (e.toString());
121 }
122 catch (IllegalAccessException e)
123 {
124 throw new IllegalStateException (e.toString());
125 }
126 }
127 }