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.openecomp.sdcrests.action.rest.services.ActionsImpl.java
@Override public Response deleteAction(String actionInvariantUuId, HttpServletRequest servletRequest) { try {//ww w .j ava 2 s .co m log.debug(" entering API deleteAction "); initializeRequestMDC(servletRequest, actionInvariantUuId, ActionRequest.DELETE_ACTION); Map<String, String> errorMap = validateRequestHeaders(servletRequest); if (errorMap.isEmpty()) { String user = servletRequest.getRemoteUser(); actionManager.deleteAction(actionInvariantUuId, user); } else { checkAndThrowError(errorMap); } actionLogPostProcessor(StatusCode.COMPLETE, true); log.debug(" exit API deleteAction "); return Response.ok(new ActionResponseDto()).build(); } catch (ActionException e) { actionLogPostProcessor(StatusCode.ERROR, e.getErrorCode(), e.getDescription(), true); actionErrorLogProcessor(CategoryLogLevel.ERROR, e.getErrorCode(), e.getDescription()); log.error(MDC.get(ERROR_DESCRIPTION)); throw e; } catch (Exception e) { actionLogPostProcessor(StatusCode.ERROR, true); actionErrorLogProcessor(CategoryLogLevel.ERROR, ACTION_INTERNAL_SERVER_ERR_CODE, ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); log.error(e.getMessage()); throw e; } finally { finalAuditMetricsLogProcessor(ActionRequest.DELETE_ACTION.name()); } }
From source file:net.sourceforge.subsonic.controller.RESTController.java
private String createPlayerIfNecessary(HttpServletRequest request, boolean jukebox) { String username = request.getRemoteUser(); String clientId = request.getParameter("c"); if (jukebox) { clientId += "-jukebox"; }//from w w w .j a va 2 s.c om List<Player> players = playerService.getPlayersForUserAndClientId(username, clientId); // If not found, create it. if (players.isEmpty()) { Player player = new Player(); player.setIpAddress(request.getRemoteAddr()); player.setUsername(username); player.setClientId(clientId); player.setName(clientId); player.setTechnology(jukebox ? PlayerTechnology.JUKEBOX : PlayerTechnology.EXTERNAL_WITH_PLAYLIST); playerService.createPlayer(player); players = playerService.getPlayersForUserAndClientId(username, clientId); } // Return the player ID. return !players.isEmpty() ? players.get(0).getId() : null; }
From source file:alpha.portal.webapp.controller.CardVersionHistoryController.java
/** * Show form.//ww w . ja v a2s.com * * @param m * the m * @param request * the request * @return the string * @throws IOException * Signals that an I/O exception has occurred. */ @RequestMapping(method = RequestMethod.GET) protected String showForm(final Model m, final HttpServletRequest request) throws IOException { final String caseId = request.getParameter("case"); final String version = request.getParameter("version"); String paging = ""; for (final Object e : request.getParameterMap().keySet()) { if ((e.toString().length() > 2) && e.toString().substring(0, 2).equalsIgnoreCase("d-")) { paging = e.toString() + "=" + request.getParameter(e.toString()); break; } } m.addAttribute("paging", paging); Long versionL = null; if (StringUtils.isNotBlank(version)) { try { versionL = Long.parseLong(version); } catch (final NumberFormatException e) { this.saveError(request, "card.invalidVersion"); return "redirect:/caseform?caseId=" + caseId; } } if (StringUtils.isBlank(caseId) || !this.caseManager.exists(caseId)) { this.saveError(request, "case.invalidId"); return "redirect:/caseMenu"; } final AlphaCase alphaCase = this.caseManager.get(caseId); final List<AlphaCard> versions = this.cardManager.getAllVersions(caseId); m.addAttribute("case", alphaCase); m.addAttribute("cards", versions); AlphaCard activeCard = null; final User user = this.getUserManager().getUserByUsername(request.getRemoteUser()); for (final AlphaCard c : versions) { if (c.getAlphaCardIdentifier().getSequenceNumber() == versionL) { final Adornment contributor = c.getAlphaCardDescriptor() .getAdornment(AdornmentType.Contributor.getName()); if ((user == null) || ((contributor != null) && !contributor.getValue().equals(user.getId().toString()))) { this.saveError(request, "card.invalidId"); return "cardVersionHistory"; } activeCard = c; break; } } m.addAttribute("activeCard", activeCard); return "cardVersionHistory"; }
From source file:org.eclipse.orion.internal.server.servlets.workspace.WorkspaceResourceHandler.java
private ProjectInfo handleAddProject(HttpServletRequest request, HttpServletResponse response, WorkspaceInfo workspace, JSONObject data) throws IOException, ServletException { //make sure required fields are set JSONObject toAdd = data;// w ww . j a v a2 s. c o m String id = toAdd.optString(ProtocolConstants.KEY_ID, null); String name = toAdd.optString(ProtocolConstants.KEY_NAME, null); if (name == null) name = request.getHeader(ProtocolConstants.HEADER_SLUG); if (!validateProjectName(workspace, name, request, response)) return null; ProjectInfo project = new ProjectInfo(); if (id != null) project.setUniqueId(id); project.setFullName(name); project.setWorkspaceId(workspace.getUniqueId()); String content = toAdd.optString(ProtocolConstants.KEY_CONTENT_LOCATION, null); if (!isAllowedLinkDestination(content, request.getRemoteUser())) { String msg = NLS.bind( "Cannot link to server path {0}. Use the orion.file.allowedPaths property to specify server locations where content can be linked.", content); statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_FORBIDDEN, msg, null)); return null; } try { //project creation will assign unique project id getMetaStore().createProject(project); } catch (CoreException e) { String msg = "Error persisting project state"; statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e)); return null; } try { computeProjectLocation(request, project, content, getInit(toAdd)); getMetaStore().updateProject(project); } catch (CoreException e) { boolean authFail = handleAuthFailure(request, response, e); //delete the project so we don't end up with a project in a bad location try { getMetaStore().deleteProject(workspace.getUniqueId(), project.getFullName()); } catch (CoreException e1) { //swallow secondary error LogHelper.log(e1); } if (authFail) { return null; } //we are unable to write in the platform location! String msg = NLS.bind("Cannot create project: {0}", project.getFullName()); statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e)); return null; } //serialize the new project in the response //the baseLocation should be the workspace location URI baseLocation = getURI(request); JSONObject result = WebProjectResourceHandler.toJSON(workspace, project, baseLocation); OrionServlet.writeJSONResponse(request, response, result); //add project location to response header response.setHeader(ProtocolConstants.HEADER_LOCATION, result.optString(ProtocolConstants.KEY_LOCATION)); response.setStatus(HttpServletResponse.SC_CREATED); return project; }
From source file:net.bull.javamelody.TestMonitoringFilter.java
private void doFilter(HttpServletRequest request, Throwable exceptionInDoFilter) throws ServletException, IOException { final FilterChain chain = createNiceMock(FilterChain.class); expect(request.getRequestURI()).andReturn("/test/request").anyTimes(); expect(request.getContextPath()).andReturn(CONTEXT_PATH).anyTimes(); expect(request.getMethod()).andReturn("GET").anyTimes(); if (exceptionInDoFilter != null) { // cela fera une erreur systme http compte dans les stats expect(request.getRemoteUser()).andThrow(exceptionInDoFilter); }//w ww . j a v a 2 s .co m final HttpServletResponse response = createNiceMock(HttpServletResponse.class); replay(request); replay(response); replay(chain); if (exceptionInDoFilter != null) { try { monitoringFilter.doFilter(request, response, chain); } catch (final Throwable t) { // NOPMD assertNotNull("ok", t); } } else { monitoringFilter.doFilter(request, response, chain); } verify(request); verify(response); verify(chain); }
From source file:org.esigate.servlet.impl.RequestFactory.java
public IncomingRequest create(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException { HttpServletRequestContext context = new HttpServletRequestContext(request, response, servletContext, filterChain);//from w w w .j a v a 2s . c om // create request line String uri = UriUtils.createURI(request.getScheme(), request.getServerName(), request.getServerPort(), request.getRequestURI(), request.getQueryString(), null); ProtocolVersion protocolVersion = BasicLineParser.parseProtocolVersion(request.getProtocol(), null); IncomingRequest.Builder builder = IncomingRequest .builder(new BasicRequestLine(request.getMethod(), uri, protocolVersion)); builder.setContext(context); // copy headers @SuppressWarnings("rawtypes") Enumeration names = request.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); @SuppressWarnings("rawtypes") Enumeration values = request.getHeaders(name); while (values.hasMoreElements()) { String value = (String) values.nextElement(); builder.addHeader(name, value); } } // create entity HttpServletRequestEntity entity = new HttpServletRequestEntity(request); builder.setEntity(entity); builder.setRemoteAddr(request.getRemoteAddr()); builder.setRemoteUser(request.getRemoteUser()); HttpSession session = request.getSession(false); if (session != null) { builder.setSessionId(session.getId()); } builder.setUserPrincipal(request.getUserPrincipal()); // Copy cookies // As cookie header contains only name=value so we don't need to copy // all attributes! javax.servlet.http.Cookie[] src = request.getCookies(); if (src != null) { for (int i = 0; i < src.length; i++) { javax.servlet.http.Cookie c = src[i]; BasicClientCookie dest = new BasicClientCookie(c.getName(), c.getValue()); builder.addCookie(dest); } } builder.setSession(new HttpServletSession(request)); builder.setContextPath(request.getContextPath()); return builder.build(); }
From source file:org.apache.ofbiz.base.util.UtilHttp.java
public static void setInitialRequestInfo(HttpServletRequest request) { HttpSession session = request.getSession(); if (UtilValidate.isNotEmpty(session.getAttribute("_WEBAPP_NAME_"))) { // oops, info already in place... return;/*from w w w . j av a 2 s.c o m*/ } String fullRequestUrl = getFullRequestUrl(request); session.setAttribute("_WEBAPP_NAME_", getApplicationName(request)); session.setAttribute("_CLIENT_LOCALE_", request.getLocale()); session.setAttribute("_CLIENT_REQUEST_", fullRequestUrl); session.setAttribute("_CLIENT_USER_AGENT_", request.getHeader("User-Agent") != null ? request.getHeader("User-Agent") : ""); session.setAttribute("_CLIENT_REFERER_", request.getHeader("Referer") != null ? request.getHeader("Referer") : ""); session.setAttribute("_CLIENT_FORWARDED_FOR_", request.getHeader("X-Forwarded-For")); session.setAttribute("_CLIENT_REMOTE_ADDR_", request.getRemoteAddr()); session.setAttribute("_CLIENT_REMOTE_HOST_", request.getRemoteHost()); session.setAttribute("_CLIENT_REMOTE_USER_", request.getRemoteUser()); }
From source file:org.openecomp.sdcrests.action.rest.services.ActionsImpl.java
public Response deleteArtifactInternal(String actionInvariantUuId, String artifactUuId, HttpServletRequest servletRequest) { Map<String, String> errorMap = validateRequestHeaders(servletRequest); Map<String, String> queryParamErrors = validateQueryParam(actionInvariantUuId); errorMap.putAll(queryParamErrors);//from w w w .ja va 2 s .c om queryParamErrors = validateQueryParam(artifactUuId); errorMap.putAll(queryParamErrors); if (errorMap.isEmpty()) { actionManager.deleteArtifact(actionInvariantUuId, artifactUuId, servletRequest.getRemoteUser()); } else { checkAndThrowError(errorMap); } return Response.ok().build(); }
From source file:alpha.portal.webapp.controller.CardFormController.java
/** * Save card./*from w ww.j av a 2 s .co m*/ * * @param jspCard * the jsp card * @param errors * the errors * @param request * the request * @param response * the response * @return the string * @throws Exception * the exception */ @RequestMapping(method = RequestMethod.POST, params = { "saveCard" }) public String saveCard(final AlphaCard jspCard, final BindingResult errors, final HttpServletRequest request, final HttpServletResponse response) throws Exception { AlphaCard alphaCard = null; AlphaCardIdentifier identifier = null; final Locale locale = request.getLocale(); if (!StringUtils.isBlank(jspCard.getAlphaCardIdentifier().getCardId())) { alphaCard = this.alphaCardManager.get(jspCard.getAlphaCardIdentifier()); identifier = alphaCard.getAlphaCardIdentifier(); final String cardId = identifier.getCardId(); final String caseId = identifier.getCaseId(); final Adornment contributor = alphaCard.getAlphaCardDescriptor() .getAdornment(AdornmentType.Contributor.getName()); if ((contributor.getValue() == null) || contributor.getValue().isEmpty()) { this.saveError(request, this.getText("adornment.noAccess", locale)); return "redirect:/caseform?activeCardId=" + cardId + "&caseId=" + caseId; } else { final Long contributorID = Long.parseLong(contributor.getValue()); final User currentUser = this.getUserManager().getUserByUsername(request.getRemoteUser()); if (contributorID != currentUser.getId()) { this.saveError(request, this.getText("adornment.noAccess", locale)); return "redirect:/caseform?activeCardId=" + cardId + "&caseId=" + caseId; } } /** * Check if card has been deleted */ final Adornment delAdornment = alphaCard.getAlphaCardDescriptor() .getAdornment(AdornmentType.Deleted.getName()); if (delAdornment != null) { final String delIsTrue = AdornmentTypeDeleted.TRUE.value(); if (delAdornment.getValue().equals(delIsTrue)) { this.saveError(request, this.getText("adornment.errorChange", locale)); return "redirect:/caseform?activeCardId=" + cardId + "&caseId=" + caseId; } } alphaCard.getAlphaCardDescriptor().setTitle(jspCard.getAlphaCardDescriptor().getTitle()); } else { alphaCard = this.alphaCardManager.createAlphaCard(jspCard.getAlphaCardIdentifier().getCaseId()); final User currentUser = this.userManager.getUserByUsername(request.getRemoteUser()); alphaCard.getAlphaCardDescriptor().setContributor(currentUser.getId()); for (final Adornment a : jspCard.getAlphaCardDescriptor().getAllAdornments()) { alphaCard.getAlphaCardDescriptor().setAdornment(a.getName(), a.getValue()); } identifier = alphaCard.getAlphaCardIdentifier(); final AlphaCase alphaCase = this.caseManager.get(identifier.getCaseId()); alphaCase.addAlphaCard(alphaCard); } alphaCard = this.alphaCardManager.save(alphaCard); this.saveMessage(request, this.getText("card.updated", locale)); return "redirect:/caseform?caseId=" + identifier.getCaseId() + "&activeCardId=" + identifier.getCardId(); }