List of usage examples for javax.servlet.http HttpServletRequest getServerName
public String getServerName();
From source file:cz.fi.muni.xkremser.editor.server.AuthenticationServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { HttpSession session = req.getSession(true); String url = (String) session.getAttribute(HttpCookies.TARGET_URL); String root = (URLS.LOCALHOST() ? "http://" : "https://") + req.getServerName() + (URLS.LOCALHOST() ? (req.getServerPort() == 80 || req.getServerPort() == 443 ? "" : (":" + req.getServerPort())) : "") + URLS.ROOT() + (URLS.LOCALHOST() ? "?gwt.codesvr=127.0.0.1:9997" : ""); String authHeader = req.getHeader("Authorization"); if (authHeader != null) { String decodedHeader = decode(req, authHeader); String pass = configuration.getHttpBasicPass(); if (pass == null || "".equals(pass.trim()) || pass.length() < 4) { requrireAuthentication(resp); }//from w w w. ja v a 2 s .c o m if (decodedHeader.equals(ALLOWED_PREFIX + pass)) { session.setAttribute(HttpCookies.TARGET_URL, null); session.setAttribute(HttpCookies.SESSION_ID_KEY, "https://www.google.com/profiles/109255519115168093543"); session.setAttribute(HttpCookies.NAME_KEY, "admin"); session.setAttribute(HttpCookies.ADMIN, HttpCookies.ADMIN_YES); ACCESS_LOGGER.info("LOG IN: [" + FORMATTER.format(new Date()) + "] User " + decodedHeader.substring(0, decodedHeader.indexOf(":")) + " with openID BASIC_AUTH and IP " + req.getRemoteAddr()); URLS.redirect(resp, url == null ? root : url); return; } else { requrireAuthentication(resp); return; } } session.setAttribute(HttpCookies.TARGET_URL, null); String token = req.getParameter("token"); String appID = configuration.getOpenIDApiKey(); String openIdurl = configuration.getOpenIDApiURL(); RPX rpx = new RPX(appID, openIdurl); Element e = null; try { e = rpx.authInfo(token); } catch (ConnectionException connEx) { requrireAuthentication(resp); return; } String idXPath = "//identifier"; String nameXPath = "//displayName"; XPathFactory xpfactory = XPathFactory.newInstance(); XPath xpath = xpfactory.newXPath(); String identifier = null; String name = null; try { XPathExpression expr1 = xpath.compile(idXPath); XPathExpression expr2 = xpath.compile(nameXPath); NodeList nodes1 = (NodeList) expr1.evaluate(e.getOwnerDocument(), XPathConstants.NODESET); NodeList nodes2 = (NodeList) expr2.evaluate(e.getOwnerDocument(), XPathConstants.NODESET); Element el = null; if (nodes1.getLength() != 0) { el = (Element) nodes1.item(0); } if (el != null) { identifier = el.getTextContent(); } if (nodes2.getLength() != 0) { el = (Element) nodes2.item(0); } if (el != null) { name = el.getTextContent(); } } catch (XPathExpressionException e1) { e1.printStackTrace(); } if (identifier != null && !"".equals(identifier)) { ACCESS_LOGGER.info("LOG IN: [" + FORMATTER.format(new Date()) + "] User " + name + " with openID " + identifier + " and IP " + req.getRemoteAddr()); int userStatus = UserDAO.UNKNOWN; try { userStatus = userDAO.isSupported(identifier); } catch (DatabaseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } switch (userStatus) { case UserDAO.UNKNOWN: // TODO handle DB error (inform user) break; case UserDAO.USER: // HttpCookies.setCookie(req, resp, HttpCookies.SESSION_ID_KEY, // identifier); session.setAttribute(HttpCookies.SESSION_ID_KEY, identifier); session.setAttribute(HttpCookies.NAME_KEY, name); URLS.redirect(resp, url == null ? root : url); break; case UserDAO.ADMIN: // HttpCookies.setCookie(req, resp, HttpCookies.SESSION_ID_KEY, // identifier); // HttpCookies.setCookie(req, resp, HttpCookies.ADMIN, // HttpCookies.ADMIN_YES); session.setAttribute(HttpCookies.SESSION_ID_KEY, identifier); session.setAttribute(HttpCookies.NAME_KEY, name); session.setAttribute(HttpCookies.ADMIN, HttpCookies.ADMIN_YES); URLS.redirect(resp, url == null ? root : url); break; case UserDAO.NOT_PRESENT: default: session.setAttribute(HttpCookies.UNKNOWN_ID_KEY, identifier); session.setAttribute(HttpCookies.NAME_KEY, name); URLS.redirect(resp, root + URLS.INFO_PAGE); break; } } else { URLS.redirect(resp, root + (URLS.LOCALHOST() ? URLS.LOGIN_LOCAL_PAGE : URLS.LOGIN_PAGE)); } // System.out.println("ID:" + identifier); // if user is supported redirect to homepage else show him a page that he // has to be added to system first by admin }
From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.AbstractPageController.java
@ModelAttribute("jirafeSiteId") public String getJirafeSiteId(final HttpServletRequest request) { String propertyValue = getHostConfigService().getProperty( ThirdPartyConstants.Jirafe.SITE_ID + "." + storeSessionFacade.getCurrentCurrency().getIsocode().toLowerCase(), request.getServerName()); if ("".equals(propertyValue)) { propertyValue = getHostConfigService().getProperty(ThirdPartyConstants.Jirafe.SITE_ID, request.getServerName()); }//from w w w . j ava 2 s.c o m return propertyValue; }
From source file:com.sun.syndication.propono.atom.server.impl.FileBasedAtomHandler.java
/** * Contruct handler for one request, using specified file storage directory. * @param req Request to be handled. * @param uploaddir File storage upload dir. *//*from ww w. j a va 2s .c om*/ public FileBasedAtomHandler(HttpServletRequest req, String uploaddir) { log.debug("ctor"); userName = authenticateBASIC(req); atomProtocolURL = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath() + req.getServletPath(); contextURI = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath(); try { service = new FileBasedAtomService(userName, uploaddir, contextURI, req.getContextPath(), req.getServletPath()); } catch (Throwable t) { throw new RuntimeException("ERROR creating FileBasedAtomService", t); } }
From source file:com.nirima.jenkins.webdav.impl.methods.MethodBase.java
public void init(HttpServletRequest request, HttpServletResponse response, IDavContext ctx, IDavRepo repo, String root) {// w ww . java 2 s. c o m m_request = request; m_response = response; m_ctx = ctx; m_repo = repo; // TODO : what if it is https m_baseUrl = "http://" + request.getServerName(); if (request.getServerPort() != 80) m_baseUrl += ":" + request.getServerPort(); m_baseUrl += request.getContextPath() + request.getServletPath(); // Path is the path into the repo we have requested // Root will be something like /config, so add to the base url m_baseUrl += root; // PathInfo will also be /config/woo, but we ignore the 1st part String pathInfo = request.getPathInfo(); if (pathInfo == null) { pathInfo = request.getServletPath(); } m_path = request.getContextPath() + pathInfo; if (m_path == null) { m_path = "/"; } else { m_path = m_path.substring(root.length()); } s_logger.info(request.getMethod() + " " + m_baseUrl + " Called with path " + m_path); }
From source file:com.qkj.qkjmanage.action.SendcarAction.java
public String sureSend() throws Exception { try {//from w w w . ja va2 s.com dao.startTransaction(); if (sendcar != null && sendcar.getOutcar_id() != null) { //? OutcarDAO ocd = new OutcarDAO(); outcar = new Outcar(); outcar.setUuid(sendcar.getOutcar_id()); outcar.setStatus(4); outcar.setLm_user(ContextHelper.getUserLoginUuid()); outcar.setLm_time(new Date()); ocd.mdyOutcarStatus(outcar); Outcar outmsg = new Outcar(); outmsg = (Outcar) ocd.get(sendcar.getOutcar_id()); //? SendDAO sd = new SendDAO(); PoolDAO pd = new PoolDAO(); map.clear(); map.put("outcar_id", outcar.getUuid()); this.setSendcars(sd.list(map)); List<Poolcar> pls = new ArrayList<Poolcar>(); pls = pd.list(map); StringBuffer url = new StringBuffer(); HttpServletRequest request = ServletActionContext.getRequest(); String url2 = request.getServerName().toString(); String uri = request.getRequestURI(); //url.append(url2.substring(0, url2.indexOf(uri))); url.append("http://cl.qkj.com.cn"); url.append("/qkjmanage/sendcar_edit?"); if (sendcars.size() > 0) { for (Sendcar s : sendcars) { List<Driver_files> d = new ArrayList<Driver_files>(); DriverDAO dr = new DriverDAO(); map.clear(); map.put("uuid", s.getDriver_id()); d = dr.list(map); for (Driver_files dd : d) { String meg = "" + timeStamp() + ";"; meg += "??;:" + outmsg.getApply_dept_name() + ";" + outmsg.getTheme() + "" + outmsg.getUse_date() + " " + outmsg.getUse_date_time() + ";" + ";" + outmsg.getStart_line() + ""; meg += outmsg.getEnd_line() + ";??" + outmsg.getAirport() + ";??" + outmsg.getApply_user() + ";" + ";??:" + s.getSeat_num() + ";??:" + outmsg.getPeple_phone() + ";???????????"; url.append("dcar.outcar_id=" + outcar.getUuid()); url.append("&dcar.send_id=" + s.getUuid());//id url.append("&dcar.driver_id=" + s.getDriver_id());//siji meg += "?:" + url.toString(); System.out.println(meg); if (dd.getDingdingid() != null) { Demo demo = new Demo(); demo.sendMessage(dd.getName() + meg, dd.getDingdingid()); } else { Weimimember_message wm = new Weimimember_message(); wm.sms_api2(dd.getPhone(), dd.getName(), meg); } if (outmsg.getPeple_phone() != null) { Weimimember_message wm = new Weimimember_message(); String meg2 = ""; meg2 = "" + timeStamp() + ";?;?:" + dd.getName() + ";???:" + dd.getPhone() + ";?" + s.getLicense(); meg2 += "???????????????????"; wm.sms_api2(outmsg.getPeple_phone(), "", meg2); } } } } if (pls.size() > 0) { for (Poolcar s : pls) { List<Driver_files> d = new ArrayList<Driver_files>(); DriverDAO dr = new DriverDAO(); map.clear(); map.put("uuid", s.getDriver_id()); d = dr.list(map); for (Driver_files dd : d) { String meg = ""; Weimimember_message wm = new Weimimember_message(); meg = "" + timeStamp() + ";"; meg += "??;:" + outmsg.getApply_dept_name() + ";" + outmsg.getTheme() + "" + outmsg.getUse_date() + " " + outmsg.getUse_date_time() + ";" + ";" + outmsg.getStart_line() + ""; meg += outmsg.getEnd_line() + ";??" + outmsg.getAirport() + ";??" + outmsg.getApply_user() + ";" + ";??:" + s.getSeat_num() + ";??:" + outmsg.getPeple_phone() + ";???????????"; if (dd.getDingdingid() != null) { Demo demo = new Demo(); demo.sendMessage(dd.getName() + meg, dd.getDingdingid()); } else { wm.sms_api2(dd.getPhone(), dd.getName(), meg); } if (outmsg.getPeple_phone() != null) { String meg2 = ""; meg2 = "" + timeStamp() + ";" + outmsg.getTheme() + "?;?:" + dd.getName() + ";???:" + dd.getPhone() + ";?" + s.getLicense(); meg2 += "???????????????????"; wm.sms_api2(outmsg.getPeple_phone(), "", meg2); } } } } } dao.commitTransaction(); } catch (Exception e) { log.error(this.getClass().getName() + "!add ?:", e); throw new Exception(this.getClass().getName() + "!add ?:", e); } finally { dao.endTransaction(); } return SUCCESS; }
From source file:com.gitblit.wicket.pages.BasePage.java
protected String getServerName() { ServletWebRequest servletWebRequest = (ServletWebRequest) getRequest(); HttpServletRequest req = servletWebRequest.getHttpServletRequest(); return req.getServerName(); }
From source file:com.ucap.uccc.cmis.impl.webservices.CmisWebServicesServlet.java
private UrlBuilder compileBaseUrl(HttpServletRequest request, HttpServletResponse response) { UrlBuilder result;/*from w ww. jav a2 s .co m*/ String baseUrl = (String) request.getAttribute(Dispatcher.BASE_URL_ATTRIBUTE); if (baseUrl != null) { result = new UrlBuilder(baseUrl); } else { result = new UrlBuilder(request.getScheme(), request.getServerName(), request.getServerPort(), null); result.addPath(request.getContextPath()); result.addPath(request.getServletPath()); } return result; }
From source file:com.music.web.AuthenticationController.java
@RequestMapping("/persona/auth") @ResponseBody/*from w w w . ja va 2s . co m*/ public String authenticateWithPersona(@RequestParam String assertion, @RequestParam boolean userRequestedAuthentication, HttpServletRequest request, HttpServletResponse httpResponse, Model model) throws IOException { if (context.getUser() != null) { return ""; } MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("assertion", assertion); params.add("audience", request.getScheme() + "://" + request.getServerName() + ":" + (request.getServerPort() == 80 ? "" : request.getServerPort())); PersonaVerificationResponse response = restTemplate.postForObject( "https://verifier.login.persona.org/verify", params, PersonaVerificationResponse.class); if (response.getStatus().equals("okay")) { User user = userService.getUserByEmail(response.getEmail()); if (user == null && userRequestedAuthentication) { return "/socialSignUp?email=" + response.getEmail(); } else if (user != null) { if (userRequestedAuthentication || user.isLoginAutomatically()) { signInAdapter.signIn(user, httpResponse, true); return "/"; } else { return ""; } } else { return ""; //in case this is not a user-requested operation, do nothing } } else { logger.warn("Persona authentication failed due to reason: " + response.getReason()); throw new IllegalStateException("Authentication failed"); } }
From source file:com.yoho.core.trace.instrument.web.TraceInterceptor.java
/** * Override to add annotations not defined in {@link TraceKeys}. *///from w ww .j a v a 2s . c o m protected void addRequestTags(HttpServletRequest request) { //add uid this.tracer.addTag(this.traceKeys.getYoho().getUid(), request.getParameter("uid")); //add http String uri = this.urlPathHelper.getPathWithinApplication(request); this.tracer.addTag(this.traceKeys.getHttp().getUrl(), getFullUrl(request)); this.tracer.addTag(this.traceKeys.getHttp().getHost(), request.getServerName()); this.tracer.addTag(this.traceKeys.getHttp().getPath(), uri); this.tracer.addTag(this.traceKeys.getHttp().getMethod(), request.getMethod()); for (String name : this.traceKeys.getHttp().getHeaders()) { Enumeration<String> values = request.getHeaders(name); if (values.hasMoreElements()) { String key = this.traceKeys.getHttp().getPrefix() + name.toLowerCase(); ArrayList<String> list = Collections.list(values); String value = list.size() == 1 ? list.get(0) : StringUtils.collectionToDelimitedString(list, ",", "'", "'"); this.tracer.addTag(key, value); } } }
From source file:org.apache.shiro.samples.spring.web.JnlpController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Subject subject = SecurityUtils.getSubject(); Session session = null;/* w w w . j a v a2 s . c o m*/ if (subject != null) { session = subject.getSession(); } if (session == null) { String msg = "Expected a non-null Shiro session."; throw new IllegalArgumentException(msg); } StringBuilder sb = new StringBuilder(); sb.append("http://"); sb.append(request.getServerName()); if (request.getServerPort() != 80) { sb.append(":"); sb.append(request.getServerPort()); } sb.append(request.getContextPath()); // prevent JNLP caching by setting response headers response.setHeader("cache-control", "no-cache"); response.setHeader("pragma", "no-cache"); Map<String, Object> model = new HashMap<String, Object>(); model.put("codebaseUrl", sb.toString()); model.put("sessionId", session.getId()); return new ModelAndView(jnlpView, model); }