Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2015-11-24 21:58:27 -0500
committerJan Bartel2015-11-24 21:58:27 -0500
commit6e37f4886a4e04c0505d478e57122c13e6c25fd3 (patch)
tree80876efbfcc49258e61f66070e78a58a30633805 /jetty-plus
parent648ab51afa7d705554f2902aae6890a4c547bdb4 (diff)
downloadorg.eclipse.jetty.project-6e37f4886a4e04c0505d478e57122c13e6c25fd3.tar.gz
org.eclipse.jetty.project-6e37f4886a4e04c0505d478e57122c13e6c25fd3.tar.xz
org.eclipse.jetty.project-6e37f4886a4e04c0505d478e57122c13e6c25fd3.zip
Refactor jaas login sequence to only fetch role data if user is authenticated according to that module.
Diffstat (limited to 'jetty-plus')
-rw-r--r--jetty-plus/src/main/java/org/eclipse/jetty/plus/security/DataSourceLoginService.java127
1 files changed, 116 insertions, 11 deletions
diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/security/DataSourceLoginService.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/security/DataSourceLoginService.java
index 141597d4f2..aa61b57a0e 100644
--- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/security/DataSourceLoginService.java
+++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/security/DataSourceLoginService.java
@@ -73,6 +73,33 @@ public class DataSourceLoginService extends MappedLoginService
private String _userSql;
private String _roleSql;
private boolean _createTables = false;
+
+
+ /**
+ * DBUser
+ *
+ *
+ */
+ public class DBUser extends KnownUser
+ {
+ private int _key;
+
+ /**
+ * @param name
+ * @param credential
+ */
+ public DBUser(String name, Credential credential, int key)
+ {
+ super(name, credential);
+ _key = key;
+ }
+
+ public int getKey ()
+ {
+ return _key;
+ }
+
+ }
/* ------------------------------------------------------------ */
public DataSourceLoginService()
@@ -290,13 +317,13 @@ public class DataSourceLoginService extends MappedLoginService
*
* @param userName the user name
*/
- @Override
+ @Deprecated
protected UserIdentity loadUser (String userName)
{
try
{
try (Connection connection = getConnection();
- PreparedStatement statement1 = connection.prepareStatement(_userSql))
+ PreparedStatement statement1 = connection.prepareStatement(_userSql))
{
statement1.setObject(1, userName);
try (ResultSet rs1 = statement1.executeQuery())
@@ -305,19 +332,20 @@ public class DataSourceLoginService extends MappedLoginService
{
int key = rs1.getInt(_userTableKey);
String credentials = rs1.getString(_userTablePasswordField);
- List<String> roles = new ArrayList<String>();
- try (PreparedStatement statement2 = connection.prepareStatement(_roleSql))
- {
- statement2.setInt(1, key);
- try (ResultSet rs2 = statement2.executeQuery())
+
+ List<String> roles = new ArrayList<String>();
+ try (PreparedStatement statement2 = connection.prepareStatement(_roleSql))
{
- while (rs2.next())
+ statement2.setInt(1, key);
+ try (ResultSet rs2 = statement2.executeQuery())
{
- roles.add(rs2.getString(_roleTableRoleField));
+ while (rs2.next())
+ {
+ roles.add(rs2.getString(_roleTableRoleField));
+ }
}
}
- }
- return putUser(userName, Credential.getCredential(credentials), roles.toArray(new String[roles.size()]));
+ return putUser(userName, Credential.getCredential(credentials), roles.toArray(new String[roles.size()]));
}
}
}
@@ -334,6 +362,83 @@ public class DataSourceLoginService extends MappedLoginService
}
+ /**
+ * @see org.eclipse.jetty.security.MappedLoginService#loadUserInfo(java.lang.String)
+ * @Override
+ */
+ public KnownUser loadUserInfo (String username)
+ {
+ try
+ {
+ try (Connection connection = getConnection();
+ PreparedStatement statement1 = connection.prepareStatement(_userSql))
+ {
+ statement1.setObject(1, username);
+ try (ResultSet rs1 = statement1.executeQuery())
+ {
+ if (rs1.next())
+ {
+ int key = rs1.getInt(_userTableKey);
+ String credentials = rs1.getString(_userTablePasswordField);
+
+ return new DBUser(username, Credential.getCredential(credentials), key);
+ }
+ }
+ }
+ }
+ catch (NamingException e)
+ {
+ LOG.warn("No datasource for "+_jndiName, e);
+ }
+ catch (SQLException e)
+ {
+ LOG.warn("Problem loading user info for "+username, e);
+ }
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.jetty.security.MappedLoginService#loadRoleInfo(org.eclipse.jetty.security.MappedLoginService.KnownUser)
+ * @Override
+ */
+ public String[] loadRoleInfo (KnownUser user)
+ {
+ DBUser dbuser = (DBUser)user;
+
+ try
+ {
+ try (Connection connection = getConnection();
+ PreparedStatement statement2 = connection.prepareStatement(_roleSql))
+ {
+
+ List<String> roles = new ArrayList<String>();
+
+ statement2.setInt(1, dbuser.getKey());
+ try (ResultSet rs2 = statement2.executeQuery())
+ {
+ while (rs2.next())
+ {
+ roles.add(rs2.getString(_roleTableRoleField));
+ }
+
+ return roles.toArray(new String[roles.size()]);
+ }
+ }
+ }
+ catch (NamingException e)
+ {
+ LOG.warn("No datasource for "+_jndiName, e);
+ }
+ catch (SQLException e)
+ {
+ LOG.warn("Problem loading user info for "+user.getName(), e);
+ }
+ return null;
+ }
+
+
+
+
/* ------------------------------------------------------------ */
@Override

Back to the top