1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.jaas.spi;
20
21 import java.sql.Connection;
22 import java.sql.DriverManager;
23 import java.util.Map;
24
25 import javax.security.auth.Subject;
26 import javax.security.auth.callback.CallbackHandler;
27
28 import org.eclipse.jetty.util.Loader;
29 import org.eclipse.jetty.util.log.Log;
30 import org.eclipse.jetty.util.log.Logger;
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 static final Logger LOG = Log.getLogger(JDBCLoginModule.class);
52
53 private String dbDriver;
54 private String dbUrl;
55 private String dbUserName;
56 private String dbPassword;
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<String,?> sharedState,
93 Map<String,?> 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 }