User: starksm
Date: 01/05/30 05:25:07
Modified: src/main/org/jboss/security/auth/spi
UsersRolesLoginModule.java
Log:
Prevent NPE for missing users/roles properties files
Fix problem with parsing of similar username roles
Revision Changes Path
1.6 +46 -40
jbosssx/src/main/org/jboss/security/auth/spi/UsersRolesLoginModule.java
Index: UsersRolesLoginModule.java
===================================================================
RCS file:
/cvsroot/jboss/jbosssx/src/main/org/jboss/security/auth/spi/UsersRolesLoginModule.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- UsersRolesLoginModule.java 2001/04/23 16:22:17 1.5
+++ UsersRolesLoginModule.java 2001/05/30 12:25:07 1.6
@@ -62,10 +62,10 @@
*/
public class UsersRolesLoginModule extends UsernamePasswordLoginModule
{
- // users+passwords, users+roles
- private Properties _users; // You might think these should be static. The
only problem with
- private Properties _roles; // static attributes is they are shared across the
VM. So I chose safety
- // over performance.
+ /** The users.properties values */
+ private Properties users;
+ /** The roles.properties values */
+ private Properties roles;
/**
* Initialize this LoginModule.
@@ -75,16 +75,16 @@
super.initialize(subject, callbackHandler, sharedState, options);
try
{
-// Load the properties file that contains the list of users and passwords
- LoadUsers();
- LoadRoles();
+ // Load the properties file that contains the list of users and
passwords
+ loadUsers();
+ loadRoles();
}
catch (Exception e)
{
- System.out.print("[JAASSecurity] PANIC! Couldn't load
users/passwords/role files.\n");
- e.printStackTrace();
-// Note that although this exception isn't passed on, _users or _roles will be null
-// so that any call to login will throw a LoginException.
+ // Note that although this exception isn't passed on, users or roles
will be null
+ // so that any call to login will throw a LoginException.
+ System.out.print("Error, couldn't load users/passwords/role files.\n");
+ e.printStackTrace();
}
}
@@ -102,9 +102,9 @@
*/
public boolean login() throws LoginException
{
- if(_users == null )
+ if( users == null )
throw new LoginException("Missing users.properties file.");
- if(_roles == null )
+ if( roles == null )
throw new LoginException("Missing roles.properties file.");
return super.login();
@@ -118,19 +118,21 @@
protected Group[] getRoleSets() throws LoginException
{
String targetUser = getUsername();
- Enumeration users = _roles.propertyNames();
+ Enumeration users = roles.propertyNames();
SimpleGroup rolesGroup = new SimpleGroup("Roles");
ArrayList groups = new ArrayList();
groups.add(rolesGroup);
while( users.hasMoreElements() )
{
String user = (String) users.nextElement();
- String value = _roles.getProperty(user);
- if( user.startsWith(targetUser) == false )
+ String value = roles.getProperty(user);
+ // See if this entry is of the form targetUser[.GroupName]=roles
+ int index = user.indexOf('.');
+ int length = index > 0 ? index : user.length();
+ if( targetUser.regionMatches(0, user, 0, length) == false )
continue;
// Check for username.RoleGroup pattern
- int index = user.indexOf('.');
if( index > 0 )
{
String groupName = user.substring(index+1);
@@ -139,7 +141,7 @@
else
{
SimpleGroup group = new SimpleGroup(groupName);
- parseGroupMembers(rolesGroup, value);
+ parseGroupMembers(group, value);
groups.add(group);
}
}
@@ -155,7 +157,11 @@
}
protected String getUsersPassword()
{
- return _users.getProperty(getUsername(), null);
+ String username = getUsername();
+ String password = null;
+ if( username != null )
+ password = users.getProperty(username , null);
+ return password;
}
// utility methods
@@ -170,14 +176,14 @@
}
}
- private void LoadUsers() throws IOException
+ private void loadUsers() throws IOException
{
- _users = LoadProperties("users.properties");
+ users = loadProperties("users.properties");
}
- private void LoadRoles() throws IOException
+ private void loadRoles() throws IOException
{
- _roles = LoadProperties("roles.properties");
+ roles = loadProperties("roles.properties");
}
/**
@@ -185,24 +191,24 @@
* key,value pairs in that file.
* The properties files should be in the class path.
*/
- private Properties LoadProperties(String propertiesName) throws IOException
+ private Properties loadProperties(String propertiesName) throws IOException
{
- Properties bundle = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- URL url = loader.getResource(propertiesName);
- if( url == null )
- throw new IOException("Properties file " + propertiesName + " not found");
- InputStream is = url.openStream();
- if( is != null )
- {
- bundle = new Properties();
- bundle.load(is);
- }
- else
- {
- throw new IOException("Properties file " + propertiesName + " not
avilable");
- }
- return bundle;
+ Properties bundle = null;
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ URL url = loader.getResource(propertiesName);
+ if( url == null )
+ throw new IOException("Properties file " + propertiesName + " not
found");
+ InputStream is = url.openStream();
+ if( is != null )
+ {
+ bundle = new Properties();
+ bundle.load(is);
+ }
+ else
+ {
+ throw new IOException("Properties file " + propertiesName + " not
avilable");
+ }
+ return bundle;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development