if (allowedFileRequest(exchange.getRequestURI().getPath())) {
return new Authenticator.Success(new HttpPrincipal("", _realm));
}
Headers rmap = exchange.getRequestHeaders();
boolean isProtectedRequest = this.isProtectedRequest(exchange);
String auth = rmap.getFirst("Authorization");
if (auth == null) {
if ((_mode == DatabaseWikiProperties.AuthenticateAlways)
|| ((_mode == DatabaseWikiProperties.AuthenticateWriteOnly) && (isProtectedRequest))
|| (exchange.getRequestURI().getPath().equals(WikiServer.SpecialFolderLogin))) {
Headers map = exchange.getResponseHeaders();
map.set("WWW-Authenticate", "Basic realm=" + "\"" + _realm + "\"");
return new Authenticator.Retry(401);
} else {
return new Authenticator.Success(new HttpPrincipal(User.UnknownUserName, _realm));
}
} else {
int sp = auth.indexOf(' ');
if (sp == -1 || !auth.substring(0, sp).equals("Basic")) {
return new Authenticator.Failure(401);
}
byte[] b = new Base64().base64ToByteArray(auth.substring(sp + 1));
String userpass = new String(b);
int colon = userpass.indexOf(':');
String uname = userpass.substring(0, colon);
String pass = userpass.substring(colon + 1);
if ((_mode == DatabaseWikiProperties.AuthenticateAlways)
|| ((_mode == DatabaseWikiProperties.AuthenticateWriteOnly) && (isProtectedRequest))
|| (exchange.getRequestURI().getPath().equals(WikiServer.SpecialFolderLogin))) {
if (checkCredentials(uname, pass)) {
return new Authenticator.Success(new HttpPrincipal(uname, _realm));
} else {
Headers map = exchange.getResponseHeaders();
map.set("WWW-Authenticate", "Basic realm=" + "\"" + _realm + "\"");
return new Authenticator.Failure(401);
}
} else {
return new Authenticator.Success(new HttpPrincipal(uname, _realm));
}