use of org.exist.http.servlets.BasicAuthenticator in project exist by eXist-db.
the class XQueryURLRewrite method configure.
private void configure() throws ServletException {
if (pool != null) {
return;
}
try {
final Class<?> driver = Class.forName(DRIVER);
final Database database = (Database) driver.newInstance();
database.setProperty("create-database", "true");
DatabaseManager.registerDatabase(database);
if (LOG.isDebugEnabled()) {
LOG.debug("Initialized database");
}
} catch (final Exception e) {
final String errorMessage = "Failed to initialize database driver";
LOG.error(errorMessage, e);
throw new ServletException(errorMessage + ": " + e.getMessage(), e);
}
try {
pool = BrokerPool.getInstance();
} catch (final EXistException e) {
throw new ServletException("Could not initialize db: " + e.getMessage(), e);
}
defaultUser = pool.getSecurityManager().getGuestSubject();
final String username = config.getInitParameter("user");
if (username != null) {
final String password = config.getInitParameter("password");
try {
final Subject user = pool.getSecurityManager().authenticate(username, password);
if (user != null && user.isAuthenticated()) {
defaultUser = user;
}
} catch (final AuthenticationException e) {
LOG.error("User can not be authenticated ({}), using default user.", username);
}
}
authenticator = new BasicAuthenticator(pool);
}
Aggregations