List of usage examples for javax.servlet.http HttpServletRequest getRemoteAddr
public String getRemoteAddr();
From source file:edu.northwestern.bioinformatics.studycalendar.grid.AuditInfoRequestHandler.java
public void invoke(MessageContext context) throws AxisFault { HttpServletRequest request = (HttpServletRequest) context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); String identity = SecurityManager.getManager().getCaller(); if (identity == null) { identity = "ANONYMOUS"; }/* w ww .java 2 s. c om*/ logger.debug("Auditing request from " + identity); String info = null; // try { // info = context.getCurrentMessage().getSOAPEnvelope().getAsString(); // } catch (Exception ex) { // logger.error("Error serializing message to string: " + ex.getMessage(), ex); // } info = request.getRequestURI(); DataAuditInfo.setLocal(new DataAuditInfo(identity, request.getRemoteAddr(), new Date(), info)); }
From source file:com.ebay.pulsar.analytics.resources.PulsarQueryResource.java
@POST @Path("realtime") @Consumes(MediaType.APPLICATION_JSON)// www . j a v a 2 s . com @Produces(MediaType.APPLICATION_JSON) public Response realtime(@Context HttpServletRequest request, RealtimeRequest req) { if (logger.isDebugEnabled()) { logger.debug("Realtime API called from IP: " + request.getRemoteAddr()); } req.setNamespace(RequestNameSpace.realtime); boolean trace = request.getParameter("debug") == null ? false : true; return processRequest(req, trace); }
From source file:org.slc.sli.dashboard.security.SLIAuthenticationEntryPoint.java
private void completeAuthentication(HttpServletRequest request, HttpServletResponse response, HttpSession session, Object token, boolean cookieFound) throws ServletException, IOException { // Complete Spring security integration SLIPrincipal principal = completeSpringAuthentication((String) token); LOG.info(LOG_MESSAGE_AUTH_COMPLETED, new Object[] { principal.getName(), request.getRemoteAddr() }); // Save the cookie to support sessions across multiple dashboard servers saveCookieWithToken(request, response, (String) token); // AJAX calls OR cookie sessions should not redirect if (isAjaxRequest(request) || cookieFound) { RequestDispatcher dispatcher = request.getRequestDispatcher(request.getServletPath()); dispatcher.forward(request, response); } else {/*from ww w. j av a 2s . c o m*/ LOG.info(LOG_MESSAGE_AUTH_REDIRECTING, new Object[] { principal.getName(), request.getRemoteAddr() }); response.sendRedirect(request.getRequestURI()); } }
From source file:br.org.indt.ndg.servlets.GetClient.java
private void createTransactionLogVO(HttpServletRequest request) throws MSMApplicationException { TransactionLogVO t = new TransactionLogVO(); t.setTransmissionMode(TransactionLogVO.MODE_HTTP); t.setAddress(request.getRemoteAddr()); t.setTransactionType(TransactionLogVO.DOWNLOAD_CLIENT); t.setUser(imeiVo.getUserName());// w ww . j ava2 s .c o m t.setStatus(SUCCESS); t.setDtLog(new Timestamp(System.currentTimeMillis())); t.setImei(imeiVo.getImei()); msmBD.logTransaction(t); }
From source file:com.liferay.portal.action.LogoutAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception { try {/*from ww w. j a va2s. c o m*/ HttpSession ses = req.getSession(); try { // Logger.info(this, "User " + // PortalUtil.getUser(req).getFullName() + " (" + // PortalUtil.getUser(req).getUserId() + // ") has logged out from IP: " + req.getRemoteAddr()); SecurityLogger.logInfo(this.getClass(), "User " + PortalUtil.getUser(req).getFullName() + " (" + PortalUtil.getUser(req).getUserId() + ") has logged out from IP: " + req.getRemoteAddr()); } catch (Exception e) { //Logger.info(this, "User has logged out from IP: " + req.getRemoteAddr()); SecurityLogger.logInfo(this.getClass(), "User has logged out from IP: " + req.getRemoteAddr()); } EventsProcessor.process(PropsUtil.getArray(PropsUtil.LOGOUT_EVENTS_PRE), req, res); ArrayList<Cookie> al = new ArrayList<Cookie>(); Cookie[] cookies = req.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; al.add(cookie); cookie.setMaxAge(0); cookie.setPath("/"); res.addCookie(cookie); } } Map sessions = PortletSessionPool.remove(ses.getId()); if (sessions != null) { Iterator itr = sessions.entrySet().iterator(); while (itr.hasNext()) { Map.Entry entry = (Map.Entry) itr.next(); HttpSession portletSession = (HttpSession) entry.getValue(); portletSession.invalidate(); } } try { ses.invalidate(); } catch (Exception e) { } EventsProcessor.process(PropsUtil.getArray(PropsUtil.LOGOUT_EVENTS_POST), req, res); // ActionForward af = mapping.findForward("referer"); // return af; return mapping.findForward(Constants.COMMON_REFERER); } catch (Exception e) { req.setAttribute(PageContext.EXCEPTION, e); return mapping.findForward(Constants.COMMON_REFERER); } }
From source file:br.org.indt.ndg.servlets.DownloadClient.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.info("Started processing stream from " + request.getRemoteAddr()); log.info("User: " + request.getParameter("user")); InputStreamReader dis = new InputStreamReader(request.getInputStream(), "UTF-8"); DataOutputStream dos = new DataOutputStream(response.getOutputStream()); if (dis != null) { BufferedReader reader = new BufferedReader(dis); StringBuffer tempBuffer = new StringBuffer(); String line = null;/* w ww . j a v a2 s. c o m*/ if (validateUser(request.getParameter("user"), request.getParameter("psw"))) { while ((line = reader.readLine()) != null) { tempBuffer.append(line + '\n'); log.info(line); } try { msmBD.postSurvey(request.getParameter("user"), tempBuffer, createTransactionLogVO(request), false); dos.writeBytes(SUCCESS); } catch (MSMApplicationException e) { dos.writeBytes(FAILURE); e.printStackTrace(); } catch (MSMSystemException e) { dos.writeBytes(FAILURE); e.printStackTrace(); } } else { dos.writeBytes(USERINVALID); log.info("User invalid, returning " + USERINVALID + " to " + request.getRemoteAddr()); } reader.close(); dos.close(); } else { dos.writeBytes(FAILURE); log.info("Failed processing stream from " + request.getRemoteAddr()); } }
From source file:org.jamwiki.servlets.ImportTiddlyWikiServlet.java
/** * *///from w ww .ja va 2 s. c o m private void importFile(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception { String virtualWiki = WikiUtil.getVirtualWikiFromURI(request); Iterator iterator = ServletUtil.processMultipartRequest(request); WikiUser user = WikiUtil.currentUser(); if (!user.hasRole(Role.ROLE_USER)) { // FIXME - setting the user to null may not be necessary, but it is // consistent with how the code behaved when WikiUtil.currentUser() // returned null for non-logged-in users user = null; } TiddlyWikiParser parser = new TiddlyWikiParser(virtualWiki, user, request.getRemoteAddr()); String topicName = null; while (iterator.hasNext()) { FileItem item = (FileItem) iterator.next(); if (item.isFormField()) { continue; } File xmlFile = saveFileItem(item); topicName = parser.parse(xmlFile); xmlFile.delete(); } if (!StringUtils.isBlank(topicName)) { ServletUtil.redirect(next, virtualWiki, topicName); } else { next.addObject("error", new WikiMessage("import.caption.failure")); view(request, next, pageInfo); } }
From source file:gov.nih.nci.cabig.caaers.grid.AuditInfoRequestHandler.java
public void invoke(final MessageContext context) throws AxisFault { HttpServletRequest request = (HttpServletRequest) context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); String identity = SecurityManager.getManager().getCaller(); if (identity == null) { identity = "ANONYMOUS"; }//from w ww . j a v a2 s .c o m logger.debug("Auditing request from " + identity); String info = null; // try { // info = context.getCurrentMessage().getSOAPEnvelope().getAsString(); // } catch (Exception ex) { // logger.error("Error serializing message to string: " + ex.getMessage(), ex); // } info = request.getRequestURI(); gov.nih.nci.cabig.ctms.audit.domain.DataAuditInfo .setLocal(new DataAuditInfo(identity, request.getRemoteAddr(), new Date(), info)); }
From source file:org.apache.hadoop.gateway.AuditLoggingTest.java
@Test /**//from www .j a va 2 s . co m * Empty filter chain. Two events with same correlation ID are expected: * * action=access request_type=uri outcome=unavailable * action=access request_type=uri outcome=success message=Response status: 404 */ public void testNoFiltersAudit() throws ServletException, IOException { FilterConfig config = EasyMock.createNiceMock(FilterConfig.class); EasyMock.replay(config); HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); ServletContext context = EasyMock.createNiceMock(ServletContext.class); GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class); EasyMock.expect(request.getMethod()).andReturn(METHOD).anyTimes(); EasyMock.expect(request.getPathInfo()).andReturn(PATH).anyTimes(); EasyMock.expect(request.getContextPath()).andReturn(CONTEXT_PATH).anyTimes(); EasyMock.expect(request.getRemoteAddr()).andReturn(ADDRESS).anyTimes(); EasyMock.expect(request.getRemoteHost()).andReturn(HOST).anyTimes(); EasyMock.expect(request.getServletContext()).andReturn(context).anyTimes(); EasyMock.expect(context.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE)).andReturn(gatewayConfig) .anyTimes(); EasyMock.expect(gatewayConfig.getHeaderNameForRemoteAddress()).andReturn("Custom-Forwarded-For").anyTimes(); EasyMock.replay(request); EasyMock.replay(context); EasyMock.replay(gatewayConfig); HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); EasyMock.replay(response); FilterChain chain = EasyMock.createNiceMock(FilterChain.class); EasyMock.replay(chain); GatewayFilter gateway = new GatewayFilter(); gateway.init(config); gateway.doFilter(request, response, chain); gateway.destroy(); assertThat(CollectAppender.queue.size(), is(1)); Iterator<LoggingEvent> iterator = CollectAppender.queue.iterator(); LoggingEvent accessEvent = iterator.next(); verifyAuditEvent(accessEvent, CONTEXT_PATH + PATH, ResourceType.URI, Action.ACCESS, ActionOutcome.UNAVAILABLE, null, "Request method: GET"); }
From source file:com.ebay.pulsar.analytics.resources.PulsarQueryResource.java
@POST @Path("yesterday") @Consumes(MediaType.APPLICATION_JSON)// w w w . j av a2s .c om @Produces(MediaType.APPLICATION_JSON) public Response yesterday(@Context HttpServletRequest request, CoreRequest req) { if (logger.isDebugEnabled()) { logger.debug("Yesterday API called from IP: " + request.getRemoteAddr()); } req.setNamespace(RequestNameSpace.yesterday); req.setGranularity("fifteen_minute"); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("MST")); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); Date end = new Date(c.getTimeInMillis()); c.add(Calendar.DATE, -1); Date start = new Date(c.getTimeInMillis()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); dateFormat.setTimeZone(TimeZone.getTimeZone("MST")); req.setStartTime(dateFormat.format(start)); req.setEndTime(dateFormat.format(end)); boolean trace = request.getParameter("debug") == null ? false : true; return processRequest(req, trace); }