Skip to content

Commit

Permalink
[bugfix] XQueryURLRewrite does not check basic auth header, but alway…
Browse files Browse the repository at this point in the history
…s executes controller as guest.
  • Loading branch information
wolfgangmm committed Jan 30, 2014
1 parent 6369bf5 commit 2698cf3
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/org/exist/http/urlrewrite/XQueryURLRewrite.java
Expand Up @@ -33,6 +33,8 @@

import org.apache.log4j.Logger;

import org.exist.http.servlets.Authenticator;
import org.exist.http.servlets.BasicAuthenticator;
import org.exist.security.internal.web.HttpAccount;
import org.exist.source.Source;
import org.exist.source.DBSource;
Expand Down Expand Up @@ -139,7 +141,9 @@ public class XQueryURLRewrite extends HttpServlet {
private boolean compiledCache = true;

private RewriteConfig rewriteConfig;


private Authenticator authenticator;

@Override
public void init(ServletConfig filterConfig) throws ServletException {
// save FilterConfig for later use
Expand Down Expand Up @@ -187,8 +191,18 @@ protected void service(HttpServletRequest servletRequest, HttpServletResponse se
Subject user = defaultUser;

Subject requestUser = HttpAccount.getUserFromServletRequest(request);
if (requestUser != null)
{user = requestUser;}
if (requestUser != null) {
user = requestUser;
} else {
// Secondly try basic authentication
final String auth = request.getHeader("Authorization");
if (auth != null) {
requestUser = authenticator.authenticate(request, response);
if (requestUser != null) {
user = requestUser;
}
}
}

try {
configure();
Expand Down Expand Up @@ -637,6 +651,7 @@ private void configure() throws ServletException {
LOG.error("User can not be authenticated ("+username+"), using default user.");
}
}
authenticator = new BasicAuthenticator(pool);
}

private void logResult(DBBroker broker, Sequence result) throws IOException, SAXException {
Expand Down

0 comments on commit 2698cf3

Please sign in to comment.