Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Mazursky2013-08-27 23:58:56 -0400
committerGerrit Code Review @ Eclipse.org2013-09-09 00:24:31 -0400
commit767faece5c4692748d1ac8e130b2e4c5faa1ff20 (patch)
tree787e93c5bf452b69d28d737a04d57cddae0b7ede /jetty-security/src
parentcdd95bb5515f35af090bcbcf6f9af03d5c6762c9 (diff)
downloadorg.eclipse.jetty.project-767faece5c4692748d1ac8e130b2e4c5faa1ff20.tar.gz
org.eclipse.jetty.project-767faece5c4692748d1ac8e130b2e4c5faa1ff20.tar.xz
org.eclipse.jetty.project-767faece5c4692748d1ac8e130b2e4c5faa1ff20.zip
[Bug 415999] Fix some of FindBugs warnings
Mostly not closed streams/DB resources are fixed. But also less important things. Signed-off-by: Mikhail Mazursky <mikhail.mazursky@gmail.com>
Diffstat (limited to 'jetty-security/src')
-rw-r--r--jetty-security/src/main/java/org/eclipse/jetty/security/JDBCLoginService.java45
-rw-r--r--jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java4
-rw-r--r--jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java19
3 files changed, 39 insertions, 29 deletions
diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/JDBCLoginService.java b/jetty-security/src/main/java/org/eclipse/jetty/security/JDBCLoginService.java
index 58db6e4727..5373161801 100644
--- a/jetty-security/src/main/java/org/eclipse/jetty/security/JDBCLoginService.java
+++ b/jetty-security/src/main/java/org/eclipse/jetty/security/JDBCLoginService.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.security;
import java.io.IOException;
+import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
@@ -116,8 +117,10 @@ public class JDBCLoginService extends MappedLoginService
{
Properties properties = new Properties();
Resource resource = Resource.newResource(_config);
- properties.load(resource.getInputStream());
-
+ try (InputStream in = resource.getInputStream())
+ {
+ properties.load(in);
+ }
_jdbcDriver = properties.getProperty("jdbcdriver");
_url = properties.getProperty("url");
_userName = properties.getProperty("username");
@@ -238,25 +241,29 @@ public class JDBCLoginService extends MappedLoginService
if (null == _con)
throw new SQLException("Can't connect to database");
- PreparedStatement stat = _con.prepareStatement(_userSql);
- stat.setObject(1, username);
- ResultSet rs = stat.executeQuery();
-
- if (rs.next())
+ try (PreparedStatement stat1 = _con.prepareStatement(_userSql))
{
- int key = rs.getInt(_userTableKey);
- String credentials = rs.getString(_userTablePasswordField);
- stat.close();
-
- stat = _con.prepareStatement(_roleSql);
- stat.setInt(1, key);
- rs = stat.executeQuery();
- List<String> roles = new ArrayList<String>();
- while (rs.next())
- roles.add(rs.getString(_roleTableRoleField));
+ stat1.setObject(1, username);
+ try (ResultSet rs1 = stat1.executeQuery())
+ {
+ if (rs1.next())
+ {
+ int key = rs1.getInt(_userTableKey);
+ String credentials = rs1.getString(_userTablePasswordField);
+ List<String> roles = new ArrayList<String>();
- stat.close();
- return putUser(username, Credential.getCredential(credentials),roles.toArray(new String[roles.size()]));
+ try (PreparedStatement stat2 = _con.prepareStatement(_roleSql))
+ {
+ stat2.setInt(1, key);
+ try (ResultSet rs2 = stat2.executeQuery())
+ {
+ while (rs2.next())
+ roles.add(rs2.getString(_roleTableRoleField));
+ }
+ }
+ return putUser(username, Credential.getCredential(credentials),roles.toArray(new String[roles.size()]));
+ }
+ }
}
}
catch (SQLException e)
diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java b/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java
index edb5f9156d..df8a4eb12c 100644
--- a/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java
+++ b/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java
@@ -650,7 +650,7 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
- public static Principal __NO_USER = new Principal()
+ public static final Principal __NO_USER = new Principal()
{
public String getName()
{
@@ -674,7 +674,7 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti
* FormAuthenticator to allow access to logon and error pages within an
* authenticated URI tree.
*/
- public static Principal __NOBODY = new Principal()
+ public static final Principal __NOBODY = new Principal()
{
public String getName()
{
diff --git a/jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java b/jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java
index a25ee6384e..6b68b9b36b 100644
--- a/jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java
+++ b/jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.security;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
+import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@@ -55,19 +56,21 @@ public class PropertyUserStoreTest
private void writeInitialUsers(String testFile) throws Exception
{
- BufferedWriter writer = new BufferedWriter(new FileWriter(testFile));
- writer.append("tom: tom, roleA\n");
- writer.append("dick: dick, roleB\n");
- writer.append("harry: harry, roleA, roleB\n");
- writer.close();
+ try (Writer writer = new BufferedWriter(new FileWriter(testFile)))
+ {
+ writer.append("tom: tom, roleA\n");
+ writer.append("dick: dick, roleB\n");
+ writer.append("harry: harry, roleA, roleB\n");
+ }
}
private void writeAdditionalUser(String testFile) throws Exception
{
Thread.sleep(1001);
- BufferedWriter writer = new BufferedWriter(new FileWriter(testFile,true));
- writer.append("skip: skip, roleA\n");
- writer.close();
+ try (Writer writer = new BufferedWriter(new FileWriter(testFile,true)))
+ {
+ writer.append("skip: skip, roleA\n");
+ }
}
@Test

Back to the top