List of usage examples for javax.servlet.http HttpServletRequest getRemoteAddr
public String getRemoteAddr();
From source file:fr.scc.elo.controller.PlayerController.java
@GET @Produces({ MediaType.TEXT_HTML }) @Path("/delete/{name}") public void deletePlayer(@Context HttpServletRequest http, @Context HttpServletResponse redirect, @PathParam("name") String name) throws IOException { if (connectionService.acceptIPDelete(http.getRemoteAddr())) { eloService.deletePlayer(Player.builder().name(name).build()); }/*from www .ja v a 2s. com*/ redirect.sendRedirect("/rest/v1/player/showall/html"); }
From source file:fr.scc.elo.controller.PlayerController.java
@GET @Produces({ MediaType.TEXT_HTML }) @Path("/create/{name}") public void createPlayer(@Context HttpServletRequest http, @Context HttpServletResponse redirect, @PathParam("name") String name) throws IOException { if (connectionService.acceptIPDelete(http.getRemoteAddr())) { eloService.createPlayer(name);/* ww w . ja v a 2 s . c om*/ } redirect.sendRedirect("/rest/v1/player/showall/html"); }
From source file:com.bluepandora.therap.donatelife.servlet.LifeService.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w .j a v a 2 s. c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JSONException { response.setContentType("text/html;charset=UTF-8"); Debug.debugLog("SERVICE SERVLET HITTED FROM : " + request.getRemoteAddr()); String requestName = request.getParameter("requestName"); try { if (requestName != null) { if (requestName.equals(Request.BLOOD_GROUP_LIST)) { DataService.getBloodGroupList(request, response); } else if (requestName.equals(Request.HOSPITAL_LIST)) { DataService.getHospitalList(request, response); } else if (requestName.equals(Request.DISTRICT_LIST)) { DataService.getDistrictList(request, response); } else if (requestName.equals(Request.GET_BLOOD_REQUEST)) { Debug.debugURL(request, response); DataService.getBloodRequestList(request, response); } else if (requestName.equals(Request.USER_INFO)) { DataService.getUserProfile(request, response); } else if (requestName.equals(Request.GET_DONATION_RECORD)) { DataService.getUserDonationRecord(request, response); } else if (requestName.equals(Request.REGISTER)) { UserRegistrationService.registerUser(request, response); } else if (requestName.equals(Request.FEEDBACK)) { FeedBackService.addFeedback(request, response); } else if (requestName.equals(Request.GCM_UPDATE)) { GcmProfileService.updateGCMKey(request, response); } else if (requestName.equals(Request.IS_REGISTER)) { UserRegistrationService.userRegistrationCheck(request, response); } else if (requestName.equals(Request.ADD_BLOOD_REQUEST)) { BloodRequestService.addBloodRequest(request, response); } else if (requestName.equals(Request.REMOVE_TRACKER)) { BloodRequestService.removePersonBloodRequestTracker(request, response); } else if (requestName.equals(Request.ADD_DONATION_RECORD)) { DonationService.addDonationRecord(request, response); } else if (requestName.equals(Request.REMOVE_DONATION_RECORD)) { DonationService.removeDonationRecord(request, response); } else if (requestName.equals(Request.DELETE_BLOOD_REQUET_IN_KEY)) { BloodRequestService.removeBloodRequest(request, response); } else if (requestName.equals(Request.UPDATE_USER_INFO)) { UserRegistrationService.updateUserPersonalInfo(request, response); } else if (requestName.equals(Request.FIND_DONATOR_MOBILE_NUMBER)) { DataService.getDonatorMobileNumber(request, response); } else { Debug.debugLog("REQUEST NAME NOT MATCHED!"); Debug.debugURL(request, response); DataService.unknownHit(request, response); } } else { Debug.debugLog("NO REQUEST NAME FOUND!"); Debug.debugURL(request, response); DataService.unknownHit(request, response); } } catch (Exception error) { Debug.debugURL(request, response); JSONObject jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, "PROBLEM ARISE WITH YOUR REQUEST IN SERVLET!"); SendJsonData.sendJsonData(request, response, jsonObject); } }
From source file:jeeves.server.sources.ServiceRequestFactory.java
/** Builds the request with data supplied by tomcat. * A request is in the form: srv/<language>/<service>[!]<parameters> *///from w w w. ja v a2 s . c o m public static ServiceRequest create(HttpServletRequest req, HttpServletResponse res, String uploadDir, int maxUploadSize) throws Exception { String url = req.getPathInfo(); // FIXME: if request character encoding is undefined set it to UTF-8 String encoding = req.getCharacterEncoding(); try { // verify that encoding is valid Charset.forName(encoding); } catch (Exception e) { encoding = null; } if (encoding == null) { try { req.setCharacterEncoding(Jeeves.ENCODING); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } } //--- extract basic info HttpServiceRequest srvReq = new HttpServiceRequest(res); srvReq.setDebug(extractDebug(url)); srvReq.setLanguage(extractLanguage(url)); srvReq.setService(extractService(url)); srvReq.setJSONOutput(extractJSONFlag(url)); String ip = req.getRemoteAddr(); String forwardedFor = req.getHeader("x-forwarded-for"); if (forwardedFor != null) ip = forwardedFor; srvReq.setAddress(ip); srvReq.setOutputStream(res.getOutputStream()); //--- discover the input/output methods String accept = req.getHeader("Accept"); if (accept != null) { int soapNDX = accept.indexOf("application/soap+xml"); int xmlNDX = accept.indexOf("application/xml"); int htmlNDX = accept.indexOf("html"); if (soapNDX != -1) srvReq.setOutputMethod(OutputMethod.SOAP); else if (xmlNDX != -1 && htmlNDX == -1) srvReq.setOutputMethod(OutputMethod.XML); } if ("POST".equals(req.getMethod())) { srvReq.setInputMethod(InputMethod.POST); String contType = req.getContentType(); if (contType != null) { if (contType.indexOf("application/soap+xml") != -1) { srvReq.setInputMethod(InputMethod.SOAP); srvReq.setOutputMethod(OutputMethod.SOAP); } else if (contType.indexOf("application/xml") != -1 || contType.indexOf("text/xml") != -1) srvReq.setInputMethod(InputMethod.XML); } } //--- retrieve input parameters InputMethod input = srvReq.getInputMethod(); if ((input == InputMethod.XML) || (input == InputMethod.SOAP)) { if (req.getMethod().equals("GET")) srvReq.setParams(extractParameters(req, uploadDir, maxUploadSize)); else srvReq.setParams(extractXmlParameters(req)); } else { //--- GET or POST srvReq.setParams(extractParameters(req, uploadDir, maxUploadSize)); } srvReq.setHeaders(extractHeaders(req)); return srvReq; }
From source file:in.mycp.controller.LoginController.java
@RequestMapping(produces = "text/html") public String main(HttpServletRequest req, HttpServletResponse resp) { logger.info("login " + req.getQueryString() + " {}{}{} " + req.getRequestURL() + " {}{}{} " + req.getRemoteAddr()); //HttpSession s = req.getSession(true); return "mycplogin"; }
From source file:com.qut.middleware.spep.authn.bindings.impl.AuthnPostBindingImpl.java
private void handleAuthnResponse(HttpServletRequest request, HttpServletResponse response, AuthnProcessorData data, SPEP spep) throws AuthenticationException { String remoteAddress = request.getRemoteAddr(); this.logger.debug("[Authn for {}] Going to process authentication response.", remoteAddress); String base64SAMLDocument = request.getParameter("SAMLResponse"); if (base64SAMLDocument == null || base64SAMLDocument.length() == 0) { throw new AuthenticationException( "SAMLResponse request parameter was null. Unable to process response."); }//from w w w . j a va2 s . c om byte[] samlDocument; try { samlDocument = Base64.decodeBase64(base64SAMLDocument.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new AuthenticationException( "Unable to complete authentication because a required character encoding is not supported.", e); } // Use the AuthnProcessor to unmarshal the response document. Response responseObject = spep.getAuthnProcessor().unmarshalResponse(samlDocument); this.logger.info( "[Authn for {}] Got an authentication response, going to process. Response ID: {} InResponseTo: {}", new Object[] { remoteAddress, responseObject.getID(), responseObject.getInResponseTo() }); spep.getAuthnProcessor().processAuthnResponse(data, responseObject); String sessionID = data.getSessionID(); if (sessionID == null) { throw new AuthenticationException( "Session identifier from AuthnProcessor was null. Unable to process SSO event"); } Cookie cookie = new Cookie(spep.getTokenName(), sessionID); cookie.setPath("/"); response.addCookie(cookie); try { String redirectURL = null; String base64RequestURL = data.getRequestURL(); if (base64RequestURL != null) { redirectURL = new String(Base64.decodeBase64(base64RequestURL.getBytes())); } else { redirectURL = spep.getDefaultUrl(); } this.logger.info( "[Authn for {}] Processed response ID: {} .. Created local session with session ID: {} Redirecting user to requested content: {}", new Object[] { remoteAddress, responseObject.getID(), sessionID, redirectURL }); response.sendRedirect(redirectURL); } catch (IOException e) { throw new AuthenticationException( "Unable to send redirect back to authenticated content as an I/O error occurred", e); } }
From source file:com.qut.middleware.spep.authn.bindings.impl.AuthnPostBindingImpl.java
private String buildAuthnRequestDocument(String requestedURL, HttpServletRequest request, HttpServletResponse response, AuthnProcessorData data, SPEP spep) throws AuthenticationException { String remoteAddress = request.getRemoteAddr(); this.logger.debug("[Authn for {}] Going to build AuthnRequest for new unauthenticated session.", remoteAddress);/*from www . j av a2s .c om*/ byte[] samlRequestEncoded; /* Base64 strings do not have spaces in them. So if one does, it means * that something strange has happened to make the servlet engine translate * the plus symbols into spaces. We just need to translate them back. */ requestedURL = requestedURL.replace(' ', '+'); data.setRequestURL(requestedURL); this.logger.debug("[Authn for {}] Requested URL was: {}", remoteAddress, requestedURL); String ssoURL; try { MetadataProcessor metadataProcessor = spep.getMetadataProcessor(); IdentityProviderRole identityProviderRole; if (spep.enableCompatibility()) { identityProviderRole = metadataProcessor.getEntityRoleData(spep.getTrustedESOEIdentifier(), IdentityProviderRole.class); } else { identityProviderRole = metadataProcessor.getEntityRoleData(spep.getTrustedESOEIdentifier(), TrustedESOERole.class); } if (identityProviderRole == null) { throw new AuthenticationException("No ESOE entry in metadata. Unable to process authentication"); } ssoURL = identityProviderRole.getSingleSignOnService(this.getBindingIdentifier()); data.setDestinationURL(ssoURL); } catch (MetadataStateException e) { throw new AuthenticationException( "Authentication could not be completed because the metadata state is invalid. Exception was: " + e.getMessage(), e); } AuthnRequest authnRequest = spep.getAuthnProcessor().generateAuthnRequest(data); this.logger.debug("[Authn for {}] Created AuthnRequest, going to marshal", remoteAddress); byte[] requestDocument = spep.getAuthnProcessor().marshalRequestToBytes(authnRequest); this.logger.info("[Authn for {}] Marshalled AuthnRequest successfully. Destination URL: {} ID: {}", new Object[] { remoteAddress, ssoURL, authnRequest.getID() }); samlRequestEncoded = Base64.encodeBase64(requestDocument); String base64SAMLDocument = new String(samlRequestEncoded); String document = this.samlMessageFormat.format(new Object[] { ssoURL, base64SAMLDocument }); this.logger.debug("[Authn for {}] Created HTTP POST document successfully", remoteAddress); return document; }
From source file:com.rockagen.gnext.service.spring.security.extension.BasicWebAuthenticationDetails.java
/** * Get the real Address// ww w. j a va 2s.c om * * @param request * @return * @throws Exception */ protected String getRealAddr(final HttpServletRequest request) { String customerIp = ""; // If proxies by nginx apache ... String temp1 = request.getHeader("X-Real-IP"); if (!CommUtil.isBlank(temp1)) { customerIp = temp1; } else { // use default customerIp = request.getRemoteAddr(); } return customerIp; }
From source file:net.nan21.dnet.core.web.controller.session.SessionController.java
/** * Pack extra information about login into a ThreadLocal to be passed to the * authentication-provider service//from w ww .j a v a 2s . c om * * @param clientCode * @param language * @param request */ private void prepareLoginParamsHolder(String clientCode, String language, HttpServletRequest request) { LoginParams lp = new LoginParams(); lp.setRemoteIp(request.getRemoteAddr()); lp.setUserAgent(request.getHeader("User-Agent")); lp.setRemoteHost(request.getRemoteHost()); lp.setLanguage(language); lp.setClientCode(clientCode); LoginParamsHolder.params.set(lp); }
From source file:com.scooterframework.web.controller.ScooterRequestFilter.java
protected boolean isLocalRequest(HttpServletRequest request) { String requestURL = request.getRequestURL().toString(); String remoteAddr = request.getRemoteAddr(); String remoteHost = request.getRemoteHost(); if (requestURL.startsWith(Constants.LOCAL_HOST_URL_PREFIX_1) || requestURL.startsWith(Constants.LOCAL_HOST_URL_PREFIX_2) || requestURL.startsWith(Constants.LOCAL_HOST_URL_PREFIX_3) || requestURL.startsWith(Constants.LOCAL_HOST_URL_PREFIX_4) || remoteAddr.equals(Constants.LOCAL_HOST_REMOTE_ADDRESS) || remoteHost.equals(Constants.LOCAL_HOST_REMOTE_HOST_1) || remoteHost.equals(Constants.LOCAL_HOST_REMOTE_HOST_2)) { return true; }//from www .j a v a 2 s .com return false; }