tomcatUsersLocation = "../../tomcat-users.xml";
}
javax.naming.Reference ref = new javax.naming.Reference("org.apache.catalina.UserDatabase");
ref.add(new StringRefAddr("pathname", tomcatUsersLocation));
MemoryUserDatabase memoryUserDatabase =
(MemoryUserDatabase) new MemoryUserDatabaseFactory().getObjectInstance(
ref,
new CompositeName("UserDatabase"),
null,
null);
// Add basic auth user
if(commandLineParams.basicAuthUser != null && commandLineParams.basicAuthPw != null) {
memoryUserDatabase.setReadonly(false);
Role user = memoryUserDatabase.createRole(AUTH_ROLE, AUTH_ROLE);
memoryUserDatabase.createUser(
commandLineParams.basicAuthUser,
commandLineParams.basicAuthPw,
commandLineParams.basicAuthUser).addRole(user);
memoryUserDatabase.save();
} else if (System.getenv("BASIC_AUTH_USER") != null && System.getenv("BASIC_AUTH_PW") != null) {
memoryUserDatabase.setReadonly(false);
Role user = memoryUserDatabase.createRole(AUTH_ROLE, AUTH_ROLE);
memoryUserDatabase.createUser(
System.getenv("BASIC_AUTH_USER"),
System.getenv("BASIC_AUTH_PW"),
System.getenv("BASIC_AUTH_USER")).addRole(user);
memoryUserDatabase.save();
}
// Register memoryUserDatabase with GlobalNamingContext
System.out.println("MemoryUserDatabase: " + memoryUserDatabase);
tomcat.getServer().getGlobalNamingContext().addToEnvironment("UserDatabase", memoryUserDatabase);