throws HandlerException {
if (request.getRequestURI().getPath().equals("/meta/account-manager")) {
Subject subject = new Subject();
subject.getPrincipals().add(SuperUserGVSPrincipal.instance);
try {
Subject.doAsPrivileged(subject, new PrivilegedExceptionAction() {
public Object run() throws Exception {
wrapped.handle(request, response);
return null;
}
}, null);
} catch (PrivilegedActionException e) {
throw new RuntimeException(e);
}
} else {
LoginContext loginContext;
try {
loginContext = new LoginContext("GVS-Auth", new CookieCallbackHandler(request));
loginContext.login();
} catch (LoginException e) {
/*response.setResponseStatus(ResponseStatus.FORBIDDEN);
log.info(e);
response.setBody(new MessageBody2Read() {
public ReadableByteChannel read() throws IOException {
return Channels.newChannel(new ByteArrayInputStream("Login Failed".getBytes()));
}
});
return;*/
try {
Cookie loginCookie = new Cookie("login", "-");
loginCookie.setMaxAge(-1);
response.setHeader(HeaderName.SET_COOKIE, loginCookie.toString());
loginContext = new LoginContext("GVS-Auth", new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
((NameCallback) callbacks[i]).setName("");
} else if (callbacks[i] instanceof PasswordCallback) {
((PasswordCallback) callbacks[i]).setPassword(""
.toCharArray());
} else {
throw new UnsupportedCallbackException(callbacks[i],
"Callback class not supported");
}
}
}
});
loginContext.login();
} catch (LoginException e1) {
// TODO Auto-generated catch block
throw new RuntimeException(e1);
}
}
try {
Subject subject = loginContext.getSubject();
Subject.doAsPrivileged(subject, new PrivilegedExceptionAction() {
public Object run() throws Exception {
wrapped.handle(request, response);
return null;
}
}, null);