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