use of edu.stanford.bmir.protege.web.server.session.WebProtegeSessionImpl in project webprotege by protegeproject.
the class WebProtegeRemoteServiceServlet method getUserInSession.
/**
* Gets the userId for the client associated with the current thread local request.
*
* @return The UserId. Not null (if no user is logged in then the value specified by {@link edu.stanford.bmir.protege.web.shared.user.UserId#getGuest()} ()}
* will be returned.
*/
public UserId getUserInSession() {
HttpServletRequest request = getThreadLocalRequest();
final HttpSession session = request.getSession();
return new WebProtegeSessionImpl(session).getUserInSession();
}
use of edu.stanford.bmir.protege.web.server.session.WebProtegeSessionImpl in project webprotege by protegeproject.
the class WebProtegeSessionListener method sessionDestroyed.
@Override
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
WebProtegeSession session = new WebProtegeSessionImpl(httpSessionEvent.getSession());
UserId userId = session.getUserInSession();
if (!userId.isGuest()) {
logger.info("{} Session expired", userId);
userActivityManager.setLastLogout(userId, System.currentTimeMillis());
}
}
use of edu.stanford.bmir.protege.web.server.session.WebProtegeSessionImpl in project webprotege by protegeproject.
the class DispatchServlet method executeAction.
@Override
public DispatchServiceResultContainer executeAction(Action action) throws ActionExecutionException, PermissionDeniedException {
UserId userId = getUserInSession();
HttpServletRequest request = getThreadLocalRequest();
HttpSession session = request.getSession();
final RequestContext requestContext = new RequestContext(userId);
final ExecutionContext executionContext = new ExecutionContext(new WebProtegeSessionImpl(session));
return executor.execute(action, requestContext, executionContext);
}
use of edu.stanford.bmir.protege.web.server.session.WebProtegeSessionImpl in project webprotege by protegeproject.
the class ProjectDownloadServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final WebProtegeSession webProtegeSession = new WebProtegeSessionImpl(req.getSession());
UserId userId = webProtegeSession.getUserInSession();
FileDownloadParameters downloadParameters = new FileDownloadParameters(req);
if (!downloadParameters.isProjectDownload()) {
logger.info("Bad project download request from {} at {}. Request URI: {} Query String: {}", webProtegeSession.getUserInSession(), formatAddr(req), req.getRequestURI(), req.getQueryString());
resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
logger.info("Received download request from {} at {} for project {}", userId, formatAddr(req), downloadParameters.getProjectId());
if (!accessManager.hasPermission(Subject.forUser(userId), new ProjectResource(downloadParameters.getProjectId()), BuiltInAction.DOWNLOAD_PROJECT)) {
logger.info("Denied download request as user does not have permission to download this project.");
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
} else if (downloadParameters.isProjectDownload()) {
startProjectDownload(resp, userId, downloadParameters);
}
}
use of edu.stanford.bmir.protege.web.server.session.WebProtegeSessionImpl in project webprotege by protegeproject.
the class FileUploadServlet method doPost.
@Override
@SuppressWarnings("unchecked")
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
WebProtegeSession webProtegeSession = new WebProtegeSessionImpl(req.getSession());
UserId userId = webProtegeSession.getUserInSession();
if (!accessManager.hasPermission(Subject.forUser(userId), ApplicationResource.get(), BuiltInAction.UPLOAD_PROJECT)) {
sendErrorMessage(resp, "You do not have permission to upload files to " + applicationNameSupplier.get());
}
logger.info("Received upload request from {} at {}", webProtegeSession.getUserInSession(), formatAddr(req));
resp.setHeader("Content-Type", RESPONSE_MIME_TYPE);
try {
if (ServletFileUpload.isMultipartContent(req)) {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setFileSizeMax(maxUploadSizeSupplier.get());
List<FileItem> items = upload.parseRequest(req);
for (FileItem item : items) {
if (!item.isFormField()) {
File uploadedFile = createServerSideFile();
item.write(uploadedFile);
long sizeInBytes = uploadedFile.length();
long computedFileSizeInBytes = computeFileSize(uploadedFile);
logger.info("File size is {} bytes. Computed file size is {} bytes.", sizeInBytes, computedFileSizeInBytes);
if (computedFileSizeInBytes > maxUploadSizeSupplier.get()) {
sendFileSizeTooLargeResponse(resp);
} else {
logger.info("Stored uploaded file with name {}", uploadedFile.getName());
resp.setStatus(HttpServletResponse.SC_CREATED);
sendSuccessMessage(resp, uploadedFile.getName());
}
return;
}
}
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not find form file item");
} else {
logger.info("Bad upload request: POST must be multipart encoding.");
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "POST must be multipart encoding.");
}
} catch (FileUploadBase.FileSizeLimitExceededException | FileUploadBase.SizeLimitExceededException e) {
sendFileSizeTooLargeResponse(resp);
} catch (FileUploadBase.FileUploadIOException | FileUploadBase.IOFileUploadException e) {
logger.info("File upload failed because an IOException occurred: {}", e.getMessage(), e);
sendErrorMessage(resp, "File upload failed because of an IOException");
} catch (FileUploadBase.InvalidContentTypeException e) {
logger.info("File upload failed because the content type was invalid: {}", e.getMessage());
sendErrorMessage(resp, "File upload failed because the content type is invalid");
} catch (FileUploadException e) {
logger.info("File upload failed: {}", e.getMessage());
sendErrorMessage(resp, "File upload failed");
} catch (Exception e) {
logger.info("File upload failed because of an error when trying to write the file item: {}", e.getMessage(), e);
sendErrorMessage(resp, "File upload failed");
}
}
Aggregations