blob: c250ad067e18f5e7494b6c8773a14370b418f21b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
// ========================================================================
// Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.plus.jaas.spi;
import java.sql.Connection;
import java.util.Map;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.sql.DataSource;
/**
* DataSourceLoginModule
*
* A LoginModule that uses a DataSource to retrieve user authentication
* and authorisation information.
*
* @see JDBCLoginModule
*/
public class DataSourceLoginModule extends AbstractDatabaseLoginModule
{
private String dbJNDIName;
private DataSource dataSource;
/* ------------------------------------------------ */
/** Init LoginModule.
* Called once by JAAS after new instance created.
* @param subject
* @param callbackHandler
* @param sharedState
* @param options
*/
public void initialize(Subject subject,
CallbackHandler callbackHandler,
Map<String,?> sharedState,
Map<String,?> options)
{
try
{
super.initialize(subject, callbackHandler, sharedState, options);
//get the datasource jndi name
dbJNDIName = (String)options.get("dbJNDIName");
InitialContext ic = new InitialContext();
dataSource = (DataSource)ic.lookup("java:comp/env/"+dbJNDIName);
}
catch (NamingException e)
{
throw new IllegalStateException (e.toString());
}
}
/**
* Get a connection from the DataSource
* @see AbstractDatabaseLoginModule#getConnection()
* @return the connection for the datasource
* @throws Exception
*/
public Connection getConnection ()
throws Exception
{
return dataSource.getConnection();
}
}
|