Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/AbstractDatabaseLoginModule.java')
-rw-r--r--jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/AbstractDatabaseLoginModule.java49
1 files changed, 40 insertions, 9 deletions
diff --git a/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/AbstractDatabaseLoginModule.java b/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/AbstractDatabaseLoginModule.java
index 4e8c60f95a..6c009afab5 100644
--- a/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/AbstractDatabaseLoginModule.java
+++ b/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/AbstractDatabaseLoginModule.java
@@ -21,7 +21,6 @@ package org.eclipse.jetty.jaas.spi;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -54,21 +53,36 @@ public abstract class AbstractDatabaseLoginModule extends AbstractLoginModule
private String dbUserRoleTableUserField;
private String dbUserRoleTableRoleField;
-
-
-
/**
* @return a java.sql.Connection from the database
- * @throws Exception
+ * @throws Exception if unable to get the connection
*/
public abstract Connection getConnection () throws Exception;
+
+
+ public class JDBCUserInfo extends UserInfo
+ {
+ public JDBCUserInfo (String userName, Credential credential)
+ {
+ super(userName, credential);
+ }
+
+
+
+ @Override
+ public List<String> doFetchRoles ()
+ throws Exception
+ {
+ return getRoles(getUserName());
+ }
+ }
/* ------------------------------------------------ */
/** Load info from database
* @param userName user info to load
- * @exception SQLException
+ * @exception Exception if unable to get the user info
*/
public UserInfo getUserInfo (String userName)
throws Exception
@@ -95,8 +109,22 @@ public abstract class AbstractDatabaseLoginModule extends AbstractLoginModule
return null;
}
+
+
+ return new JDBCUserInfo (userName, Credential.getCredential(dbCredential));
+ }
+ }
+
+
+ public List<String> getRoles (String userName)
+ throws Exception
+ {
+ List<String> roles = new ArrayList<String>();
+
+ try (Connection connection = getConnection())
+ {
//query for role names
- List<String> roles = new ArrayList<String>();
+
try (PreparedStatement statement = connection.prepareStatement (rolesQuery))
{
statement.setString (1, userName);
@@ -109,10 +137,13 @@ public abstract class AbstractDatabaseLoginModule extends AbstractLoginModule
}
}
}
-
- return new UserInfo (userName, Credential.getCredential(dbCredential), roles);
+
}
+
+ return roles;
}
+
+
public void initialize(Subject subject,

Back to the top