xapi.server.AuthedServlet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xapi-gwt Show documentation
Show all versions of xapi-gwt Show documentation
This module exists solely to package all other gwt modules into a single
uber jar. This makes deploying to non-mavenized targets much easier.
Of course, you would be wise to inherit your dependencies individually;
the uber jar is intended for projects like collide,
which have complex configuration, and adding many jars would be a pain.
The newest version!
package xapi.server;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import xapi.server.auth.AuthService;
public class AuthedServlet extends HttpServlet{
private static final long serialVersionUID = -2466990550904790207L;
public AuthedServlet() {
}
protected AuthService getAuthService() {
// Allow subclasses to override our static service
return X_Server.getAuthService();
}
protected String getUserId(HttpServletRequest req) {
HttpSession session = req.getSession(false);
if (session == null)
return AuthService.NOT_LOGGED_IN;
return getAuthService().getUuid(req);
}
@Override
protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
String ident = getUserId(req);
if (ident == AuthService.NOT_LOGGED_IN) {
// do unauthorized head
} else {
if (isAllowed(ident, req)) {
super.doHead(req, resp);
} else {
resp.setContentLength(0);
resp.getOutputStream().close();
}
}
}
protected boolean isAllowed(String ident, HttpServletRequest req) {
return true; // Subclasses should provide this.
}
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
super.doDelete(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doGet(req, resp);
}
@Override
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
super.doOptions(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
super.doPost(req, resp);
}
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doPut(req, resp);
}
@Override
protected void doTrace(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
super.doTrace(req, resp);
}
}