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.eclipse.orion.server.configurator.servlet.AuthorizedUserFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String remoteUser = httpRequest.getRemoteUser(); String userName = remoteUser; if (userName == null) { userName = authenticationService.getAuthenticatedUser(httpRequest, httpResponse, authProperties); if (userName == null) userName = IAuthenticationService.ANONYMOUS_LOGIN_VALUE; }//from ww w.j a v a 2 s. c o m try { String requestPath = httpRequest.getServletPath() + (httpRequest.getPathInfo() == null ? "" : httpRequest.getPathInfo()); if (!AuthorizationService.checkRights(userName, requestPath, httpRequest.getMethod())) { if (IAuthenticationService.ANONYMOUS_LOGIN_VALUE.equals(userName)) { userName = authenticationService.authenticateUser(httpRequest, httpResponse, authProperties); if (userName == null) return; } else { setNotAuthorized(httpRequest, httpResponse, requestPath); return; } } String xCreateOptions = httpRequest.getHeader("X-Create-Options"); if (xCreateOptions != null) { String sourceLocation = null; ; try { String method = xCreateOptions.contains("move") ? "POST" : "GET"; JSONObject requestObject = OrionServlet.readJSONRequest(httpRequest); sourceLocation = requestObject.getString("Location"); String normalizedLocation = new URI(sourceLocation).normalize().getPath(); normalizedLocation = normalizedLocation.startsWith(httpRequest.getContextPath()) ? normalizedLocation.substring(httpRequest.getContextPath().length()) : null; if (normalizedLocation == null || !AuthorizationService.checkRights(userName, normalizedLocation, method)) { setNotAuthorized(httpRequest, httpResponse, sourceLocation); return; } } catch (URISyntaxException e) { setNotAuthorized(httpRequest, httpResponse, sourceLocation); return; } catch (JSONException e) { // ignore, and fall through } } if (remoteUser == null && !IAuthenticationService.ANONYMOUS_LOGIN_VALUE.equals(userName)) { request.setAttribute(HttpContext.REMOTE_USER, userName); request.setAttribute(HttpContext.AUTHENTICATION_TYPE, authenticationService.getAuthType()); } } catch (CoreException e) { httpResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } chain.doFilter(request, response); }
From source file:org.eurekaclinical.user.webapp.servlet.filter.UserFilter.java
@Override public void doFilter(ServletRequest inRequest, ServletResponse inResponse, FilterChain inFilterChain) throws IOException, ServletException { HttpServletRequest servletRequest = (HttpServletRequest) inRequest; HttpServletResponse servletResponse = (HttpServletResponse) inResponse; String remoteUser = servletRequest.getRemoteUser(); inRequest.setAttribute(RequestAttributes.Eureka_Webapp_URL, this.properties.getEurekaWebappUrl()); inRequest.setAttribute(RequestAttributes.Eureka_Services_URL, this.properties.getEurekaServicesUrl()); if (!StringUtils.isEmpty(remoteUser)) { try {// w ww . ja v a 2 s . c om HttpSession session = servletRequest.getSession(false); if (session != null) { User user = this.servicesClient.getMe(); if (!user.isActive()) { session.invalidate(); sendForbiddenError(servletResponse, servletRequest, true); } else { inRequest.setAttribute(RequestAttributes.USER, user); inRequest.setAttribute(RequestAttributes.USER_IS_ACTIVATED, user.isActive()); inFilterChain.doFilter(inRequest, inResponse); } } else { goHome(servletRequest, servletResponse); } } catch (ClientException ex) { if (null != ex.getResponseStatus()) { switch (ex.getResponseStatus()) { case FORBIDDEN: { HttpSession session = servletRequest.getSession(false); if (session != null) { session.invalidate(); } sendForbiddenError(servletResponse, servletRequest, false); break; } case UNAUTHORIZED: { HttpSession session = servletRequest.getSession(false); if (session != null) { session.invalidate(); } goHome(servletRequest, servletResponse); break; } default: throw new ServletException("Error getting user " + servletRequest.getRemoteUser(), ex); } } } } else { inFilterChain.doFilter(inRequest, inResponse); } }
From source file:org.jboss.datavirt.commons.ui.header.DataVirtHeaderDataJS.java
/** * Gets the remote user, handles null.//from ww w . j a va2 s. c o m * @param request */ private String getRemoteUser(HttpServletRequest request) { return request.getRemoteUser() == null ? "<anonymous>" : request.getRemoteUser(); }
From source file:org.apache.hadoop.yarn.logaggregation.TestAggregatedLogsBlock.java
private AggregatedLogsBlockForTest getAggregatedLogsBlockForTest(Configuration configuration, String user, String containerId, String nodeName) { HttpServletRequest request = mock(HttpServletRequest.class); when(request.getRemoteUser()).thenReturn(user); AggregatedLogsBlockForTest aggregatedBlock = new AggregatedLogsBlockForTest(configuration); aggregatedBlock.setRequest(request); aggregatedBlock.moreParams().put(YarnWebParams.CONTAINER_ID, containerId); aggregatedBlock.moreParams().put(YarnWebParams.NM_NODENAME, nodeName); aggregatedBlock.moreParams().put(YarnWebParams.APP_OWNER, user); aggregatedBlock.moreParams().put("start", ""); aggregatedBlock.moreParams().put("end", ""); aggregatedBlock.moreParams().put(YarnWebParams.ENTITY_STRING, "entity"); return aggregatedBlock; }
From source file:AuthenticationSnoop.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<HTML><BODY>"); out.println("<H1>This is a password protected resource</H1>"); out.println("<PRE>"); out.println("User Name: " + req.getRemoteUser()); String name = (req.getUserPrincipal() == null) ? null : req.getUserPrincipal().getName(); out.println("Principal Name: " + name); out.println("Authentication Type: " + req.getAuthType()); out.println("Is a Manager: " + req.isUserInRole("manager")); out.println("</PRE>"); out.println("</BODY></HTML>"); }
From source file:edu.emory.cci.aiw.cvrg.eureka.servlet.filter.UserFilter.java
@Override public void doFilter(ServletRequest inRequest, ServletResponse inResponse, FilterChain inFilterChain) throws IOException, ServletException { HttpServletRequest servletRequest = (HttpServletRequest) inRequest; HttpServletResponse servletResponse = (HttpServletResponse) inResponse; String remoteUser = servletRequest.getRemoteUser(); inRequest.setAttribute(RequestAttributes.User_Webapp_URL, this.properties.getUserWebappUrl()); inRequest.setAttribute(RequestAttributes.User_Service_URL, this.properties.getUserServiceUrl()); Boolean userIsActive = true;//from w w w . j av a 2 s . c o m if (!StringUtils.isEmpty(remoteUser)) { try { HttpSession session = servletRequest.getSession(false); if (session != null) { User user = this.inUserClient.getMe(); userIsActive = this.inUserClient.getMe().isActive(); if (!userIsActive) { session.invalidate(); sendForbiddenError(servletResponse, servletRequest, true); } else { inRequest.setAttribute(RequestAttributes.USER, user); inRequest.setAttribute(RequestAttributes.USER_IS_ACTIVATED, userIsActive); inFilterChain.doFilter(inRequest, inResponse); } } else { goHome(servletRequest, servletResponse); } } catch (ClientException ex) { if (null != ex.getResponseStatus()) { switch (ex.getResponseStatus()) { case FORBIDDEN: { HttpSession session = servletRequest.getSession(false); if (session != null) { session.invalidate(); } sendForbiddenError(servletResponse, servletRequest, false); break; } case UNAUTHORIZED: { HttpSession session = servletRequest.getSession(false); if (session != null) { session.invalidate(); } goHome(servletRequest, servletResponse); break; } default: throw new ServletException("Error getting user " + servletRequest.getRemoteUser(), ex); } } } } else { inFilterChain.doFilter(inRequest, inResponse); } }
From source file:org.kuali.rice.kcb.web.spring.UserPreferencesController.java
/** * displayDelivererConfigurationForm - obtain information necessary * for displaying all possible Deliverer types and forward to the form * @param request// ww w. j a v a2s .co m * @param response * @return * @throws ServletException * @throws IOException */ public ModelAndView displayDelivererConfigurationForm(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userid = request.getRemoteUser(); LOG.debug("remoteUser: " + userid); // Get DeliveryType classes Collection<MessageDeliverer> deliveryTypes = this.messageDelivererRegistryService.getAllDeliverers(); // get all channels Collection<String> channels = getAllChannels(); // get all user preferences in a HashMap HashMap<String, String> preferences = this.recipientPreferenceService.getRecipientPreferences(userid); // get existing configured deliverers Collection<RecipientDelivererConfig> currentDeliverers = this.recipientPreferenceService .getDeliverersForRecipient(userid); // create a Map as an easy way for the JSP to determine whether a deliver is enabled for channels Map<String, Boolean> currentDeliverersMap = new HashMap<String, Boolean>(); for (RecipientDelivererConfig udc : currentDeliverers) { String channelName = udc.getChannel(); currentDeliverersMap.put(udc.getDelivererName() + "." + channelName, Boolean.TRUE); } Map<String, Object> model = new HashMap<String, Object>(); model.put("channels", channels); model.put("deliveryTypes", deliveryTypes); model.put("preferences", preferences); model.put("currentDeliverersMap", currentDeliverersMap); putBackLocation(model, request.getParameter("backLocation")); return new ModelAndView(VIEW, model); }
From source file:org.apereo.portal.rest.MarketplaceRESTController.java
@RequestMapping(value = "/marketplace/{fname}/getRating", method = RequestMethod.GET) public ModelAndView getUserRating(HttpServletRequest request, @PathVariable String fname) { Validate.notNull(fname, "Please supply a portlet to get rating for - should not be null"); IMarketplaceRating tempRating = marketplaceRatingDAO.getRating(request.getRemoteUser(), marketplaceService.getOrCreateMarketplacePortletDefinitionIfTheFnameExists(fname)); if (tempRating != null) { return new ModelAndView("json", "rating", new MarketplaceEntryRating(tempRating.getRating(), tempRating.getReview())); }/* w w w . j a va 2 s . com*/ return new ModelAndView("json", "rating", null); }
From source file:com.boyuanitsm.fort.web.rest.AccountResource.java
/** * GET /authenticate : check if the user is authenticated, and return its login. * * @param request the HTTP request//from ww w. j ava 2s. c o m * @return the login if the user is authenticated */ @RequestMapping(value = "/authenticate", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public String isAuthenticated(HttpServletRequest request) { log.debug("REST request to check if the current user is authenticated"); return request.getRemoteUser(); }