use of teammates.logic.api.GateKeeper in project teammates by TEAMMATES.
the class LogoutServlet method doPost.
@Override
public final void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String nextUrl = req.getParameter(Const.ParamsNames.NEXT_URL);
if (nextUrl == null) {
nextUrl = "/";
}
String expectedId = req.getParameter(Const.ParamsNames.HINT);
String actualId = req.getParameter(Const.ParamsNames.USER_ID);
String logoutUrl = new GateKeeper().getLogoutUrl(nextUrl);
if (expectedId == null || actualId == null) {
resp.sendRedirect(logoutUrl);
return;
}
try {
req.setAttribute(Const.ParamsNames.HINT, StringHelper.decrypt(expectedId));
req.setAttribute(Const.ParamsNames.USER_ID, StringHelper.decrypt(actualId));
req.setAttribute(Const.ParamsNames.NEXT_URL, logoutUrl);
req.getRequestDispatcher(Const.ViewURIs.GOOGLE_ACCOUNT_HINT).forward(req, resp);
} catch (Exception e) {
resp.sendRedirect(logoutUrl);
}
}
use of teammates.logic.api.GateKeeper in project teammates by TEAMMATES.
the class PublicImageServlet method doPost.
@SuppressWarnings("unchecked")
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
String url = HttpRequestHelper.getRequestedUrl(req);
UserType userType = new GateKeeper().getCurrentUser();
Map<String, String[]> requestParameters = req.getParameterMap();
String blobKey = HttpRequestHelper.getValueFromParamMap(requestParameters, Const.ParamsNames.BLOB_KEY);
Assumption.assertPostParamNotNull(Const.ParamsNames.BLOB_KEY, blobKey);
try {
if (blobKey.isEmpty()) {
String message = "Failed to serve image with URL : blobKey is missing";
Map<String, String[]> params = HttpRequestHelper.getParameterMap(req);
log.info(new LogMessageGenerator().generateBasicActivityLogMessage(url, params, message, userType));
resp.sendError(1, "No image found");
} else {
resp.setContentType("image/png");
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
blobstoreService.serve(new BlobKey(blobKey), resp);
// TODO : restrict image request to those "public" files only
String message = "Public image request with URL: <br>" + "<a href=\"" + url + "\" target=\"_blank\" rel=\"noopener noreferrer\" >" + url + "</a>";
Map<String, String[]> params = HttpRequestHelper.getParameterMap(req);
log.info(new LogMessageGenerator().generateBasicActivityLogMessage(url, params, message, userType));
}
} catch (IOException ioe) {
Map<String, String[]> params = HttpRequestHelper.getParameterMap(req);
log.warning(new LogMessageGenerator().generateActionFailureLogMessage(url, params, ioe, userType));
} catch (Exception e) {
log.severe("Exception occured while performing " + Const.PublicActionNames.PUBLIC_IMAGE_SERVE_ACTION + ": " + TeammatesException.toStringWithStackTrace(e));
}
}
Aggregations