add baseDir option to jaas properties login module so that the path to properties file can be specified independt of the system property java.security.auth.login.config, useful when run with karaf jass arch

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1090179 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2011-04-08 10:04:57 +00:00
parent 24ed4fe5ae
commit 4ab47eb9aa
1 changed files with 15 additions and 12 deletions

View File

@ -38,9 +38,6 @@ import javax.security.auth.spi.LoginModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @version $Rev: $ $Date: $
*/
public class PropertiesLoginModule implements LoginModule {
private static final String USER_FILE = "org.apache.activemq.jaas.properties.user";
@ -75,12 +72,17 @@ public class PropertiesLoginModule implements LoginModule {
reload = "true".equalsIgnoreCase((String)options.get("reload"));
}
if (options.get("baseDir") != null) {
baseDir = new File((String)options.get("baseDir"));
}
setBaseDir();
usersFile = (String) options.get(USER_FILE) + "";
File uf = new File(baseDir, usersFile);
File uf = baseDir != null ? new File(baseDir, usersFile) : new File(usersFile);
if (reload || users == null || uf.lastModified() > usersReloadTime) {
if (debug) {
LOG.debug("Reloading users from " + usersFile);
LOG.debug("Reloading users from " + uf.getAbsolutePath());
}
try {
users = new Properties();
@ -94,10 +96,10 @@ public class PropertiesLoginModule implements LoginModule {
}
groupsFile = (String) options.get(GROUP_FILE) + "";
File gf = new File(baseDir, groupsFile);
File gf = baseDir != null ? new File(baseDir, groupsFile) : new File(groupsFile);
if (reload || groups == null || gf.lastModified() > groupsReloadTime) {
if (debug) {
LOG.debug("Reloading groups from " + groupsFile);
LOG.debug("Reloading groups from " + gf.getAbsolutePath());
}
try {
groups = new Properties();
@ -115,11 +117,9 @@ public class PropertiesLoginModule implements LoginModule {
if (baseDir == null) {
if (System.getProperty("java.security.auth.login.config") != null) {
baseDir = new File(System.getProperty("java.security.auth.login.config")).getParentFile();
} else {
baseDir = new File(".");
}
if (debug) {
LOG.debug("Using basedir=" + baseDir);
LOG.debug("Using basedir=" + baseDir.getAbsolutePath());
}
}
}
}
@ -141,6 +141,9 @@ public class PropertiesLoginModule implements LoginModule {
if (tmpPassword == null) {
tmpPassword = new char[0];
}
if (user == null) {
throw new FailedLoginException("user name is null");
}
String password = users.getProperty(user);
if (password == null) {