* @see org.wymiwyg.rwcf.Handler#handle(org.wymiwyg.rwcf.Request,
* org.wymiwyg.rwcf.Response, org.wymiwyg.rwcf.HandlerChain)
*/
public void handle(final Request request, final Response response,
final HandlerChain chain) throws HandlerException {
final EnhancedRequest ehRequest = new EnhancedRequest(request);
LoginContext loginContext;
boolean httpLoginForced = false;
if (noAdminUserConfigured) {
noAdminUserConfigured = !isAdminExisting();
if (noAdminUserConfigured && initialConfiguratorAvailable) {
String path = request.getRequestURI().getPath();
if (path.equals("/admin/initial-configuration")
|| path.equals("/admin/refresh-cache")
|| (path.startsWith("/stylesheets/"))
|| (path.startsWith("/images/"))
|| (path.startsWith("/scripts/"))) {
chain.doNext(request, response);
return;
}
EnhancedResponse ehResponse = new EnhancedResponse(response);
ehResponse.sendRedirect("/admin/initial-configuration");
return;
}
}
try {
try {
httpLoginForced = request.getRequestURI().getParameterValues(
"forceHttpLogin")[0].equals("true");
} catch (Exception ex) {
}
CallbackHandler callbackHandler;
if (useCookieLogin && !httpLoginForced) {
callbackHandler = new CookieCallBackHandler(ehRequest, response);
} else {
callbackHandler = new WebCallBackHandler(request);
}
loginContext = new LoginContext(servletContextName, callbackHandler);
} catch (LoginException e) {
logger.error("Initializing LoginContext", e);
throw new RuntimeException(e.toString());
}
try {
loginContext.login();
} catch (LoginException e) {
}
try {
Subject subject = loginContext.getSubject();
Subject.doAsPrivileged(subject, new PrivilegedExceptionAction() {
public Object run() throws Exception {
// setting the policy only in the init method causes the
// current ProtectionDomain to
// be cached, i.E. all checks from classes within the
// current classpath entry to authorized
Policy.setPolicy(new RPolicy());
boolean isAdmin = false;
try {
AccessController.checkPermission(new RPermission(
AUTHORIZATION.admin));
isAdmin = true;
} catch (Exception e) {
}
if (!isAdmin) {
AccessControlFilter.checkPermssionOnResource(model
.createResource(ehRequest
.getRequestURLWithoutParams()
.toString()));
}
Request requestNoLoginParam = checkLoginRequested(request);
chain.doNext(requestNoLoginParam, response);
return null;
}
}, null);
} catch (AccessControlException e) {
// Authentication failed.
logger.debug("AccessControlException, will prompt for login", e);
if (useCookieLogin && !httpLoginForced
&& !ehRequest.getMethod().equals(Method.POST)
&& !ehRequest.getMethod().equals(Method.PUT)
&& !ehRequest.getMethod().equals(Method.MKCOL)
&& !ehRequest.getMethod().equals(Method.PROPFIND)) {
EnhancedResponse ehResponse = new EnhancedResponse(response);
try {
ehResponse.sendRedirect("/login?target="
+ URLEncoder.encode(ehRequest.getFullRequestURL()
.toString(), "utf-8"));
} catch (UnsupportedEncodingException e1) {
throw new RuntimeException(e1);
}
} else {