Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jetty-jaas')
-rw-r--r--jetty-jaas/src/main/java/org/eclipse/jetty/jaas/JAASLoginService.java4
-rw-r--r--jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/AbstractDatabaseLoginModule.java53
2 files changed, 28 insertions, 29 deletions
diff --git a/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/JAASLoginService.java b/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/JAASLoginService.java
index d50c3859aa..412ee5ec1a 100644
--- a/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/JAASLoginService.java
+++ b/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/JAASLoginService.java
@@ -57,8 +57,8 @@ public class JAASLoginService extends AbstractLifeCycle implements LoginService
{
private static final Logger LOG = Log.getLogger(JAASLoginService.class);
- public static String DEFAULT_ROLE_CLASS_NAME = "org.eclipse.jetty.jaas.JAASRole";
- public static String[] DEFAULT_ROLE_CLASS_NAMES = {DEFAULT_ROLE_CLASS_NAME};
+ public static final String DEFAULT_ROLE_CLASS_NAME = "org.eclipse.jetty.jaas.JAASRole";
+ public static final String[] DEFAULT_ROLE_CLASS_NAMES = {DEFAULT_ROLE_CLASS_NAME};
protected String[] _roleClassNames = DEFAULT_ROLE_CLASS_NAMES;
protected String _callbackHandlerClass;
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 fc2726ff89..55c60aff08 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
@@ -73,45 +73,44 @@ public abstract class AbstractDatabaseLoginModule extends AbstractLoginModule
public UserInfo getUserInfo (String userName)
throws Exception
{
- Connection connection = null;
-
- try
+ try (Connection connection = getConnection())
{
- connection = getConnection();
//query for credential
- PreparedStatement statement = connection.prepareStatement (userQuery);
- statement.setString (1, userName);
- ResultSet results = statement.executeQuery();
String dbCredential = null;
- if (results.next())
+ try (PreparedStatement statement = connection.prepareStatement (userQuery))
+ {
+ statement.setString (1, userName);
+ try (ResultSet results = statement.executeQuery())
+ {
+ if (results.next())
+ {
+ dbCredential = results.getString(1);
+ }
+ }
+ }
+
+ if (dbCredential==null)
{
- dbCredential = results.getString(1);
+ return null;
}
- results.close();
- statement.close();
//query for role names
- statement = connection.prepareStatement (rolesQuery);
- statement.setString (1, userName);
- results = statement.executeQuery();
List<String> roles = new ArrayList<String>();
-
- while (results.next())
+ try (PreparedStatement statement = connection.prepareStatement (rolesQuery))
{
- String roleName = results.getString (1);
- roles.add (roleName);
+ statement.setString (1, userName);
+ try (ResultSet results = statement.executeQuery())
+ {
+ while (results.next())
+ {
+ String roleName = results.getString (1);
+ roles.add (roleName);
+ }
+ }
}
- results.close();
- statement.close();
-
- return dbCredential==null ? null : new UserInfo (userName,
- Credential.getCredential(dbCredential), roles);
- }
- finally
- {
- if (connection != null) connection.close();
+ return new UserInfo (userName, Credential.getCredential(dbCredential), roles);
}
}

Back to the top