List of usage examples for javax.servlet.http HttpServletRequest getRemoteUser
public String getRemoteUser();
null
if the user has not been authenticated. From source file:org.opennms.web.controller.event.EventController.java
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception { List<OnmsFilterFavorite> userFilterList = favoriteService.getFavorites(request.getRemoteUser(), OnmsFilterFavorite.Page.EVENT); ModelAndView modelAndView = new ModelAndView("event/index"); modelAndView.addObject("favorites", userFilterList.toArray()); modelAndView.addObject("callback", getFilterCallback()); return modelAndView; }
From source file:com.ikon.servlet.admin.CssServlet.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doGet({}, {})", request, response); request.setCharacterEncoding("UTF-8"); String action = WebUtils.getString(request, "action"); String userId = request.getRemoteUser(); updateSessionManager(request);//from w w w . j a v a 2 s . c o m try { if (action.equals("create")) { create(userId, request, response); } else if (action.equals("edit")) { edit(userId, request, response); } else if (action.equals("delete")) { delete(userId, request, response); } else if (action.equals("download")) { download(userId, request, response); } if (action.equals("") || WebUtils.getBoolean(request, "persist")) { list(userId, request, response); } } catch (DatabaseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } }
From source file:com.ikon.servlet.admin.CronTabServlet.java
@Override @SuppressWarnings("unchecked") public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doPost({}, {})", request, response); request.setCharacterEncoding("UTF-8"); String action = ""; String userId = request.getRemoteUser(); updateSessionManager(request);/*from www . j a v a 2 s.c om*/ try { if (ServletFileUpload.isMultipartContent(request)) { InputStream is = null; FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request); CronTab ct = new CronTab(); for (Iterator<FileItem> it = items.iterator(); it.hasNext();) { FileItem item = it.next(); if (item.isFormField()) { if (item.getFieldName().equals("action")) { action = item.getString("UTF-8"); } else if (item.getFieldName().equals("ct_id")) { ct.setId(Integer.parseInt(item.getString("UTF-8"))); } else if (item.getFieldName().equals("ct_name")) { ct.setName(item.getString("UTF-8")); } else if (item.getFieldName().equals("ct_mail")) { ct.setMail(item.getString("UTF-8")); } else if (item.getFieldName().equals("ct_expression")) { ct.setExpression(item.getString("UTF-8")); } else if (item.getFieldName().equals("ct_active")) { ct.setActive(true); } } else { is = item.getInputStream(); ct.setFileName(FilenameUtils.getName(item.getName())); ct.setFileContent(SecureStore.b64Encode(IOUtils.toByteArray(is))); ct.setFileMime(MimeTypeConfig.mimeTypes.getContentType(item.getName())); is.close(); } } if (action.equals("create")) { CronTabDAO.create(ct); // Activity log UserActivity.log(userId, "ADMIN_CRONTAB_CREATE", null, null, ct.toString()); list(request, response); } else if (action.equals("edit")) { CronTabDAO.update(ct); // Activity log UserActivity.log(userId, "ADMIN_CRONTAB_EDIT", Long.toString(ct.getId()), null, ct.toString()); list(request, response); } else if (action.equals("delete")) { CronTabDAO.delete(ct.getId()); // Activity log UserActivity.log(userId, "ADMIN_CRONTAB_DELETE", Long.toString(ct.getId()), null, null); list(request, response); } } } catch (DatabaseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (FileUploadException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } }
From source file:io.apiman.common.servlet.AuthenticationFilter.java
/** * Handle BASIC authentication. Delegates this to the container by invoking 'login' * on the inbound http servlet request object. * @param credentials//from w ww. jav a2s . c om * @param request * @param response * @param chain * @throws IOException * @throws ServletException */ protected void doBasicAuth(Creds credentials, HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { try { if (credentials.username.equals(request.getRemoteUser())) { // Already logged in as this user - do nothing. This can happen // in some app servers if the app server processes the BASIC auth // credentials before this filter gets a crack at them. WildFly 8 // works this way, for example (despite the web.xml not specifying // any login config!). } else if (request.getRemoteUser() != null) { // switch user request.logout(); request.login(credentials.username, credentials.password); } else { request.login(credentials.username, credentials.password); } } catch (Exception e) { // TODO log this error? e.printStackTrace(); sendAuthResponse((HttpServletResponse) response); return; } doFilterChain(request, response, chain, null); }
From source file:org.opennms.web.controller.event.EventController.java
/** * {@inheritDoc}//from w w w . j a v a 2 s .com * * Parses the query string to determine what types of event filters to use * (for example, what to filter on or sort by), then does the database query * and then forwards the results to a JSP for display. * * <p> * Sets the <em>events</em> and <em>parms</em> request attributes for * the forwardee JSP (or whatever gets called). * </p> */ public ModelAndView list(HttpServletRequest request, HttpServletResponse response) throws Exception { OnmsFilterFavorite favorite = getFavorite(request.getParameter("favoriteId"), request.getRemoteUser(), request.getParameterValues("filter")); return list(request, favorite); }
From source file:org.eclipse.orion.server.git.servlets.GitIndexHandlerV1.java
@Override public boolean handleRequest(HttpServletRequest request, HttpServletResponse response, String path) throws ServletException { Repository db = null;/* www . j av a2 s.c om*/ try { IPath p = new Path(path); IPath filePath = p.hasTrailingSeparator() ? p : p.removeLastSegments(1); if (!AuthorizationService.checkRights(request.getRemoteUser(), "/" + filePath.toString(), request.getMethod())) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return true; } Set<Entry<IPath, File>> set = GitUtils.getGitDirs(filePath, Traverse.GO_UP).entrySet(); File gitDir = set.iterator().next().getValue(); if (gitDir == null) return false; // TODO: or an error response code, 405? db = FileRepositoryBuilder.create(gitDir); switch (getMethod(request)) { case GET: return handleGet(request, response, db, GitUtils.getRelativePath(p, set.iterator().next().getKey())); case PUT: return handlePut(request, response, db, GitUtils.getRelativePath(p, set.iterator().next().getKey())); case POST: return handlePost(request, response, db, p); default: //fall through and return false below } } catch (Exception e) { String msg = NLS.bind("Failed to process an operation on index for {0}", path); //$NON-NLS-1$ ServerStatus status = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); LogHelper.log(status); return statusHandler.handleRequest(request, response, status); } finally { if (db != null) db.close(); } return false; }
From source file:io.zipi.common.servlet.AuthenticationFilter.java
/** * Handle BASIC authentication. Delegates this to the container by invoking 'login' * on the inbound http servlet request object. * @param credentials the credentials//w w w . j a v a 2 s . c o m * @param request the http servlet request * @param response the http servlet respose * @param chain the filter chain * @throws IOException when I/O failure occurs in filter chain * @throws ServletException when servlet exception occurs during auth */ protected void doBasicAuth(Creds credentials, HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { try { if (credentials.username.equals(request.getRemoteUser())) { // Already logged in as this user - do nothing. This can happen // in some app servers if the app server processes the BASIC auth // credentials before this filter gets a crack at them. WildFly 8 // works this way, for example (despite the web.xml not specifying // any login config!). } else if (request.getRemoteUser() != null) { // switch user request.logout(); request.login(credentials.username, credentials.password); } else { request.login(credentials.username, credentials.password); } } catch (Exception e) { // TODO log this error? e.printStackTrace(); sendAuthResponse(response); return; } doFilterChain(request, response, chain, null); }
From source file:org.eclipse.orion.server.useradmin.servlets.UserAuthFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; if ("POST".equals(httpRequest.getMethod()) && httpRequest.getParameter(UserConstants.KEY_RESET) == null) { //$NON-NLS-1$ // either everyone can create users, or only the specific list if (authorizedAccountCreators == null || authorizedAccountCreators.contains(httpRequest.getRemoteUser())) { chain.doFilter(request, response); return; }/* w w w . ja v a 2 s . c o m*/ } String login = authenticationService.authenticateUser(httpRequest, httpResponse, authProperties); if (login == null) return; request.setAttribute(HttpContext.REMOTE_USER, login); request.setAttribute(HttpContext.AUTHENTICATION_TYPE, authenticationService.getAuthType()); try { String requestPath = httpRequest.getServletPath() + (httpRequest.getPathInfo() == null ? "" : httpRequest.getPathInfo()); if (!AuthorizationService.checkRights(login, requestPath, httpRequest.getMethod())) { httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN); return; } } catch (JSONException e) { httpResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } chain.doFilter(request, response); }
From source file:org.kuali.rice.ken.web.spring.AdministerNotificationRequestController.java
/** * This method handles approval/disapproval/acknowledgement of the notification request * @param request the HttpServletRequest * @param response the HttpServletResponse * @param command the command object bound for this MultiActionController * @throws ServletException//from w w w. j a v a 2s . c o m */ private void administerEventNotificationMessage(HttpServletRequest request, HttpServletResponse response, AdministerNotificationRequestCommand command, String action) throws ServletException { LOG.debug("remoteUser: " + request.getRemoteUser()); BindException bindException = new BindException(command, "command"); ValidationUtils.rejectIfEmpty(bindException, "docId", "Document id must be specified"); if (bindException.hasErrors()) { throw new ServletRequestBindingException("Document id must be specified", bindException); } // obtain a workflow user object first //WorkflowIdDTO user = new WorkflowIdDTO(request.getRemoteUser()); String userId = request.getRemoteUser(); try { // now construct the workflow document, which will interact with workflow WorkflowDocument document = NotificationWorkflowDocument.loadNotificationDocument(userId, command.getDocId()); NotificationBo notification = retrieveNotificationForWorkflowDocument(document); String initiatorPrincipalId = document.getInitiatorPrincipalId(); Person initiator = KimApiServiceLocator.getPersonService().getPerson(initiatorPrincipalId); String notificationBlurb = notification.getContentType().getName() + " notification submitted by " + initiator.getName() + " for channel " + notification.getChannel().getName(); if ("disapprove".equals(action)) { document.disapprove("User " + userId + " disapproving " + notificationBlurb); } else if ("approve".equals(action)) { document.approve("User " + userId + " approving " + notificationBlurb); } else if ("acknowledge".equals(action)) { document.acknowledge("User " + userId + " acknowledging " + notificationBlurb); } } catch (Exception e) { LOG.error("Exception occurred taking action on notification request", e); throw new ServletException("Exception occurred taking action on notification request", e); } }