Search in sources :

Example 1 with BasicAuthenticator

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);
}
Also used : BasicAuthenticator(org.exist.http.servlets.BasicAuthenticator) AuthenticationException(org.exist.security.AuthenticationException) Database(org.xmldb.api.base.Database) EXistException(org.exist.EXistException) URISyntaxException(java.net.URISyntaxException) PermissionDeniedException(org.exist.security.PermissionDeniedException) LockException(org.exist.util.LockException) AuthenticationException(org.exist.security.AuthenticationException) SAXException(org.xml.sax.SAXException) EXistException(org.exist.EXistException) Subject(org.exist.security.Subject)

Aggregations

URISyntaxException (java.net.URISyntaxException)1 EXistException (org.exist.EXistException)1 BasicAuthenticator (org.exist.http.servlets.BasicAuthenticator)1 AuthenticationException (org.exist.security.AuthenticationException)1 PermissionDeniedException (org.exist.security.PermissionDeniedException)1 Subject (org.exist.security.Subject)1 LockException (org.exist.util.LockException)1 SAXException (org.xml.sax.SAXException)1 Database (org.xmldb.api.base.Database)1