Search in sources :

Example 6 with GateKeeper

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);
    }
}
Also used : GateKeeper(teammates.logic.api.GateKeeper) IOException(java.io.IOException)

Example 7 with GateKeeper

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));
    }
}
Also used : BlobstoreService(com.google.appengine.api.blobstore.BlobstoreService) BlobKey(com.google.appengine.api.blobstore.BlobKey) LogMessageGenerator(teammates.common.util.LogMessageGenerator) GateKeeper(teammates.logic.api.GateKeeper) IOException(java.io.IOException) UserType(teammates.common.datatransfer.UserType) Map(java.util.Map) IOException(java.io.IOException) TeammatesException(teammates.common.exception.TeammatesException)

Aggregations

GateKeeper (teammates.logic.api.GateKeeper)7 UserType (teammates.common.datatransfer.UserType)3 IOException (java.io.IOException)2 LogMessageGenerator (teammates.common.util.LogMessageGenerator)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 BlobstoreService (com.google.appengine.api.blobstore.BlobstoreService)1 DatastoreTimeoutException (com.google.appengine.api.datastore.DatastoreTimeoutException)1 DeadlineExceededException (com.google.apphosting.api.DeadlineExceededException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 EntityNotFoundException (teammates.common.exception.EntityNotFoundException)1 FeedbackSessionNotVisibleException (teammates.common.exception.FeedbackSessionNotVisibleException)1 InvalidOriginException (teammates.common.exception.InvalidOriginException)1 InvalidPostParametersException (teammates.common.exception.InvalidPostParametersException)1 PageNotFoundException (teammates.common.exception.PageNotFoundException)1 TeammatesException (teammates.common.exception.TeammatesException)1 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)1 StatusMessage (teammates.common.util.StatusMessage)1 EmailSender (teammates.logic.api.EmailSender)1