List of usage examples for javax.servlet.http HttpServletRequest getRemoteHost
public String getRemoteHost();
From source file:org.kite9.diagram.server.AbstractKite9Controller.java
/** * Retrieves user info from cookie/*from w ww. ja va 2s .c o m*/ */ public User getUser(HttpServletRequest req) { if (isLocal()) { return LOCAL_USER; } Cookie[] cookies = req.getCookies(); String wpCookieName = null; String wpCookieValue = null; if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().startsWith("wordpress_logged_in")) { wpCookieName = cookie.getName(); wpCookieValue = cookie.getValue(); } } } final String ip = req.getRemoteAddr(); final String host = req.getRemoteHost(); System.out.println("Session : " + wpCookieName + " " + wpCookieValue); if (wpCookieName == null) { return NO_USER; } try { URL u = new URL(URL_ROOT + "/kite9_user_info"); URLConnection conn = u.openConnection(); conn.setRequestProperty("Cookie", wpCookieName + "=" + wpCookieValue); conn.connect(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line = br.readLine(); br.close(); if (line.contains("<none>")) { return NO_USER; } else { String parts[] = line.split(","); int id = Integer.parseInt(parts[1]); return new User(id, parts[0], false, ip, host); } } catch (IOException e) { throw new Kite9ProcessingException("Couldn't handle user log-in", e); } }
From source file:com.iLabs.spice.handler.LoginHandler.java
public String loginAction() throws IOException, ClassNotFoundException, SQLException { String result = "failure"; try {/* w w w . j a v a2 s .com*/ java.util.Date date = new java.util.Date(); System.out.println("The Start Time (1): " + new Timestamp(date.getTime())); ProfileBean ownerProfile = (ProfileBean) getSessionScope().get("ownerProfile"); ProfileBean currentProfile = (ProfileBean) getSessionScope().get("currentProfile"); if (ownerProfile == null) { ownerProfile = new ProfileBean(); } if (currentProfile == null) { currentProfile = new ProfileBean(); } IPerson person = (IPerson) ServiceLocator.getService("PersonSvc"); UserAuth authPerson = person.authenticateUser(currentProfile.getUserAuth().getUserName(), currentProfile.getUserAuth().getUserPassword()); //This condition checks if the authPerson returned from authentication service is null or not. //If the user who enters the site is an authenticated user, the user's info and his friends info is stored in //currentProfile as well as ownerProfile bean. if (authPerson != null && authPerson.getUserName() != null) { //Save the QoS Level of the user (Platinum, Gold or Silver) qoslevel = currentProfile.getUserAuth().getProfile().getProfileURL(); ClientResource clientResource = new ClientResource("http://192.168.1.41:8180/sessions"); Session session = new Session(); ConnectionParty owner = new ConnectionParty(); HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance() .getExternalContext().getRequest(); owner.setIp(request.getHeader("X-Forwarded-For")); owner.setPort(request.getRemotePort()); System.out.println("Client address: " + request.getRemoteAddr()); System.out.println("Client port: " + request.getRemotePort()); if (qoslevel.equalsIgnoreCase("GOLD")) { owner.setSip_uri("sip:alice@openepc.test"); session.setApplicationId("surveillance"); } else { if (qoslevel.equalsIgnoreCase("Silver")) { owner.setSip_uri("sip:bob@openepc.test"); session.setApplicationId("IMS"); } else { owner.setSip_uri("sip:charlie@openepc.test"); session.setApplicationId("YouTube"); } } System.out.println("REQUEST " + request.getRemoteAddr() + request.getRemoteHost() + request.getLocalPort() + request.getRequestURI()); System.out.println(request.getHeader("X-Forwarded-For")); ConnectionParty otherParty = new ConnectionParty(); otherParty.setIp("192.168.1.41"); otherParty.setPort(8080); otherParty.setSip_uri(""); session.setSessionOwner(owner); session.setSessionOtherParty(otherParty); ServiceInfo serviceInfo = new ServiceInfo(); //serviceInfo.setServiceId("Webcamstream"); setBandwidthAndPriority(serviceInfo, qoslevel); serviceInfo.setMediaType(MediaType.DATA); serviceInfo.setLifeTime(6000); session.setServiceInfo(serviceInfo); Representation response = clientResource.post(session); String resp = response.getText(); SI.setSessionID(resp.substring(70, 125)); System.out.println("200 OK RESPONSE IS: " + resp); String s = SI.getSessionID(); System.out.println("SESSION ID IS: " + s); UserFriends userFriends = person.getFriends(authPerson.getUserId()); ownerProfile.setUserAuth(authPerson); ownerProfile.setUserFriends(userFriends); currentProfile.setUserAuth(authPerson); currentProfile.setUserFriends(userFriends); getSessionScope().put("ownerProfile", ownerProfile); getSessionScope().put("currentProfile", currentProfile); DatabaseConnector r = new DatabaseConnector(); r.Write(s, authPerson.getUserId()); //authPerson.getProfile().setProfileURL(s); System.out.println("User " + authPerson.getProfile().getFirstName() + " " + authPerson.getProfile().getProfileURL()); System.out.println("The Start Time (3): " + new Timestamp(date.getTime())); result = "success"; } else { // if user is not an authenticate user, then error message is generated. FacesMessage message = new FacesMessage("Please Check Username and password"); FacesContext.getCurrentInstance().addMessage("login:user_password", message); } } catch (SysException e) { e.printStackTrace(); } return result; }
From source file:siddur.solidtrust.site.APIController.java
@RequestMapping(value = "/newprice") public @ResponseBody Object findCar(@RequestParam("id") String id, HttpServletRequest request) { AccessItem ai = new AccessItem(); ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.NEW_PRICE.getId()); ai.setRequest(id);/*from www .j a v a2 s . c om*/ Car car = carService.findCar(id); if (car == null) { ai.setStatus(0); ai.setResponse("Not found:" + id); } else { ai.setResponse(car.toString()); } free.save(ai); return car; }
From source file:it.jugpadova.util.JUGEventsExceptionResolver.java
@Override public ModelAndView resolveException(HttpServletRequest req, HttpServletResponse res, Object object, Exception e) {/*from w ww . j av a2s .c o m*/ try { if (e instanceof ParancoeAccessDeniedException) { return new ModelAndView("accessDenied", null); } if (e instanceof MaxUploadSizeExceededException) { return Utilities.getMessageView("upload.maximumSizeExceeded", Long.toString(multipartResolver.getFileUpload().getSizeMax())); } if (e instanceof RegistrationNotOpenException) { return Utilities.getMessageView("participant.registration.notOpen", ((RegistrationNotOpenException) e).getEvent().getTitle()); } if (e instanceof ConversationException) { return new ModelAndView("conversationException", null); } if (e instanceof HttpSessionRequiredException) { FlashHelper.setRedirectError(req, "objectNotFoundInSession"); return new ModelAndView("event/list", null); } if (!interceptedWithMinimalLogging(e)) { logger.error("Unexpected exception", e); } logger.info("Exception requesting URL: " + req.getRequestURL().toString()); logger.info(" request from " + req.getRemoteHost() + "(" + req.getRemoteAddr() + ")"); return super.resolveException(req, res, object, e); } catch (Exception ex) { logger.error("Error resolving exception", ex); } return new ModelAndView("redirect:/home/500page.html"); }
From source file:org.ejbca.core.protocol.ocsp.OCSPUnidExtension.java
/** Called by OCSP responder when the configured extension is found in the request. * // w w w .ja v a 2s .c o m * @param request HttpServletRequest that can be used to find out information about caller, TLS certificate etc. * @param cert X509Certificate the caller asked for in the OCSP request * @param status CertificateStatus the status the certificate has according to the OCSP responder, null means the cert is good * @return X509Extension that will be added to responseExtensions by OCSP responder, or null if an error occurs */ public Hashtable process(HttpServletRequest request, X509Certificate cert, CertificateStatus status) { if (m_log.isTraceEnabled()) { m_log.trace(">process()"); } // Check authorization first if (!checkAuthorization(request)) { errCode = OCSPUnidExtension.ERROR_UNAUTHORIZED; return null; } // If the certificate is revoked, we must not return an FNR if (status != null) { errCode = OCSPUnidExtension.ERROR_CERT_REVOKED; return null; } Connection con = null; PreparedStatement ps = null; ResultSet result = null; String fnr = null; String sn = null; try { // The Unis is in the DN component serialNumber sn = CertTools.getPartFromDN(cert.getSubjectDN().getName(), "SN"); if (sn != null) { if (m_log.isDebugEnabled()) { m_log.debug("Found serialNumber: " + sn); } String iMsg = intres.getLocalizedMessage("ocsp.receivedunidreq", request.getRemoteAddr(), request.getRemoteHost(), sn); m_log.info(iMsg); try { con = ServiceLocator.getInstance().getDataSource(dataSourceJndi).getConnection(); } catch (SQLException e) { String errMsg = intres.getLocalizedMessage("ocsp.errordatabaseunid"); m_log.error(errMsg, e); errCode = OCSPUnidExtension.ERROR_SERVICE_UNAVAILABLE; return null; } ps = con.prepareStatement("select fnr from UnidFnrMapping where unid=?"); ps.setString(1, sn); result = ps.executeQuery(); if (result.next()) { fnr = result.getString(1); } } else { String errMsg = intres.getLocalizedMessage("ocsp.errorunidnosnindn", cert.getSubjectDN().getName()); m_log.error(errMsg); errCode = OCSPUnidExtension.ERROR_NO_SERIAL_IN_DN; return null; } m_log.trace("<process()"); } catch (Exception e) { throw new EJBException(e); } finally { JDBCUtil.close(con, ps, result); } // Construct the response extentsion if we found a mapping if (fnr == null) { String errMsg = intres.getLocalizedMessage("ocsp.errorunidnosnmapping", sn); m_log.error(errMsg); errCode = OCSPUnidExtension.ERROR_NO_FNR_MAPPING; return null; } String errMsg = intres.getLocalizedMessage("ocsp.returnedunidresponse", request.getRemoteAddr(), request.getRemoteHost(), fnr, sn); m_log.info(errMsg); FnrFromUnidExtension ext = new FnrFromUnidExtension(fnr); Hashtable ret = new Hashtable(); ret.put(FnrFromUnidExtension.FnrFromUnidOid, new X509Extension(false, new DEROctetString(ext))); return ret; }
From source file:com.globalsight.dispatcher.controller.MTProfilesController.java
@RequestMapping(value = "/remove", method = RequestMethod.POST) public String remove(HttpServletRequest p_request, ModelMap p_model) throws JAXBException { String mtProfileIDStr = (String) p_request.getParameter("mtProfileID"); for (String mtProfileID : mtProfileIDStr.split(",")) { long id = Long.valueOf(mtProfileID); if (id < 0) continue; MTPLanguage mtpLang = DispatcherDAOFactory.getMTPLanguagesDAO().getFirstMTPLanguage(id); if (mtpLang != null) { p_model.addAttribute("error", "The MT Profile is used, please remove the assiciation with languages firstly."); return ""; }//w w w.jav a 2 s . co m MTP_DAO.deleteMTProfile(id); logger.info("Remove MTProfile:" + mtProfileID + " BY " + p_request.getRemoteHost()); } return "main.htm"; }
From source file:siddur.solidtrust.site.APIController.java
@RequestMapping(value = "/roadtax") @Transactional(readOnly = false)/*from w ww. ja v a 2 s . co m*/ public @ResponseBody String raodTax(@RequestParam("id") String id, HttpServletRequest request) { AccessItem ai = new AccessItem(); ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.ROADTAX.getId()); ai.setRequest(id); Car car = null; ; try { car = carService.findCar(id); } catch (Exception e) { ai.setStatus(-1); log4j.error(e.getMessage(), e); ai.setResponse(e.getMessage()); } String tax = null; if (car != null) { tax = car.getRoadTax(); ai.setResponse(tax); } else { ai.setResponse("no data"); ai.setStatus(0); } free.save(ai); return tax; }
From source file:siddur.solidtrust.site.APIController.java
@RequestMapping(value = "/rdw") public @ResponseBody Object findAzureCar(@RequestParam("id") String id, HttpServletRequest request) { AccessItem ai = new AccessItem(); ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.RDW.getId());/*from w w w. j a v a 2 s . com*/ ai.setRequest(id); Map<String, Object> carMap = null; if (!StringUtils.isEmpty(id)) { try { carMap = azureService.findEntityMapByLicensePlate(id); } catch (Exception e) { ai.setStatus(-1); log4j.error(e.getMessage(), e); ai.setResponse(e.getMessage()); } } if (carMap != null) { ai.setResponse("[bpm=" + carMap.get(AzureCarConstants.BPM) + "];" + "[brand=" + carMap.get(AzureCarConstants.MERK) + "];" + "[type=" + carMap.get(AzureCarConstants.HANDELSBENAMING) + "];" + "[arrangement=" + carMap.get(AzureCarConstants.INRICHTING) + "];"); } else { ai.setStatus(0); ai.setResponse(null); } free.save(ai); return carMap == null ? "no data" : carMap; }
From source file:siddur.solidtrust.site.APIController.java
@RequestMapping(value = "/roadtax2") @Transactional(readOnly = false)//from w ww. jav a 2 s . c o m public @ResponseBody Object raodTax2(@RequestParam("id") String id, HttpServletRequest request) { AccessItem ai = new AccessItem(); ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.ROADTAX.getId()); ai.setRequest(id); Car car = null; ; try { car = carService.findCar(id); } catch (Exception e) { ai.setStatus(-1); log4j.error(e.getMessage(), e); ai.setResponse(e.getMessage()); } String tax = null; if (car != null) { tax = car.getRoadTax(); ai.setResponse(tax); } else { ai.setResponse("no data"); ai.setStatus(0); } free.save(ai); Map<String, String> map = new HashMap<String, String>(); map.put("tax", tax); return map; }
From source file:siddur.solidtrust.site.APIController.java
@RequestMapping(value = "/rdw_status") public @ResponseBody Callable<Object> findRDWStatus(@RequestParam("id") final String id, HttpServletRequest request) { final AccessItem ai = new AccessItem(); ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.RDW_STATUS.getId()); ai.setRequest(id);//ww w . j a va 2 s .c o m return new Callable<Object>() { @Override public Object call() throws Exception { RDWStatus rdw = rdwService.findStatus(id); String result = null; if (rdw == null) { result = "no data"; ai.setResponse(result); ai.setStatus(0); free.save(ai); return result; } ai.setResponse(rdw.toString()); free.save(ai); return rdw; } }; }