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