List of usage examples for javax.servlet.http HttpServletRequest getRemoteHost
public String getRemoteHost();
From source file:de.mpg.mpdl.inge.pidcache.web.MainServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { logger.info("PID cache GET request"); try {/*from w ww . ja v a 2s .co m*/ if (!authenticate(req, resp)) { logger.warn("Unauthorized request from " + req.getRemoteHost()); return; } PidCacheService pidCacheService = new PidCacheService(); if (GwdgPidService.GWDG_PIDSERVICE_VIEW.equals(req.getPathInfo()) || GwdgPidService.GWDG_PIDSERVICE_VIEW.concat("/").equals(req.getPathInfo())) { if (req.getParameter("pid") == null) { resp.sendError(HttpServletResponse.SC_NO_CONTENT, "PID parameter failed."); } resp.getWriter().append(pidCacheService.retrieve(req.getParameter("pid"))); } else if (GwdgPidService.GWDG_PIDSERVICE_FIND.equals(req.getPathInfo()) || GwdgPidService.GWDG_PIDSERVICE_FIND.concat("/").equals(req.getPathInfo())) { if (req.getParameter("url") == null) { resp.sendError(HttpServletResponse.SC_NO_CONTENT, "URL parameter failed."); } resp.getWriter().append(pidCacheService.search(req.getParameter("url"))); } else if ("/cache/size".equals(req.getPathInfo())) { resp.getWriter().append("There are " + pidCacheService.getCacheSize() + " PID stored in cache"); } else if ("/queue/size".equals(req.getPathInfo())) { resp.getWriter().append("There are " + pidCacheService.getQueueSize() + " PID actually in queue"); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getPathInfo()); } } catch (Exception e) { throw new ServletException("Error processing request", e); } }
From source file:org.paxle.gui.impl.HttpAuthManager.java
public User authenticatedAs(final HttpServletRequest request, final String userName, String password) { final User user = userAdmin.getUser(USER_HTTP_LOGIN, userName); if (user == null) { logger.info(String.format("[%s] No user found for username '%s'.", request.getRemoteHost(), userName)); return null; }/* w w w . j a v a 2 s.c o m*/ if (!user.hasCredential(USER_HTTP_PASSWORD, password)) { logger.info(String.format("[%s] Wrong password for username '%s'.", request.getRemoteHost(), userName)); return null; } Authorization authorization = userAdmin.getAuthorization(user); if (authorization == null) { logger.info(String.format("[%s] No authorization found for username '%s'.", request.getRemoteHost(), userName)); return null; } // if (!authorization.hasRole("Administrators")) { // this.logger.warn(String.format("")) // } return user; }
From source file:com.glaf.base.modules.sys.interceptor.AuthorizeInterceptor.java
/** * method - method being invoked args - arguments to the method target - * target of the method invocation. May be null. *//*from w w w . j a va 2s . c o m*/ public void before(Method method, Object[] args, Object target) throws Throwable { boolean authorized = false; String objectName = target.getClass().getName(); String methodName = method.getName(); // logger.debug("object:" + objectName); // logger.debug("method:" + methodName); if (StringUtils.startsWith(methodName, "org.springframework.web.servlet.view")) { return; } if (StringUtils.startsWith(methodName, "login")) { return; } if (StringUtils.startsWith(methodName, "logout")) { return; } String ip = ""; String account = ""; for (int i = 0; i < args.length; i++) { // logger.debug("args:" + args[i]); if (args[i] instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) args[i]; if (request != null && request.getParameter("method") != null) { methodName = request.getParameter("method"); ip = request.getRemoteHost(); SysUser user = RequestUtil.getLoginUser(request); if (user != null) { //logger.debug(user.toJsonObject().toJSONString()); account = user.getAccount(); if (StringUtils.equals(user.getAdminFlag(), "1")) { authorized = true; } if (user.isSystemAdmin()) { authorized = true; logger.debug(account + " is admin"); } } // logger.debug("IP:" + ip + ", Account:" + account); } } } methodName = objectName + "." + methodName; // logger.debug("methodName:" + methodName); // if (findSysFunction(methodName)) { // if (findUserFunction(account, methodName)) { // logger.debug("method is in user functions"); authorized = true; } } else {// ? // logger.debug("method isn't in sys functions"); authorized = true; } // ? createLog(account, methodName, ip, authorized ? 1 : 0); if (!authorized) { throw new AuthorizeException("No Privileges."); } }
From source file:se.vgregion.portal.requestlogger.RequestLoggerController.java
private Map<String, String> getRequestInfo(PortletRequest request) { Map<String, String> requestResult = new TreeMap<String, String>(); HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request); requestResult.put("RemoteUser", httpRequest.getRemoteUser()); requestResult.put("P3P.USER_LOGIN_ID", getRemoteUserId(request)); requestResult.put("RemoteAddr", httpRequest.getRemoteAddr()); requestResult.put("RemoteHost", httpRequest.getRemoteHost()); requestResult.put("RemotePort", String.valueOf(httpRequest.getRemotePort())); requestResult.put("AuthType", httpRequest.getAuthType()); requestResult.put("CharacterEncoding", httpRequest.getCharacterEncoding()); requestResult.put("ContentLength", String.valueOf(httpRequest.getContentLength())); requestResult.put("ContentType", httpRequest.getContentType()); requestResult.put("ContextPath", httpRequest.getContextPath()); requestResult.put("LocalAddr", httpRequest.getLocalAddr()); requestResult.put("Locale", httpRequest.getLocale().toString()); requestResult.put("LocalName", httpRequest.getLocalName()); requestResult.put("LocalPort", String.valueOf(httpRequest.getLocalPort())); requestResult.put("Method", httpRequest.getMethod()); requestResult.put("PathInfo", httpRequest.getPathInfo()); requestResult.put("PathTranslated", httpRequest.getPathTranslated()); requestResult.put("Protocol", httpRequest.getProtocol()); requestResult.put("QueryString", httpRequest.getQueryString()); requestResult.put("RequestedSessionId", httpRequest.getRequestedSessionId()); requestResult.put("RequestURI", httpRequest.getRequestURI()); requestResult.put("Scheme", httpRequest.getScheme()); requestResult.put("ServerName", httpRequest.getServerName()); requestResult.put("ServerPort", String.valueOf(httpRequest.getServerPort())); requestResult.put("ServletPath", httpRequest.getServletPath()); return requestResult; }
From source file:be.fedict.hsm.model.security.SecurityAuditGeneratorBean.java
private String getHostIdentifier() { HttpServletRequest httpServletRequest; try {/*www . ja va2 s . com*/ httpServletRequest = (HttpServletRequest) PolicyContext .getContext("javax.servlet.http.HttpServletRequest"); } catch (PolicyContextException e) { LOG.debug("JACC error: " + e.getMessage()); return null; } String hostIdentifier = httpServletRequest.getRemoteHost(); return hostIdentifier; }
From source file:org.nema.medical.mint.server.controller.StudyRootController.java
@RequestMapping(method = RequestMethod.DELETE, value = "/studies/{uuid}") public void deleteStudy(@PathVariable("uuid") final String uuid, final HttpServletRequest req, final HttpServletResponse res) throws IOException { final Utils.StudyStatus studyStatus = Utils.validateStudyStatus(studiesRoot, uuid, res, studyDAO); if (studyStatus != Utils.StudyStatus.OK) { return;/*from ww w . j a v a 2 s .c o m*/ } deleteStudy(uuid, studiesRoot, req.getRemoteUser(), req.getRemoteHost(), changeDAO, studyDAO); res.setStatus(204); }
From source file:org.josso.selfservices.password.SelfServicesBaseAction.java
protected void prepareContext(HttpServletRequest request) throws SSOException, SSOAuthenticationException { // Use gateway to select a security domain SSOGateway gwy = getSSOGateway();//from w w w . j a va2 s .c om // The first thing to do is to create the context and publish the security domain !!! MutableSSOContext ctx = (MutableSSOContext) gwy.prepareSSOContext(new SSORequestImpl(request)); ctx.setUserLocation(request.getRemoteHost()); // Store current SD name in session request.getSession().setAttribute(org.josso.gateway.signon.Constants.KEY_JOSSO_SECURITY_DOMAIN_NAME, ctx.getSecurityDomain().getName()); if (logger.isDebugEnabled()) logger.debug("[prepareContext()] Storing security domain name in session [" + KEY_JOSSO_SECURITY_DOMAIN_NAME + "] : " + ctx.getSecurityDomain().getName() + " (" + request.getSession().getId() + ")"); }
From source file:org.apache.hadoop.hdfsproxy.LdapIpDirFilter.java
/** {@inheritDoc} */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String prevThreadName = Thread.currentThread().getName(); try {/* w w w .ja v a 2 s . c o m*/ Thread.currentThread().setName(contextPath); HttpServletRequest rqst = (HttpServletRequest) request; HttpServletResponse rsp = (HttpServletResponse) response; if (LOG.isDebugEnabled()) { StringBuilder b = new StringBuilder("Request from ").append(rqst.getRemoteHost()).append("/") .append(rqst.getRemoteAddr()).append(":").append(rqst.getRemotePort()); b.append("\n The Scheme is " + rqst.getScheme()); b.append("\n The Path Info is " + rqst.getPathInfo()); b.append("\n The Translated Path Info is " + rqst.getPathTranslated()); b.append("\n The Context Path is " + rqst.getContextPath()); b.append("\n The Query String is " + rqst.getQueryString()); b.append("\n The Request URI is " + rqst.getRequestURI()); b.append("\n The Request URL is " + rqst.getRequestURL()); b.append("\n The Servlet Path is " + rqst.getServletPath()); LOG.debug(b.toString()); } LdapRoleEntry ldapent = new LdapRoleEntry(); // check ip address String userIp = rqst.getRemoteAddr(); try { boolean isAuthorized = getLdapRoleEntryFromUserIp(userIp, ldapent); if (!isAuthorized) { rsp.sendError(HttpServletResponse.SC_FORBIDDEN, "IP " + userIp + " is not authorized to access"); return; } } catch (NamingException ne) { throw new IOException("NamingException while searching ldap" + ne.toString()); } // since we cannot pass ugi object cross context as they are from // different classloaders in different war file, we have to use String attribute. rqst.setAttribute("org.apache.hadoop.hdfsproxy.authorized.userID", ldapent.userId); rqst.setAttribute("org.apache.hadoop.hdfsproxy.authorized.paths", ldapent.paths); LOG.info("User: " + ldapent.userId + " Request: " + rqst.getPathInfo() + " From: " + rqst.getRemoteAddr()); chain.doFilter(request, response); } finally { Thread.currentThread().setName(prevThreadName); } }
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 ww w . j av a2s . c o m return false; }
From source file:org.jumpmind.symmetric.web.SymmetricServlet.java
protected void logException(HttpServletRequest req, Exception ex, boolean isError) { String nodeId = req.getParameter(WebConstants.NODE_ID); String externalId = req.getParameter(WebConstants.EXTERNAL_ID); String address = req.getRemoteAddr(); String hostName = req.getRemoteHost(); String method = req instanceof HttpServletRequest ? ((HttpServletRequest) req).getMethod() : ""; if (isError) { log.error("Error while processing {} request for externalId: {}, node: {} at {} ({}) with path: {}", new Object[] { method, externalId, nodeId, address, hostName, ServletUtils.normalizeRequestUri(req) }); log.error("", ex); } else {/*ww w . j a v a 2 s .c om*/ log.warn( "Error while processing {} request for externalId: {}, node: {} at {} ({}). The message is: {}", new Object[] { method, externalId, nodeId, address, hostName, ex.getMessage() }); } }