List of usage examples for javax.servlet.http HttpServletRequest getAttribute
public Object getAttribute(String name);
Object
, or null
if no attribute of the given name exists. From source file:testapp.CsrfTokenResponseHeaderBindingFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, javax.servlet.FilterChain filterChain) throws ServletException, IOException { CsrfToken token = (CsrfToken) request.getAttribute(REQUEST_ATTRIBUTE_NAME); Enumeration<String> e = request.getAttributeNames(); while (e.hasMoreElements()) { String param = (String) e.nextElement(); System.out.println(param); }/*from www . j av a 2s . c o m*/ if (token != null) { response.setHeader(RESPONSE_HEADER_NAME, token.getHeaderName()); response.setHeader(RESPONSE_PARAM_NAME, token.getParameterName()); response.setHeader(RESPONSE_TOKEN_NAME, token.getToken()); response.addCookie(new Cookie("XSRF-TOKEN", token.getToken())); } filterChain.doFilter(request, response); }
From source file:X509Snoop.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); X509Certificate[] certs = (X509Certificate[]) req.getAttribute("javax.servlet.request.X509Certificate"); if (certs != null) { for (int i = 0; i < certs.length; i++) { out.println("Client Certificate [" + i + "] = " + certs[i].toString()); }/* ww w. ja v a 2 s . c om*/ } else { if ("https".equals(req.getScheme())) { out.println("This was an HTTPS request, " + "but no client certificate is available"); } else { out.println("This was not an HTTPS request, " + "so no client certificate is available"); } } }
From source file:com.berwickheights.spring.mvc.controller.ErrorPageController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> args = new HashMap<String, Object>(); Throwable t = (Throwable) request.getAttribute("javax.servlet.error.exception"); if (t != null) { LogFactory.getLog("ErrorPage").error("Exception caught by error page", t); } else if ("500".equals(request.getAttribute("javax.servlet.error.status_code"))) { LogFactory.getLog("ErrorPage") .error("An internal error (500) has occurred but no Exception object was found in request"); }//w w w . jav a 2s . com if (request.getAttribute("javax.servlet.error.status_code") != null) { args.put("statusCode", request.getAttribute("javax.servlet.error.status_code")); } else { args.put("statusCode", request.getParameter("err")); } return new ModelAndView(getViewName(), "args", args); }
From source file:com.sfs.whichdoctor.export.prepare.TrainingSummaryExportHandler.java
/** * Gets the display options./*from ww w. j a v a 2 s .c om*/ * * @param request the request * * @return the display options */ public final BuilderBean getDisplayOptions(final HttpServletRequest request) { BuilderBean display = new BuilderBean(); String style = (String) request.getAttribute("Style"); if (StringUtils.equalsIgnoreCase(style, "basic")) { // Set display bean options display.setParameter("MIN", true); display.setParameter("Person's Name", true); display.setParameter("Also Training Under", true); display.setParameter("Total Accreditation", true); display.setParameter("Rotation Description", true); display.setParameter("Start Date", true); display.setParameter("End Date", true); display.setParameter("Training Time", true); display.setParameter("Training Months", true); display.setParameter("Supervisor(s)", true); display.setParameter("Workplace(s)", true); } else { // Set display bean options display.setParameter("MIN", true); display.setParameter("Person's Name", true); display.setParameter("Preferred Name", true); display.setParameter("Last Name", true); display.setParameter("Membership Status", true); display.setParameter("Membership Type", true); display.setParameter("Also Training Under", true); display.setParameter("Total Accreditation", true); display.setParameter("Rotation Description", true); display.setParameter("Rotation Status", true); display.setParameter("Start Date", true); display.setParameter("End Date", true); display.setParameter("Training Time", true); display.setParameter("Training Months", true); display.setParameter("Training Days", true); display.setParameter("Supervisor(s)", true); display.setParameter("Workplace(s)", true); } return display; }
From source file:com.github.lynxdb.server.api.http.Interceptor.java
@Override public void afterCompletion(HttpServletRequest _request, HttpServletResponse _response, Object _handler, Exception _ex) {//from w ww .j av a 2s.co m long time = System.currentTimeMillis() - (long) _request.getAttribute("startTime"); int status = _response.getStatus(); if (status < 400) { if (_request.getRequestURI().startsWith("/api/query")) { monitor.queryOK.incrementAndGet(); monitor.queryLatencies.add((int) time); } else if (_request.getRequestURI().startsWith("/api/put")) { monitor.putOK.incrementAndGet(); monitor.putLatencies.add((int) time); } else { monitor.httpLatencies.add((int) time); } monitor.http2xx.incrementAndGet(); } else { if (_request.getRequestURI().startsWith("/api/query")) { monitor.queryFAIL.incrementAndGet(); } else if (_request.getRequestURI().startsWith("/api/put")) { monitor.putFAIL.incrementAndGet(); } if (status < 500) { monitor.http4xx.incrementAndGet(); } else { monitor.http5xx.incrementAndGet(); } } }
From source file:eu.trentorise.game.api.rest.AuthorizationInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { @SuppressWarnings("unchecked") Map<String, String> pathVariables = (Map<String, String>) request .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); String gameId = (String) pathVariables.get("gameId"); String user = identityLookup.getName(); boolean isOk = permissionManager.checkGamePermission(user, gameId); if (!isOk) {/* w w w . jav a 2s . c om*/ response.sendError(HttpServletResponse.SC_FORBIDDEN, "access not permitted"); } return isOk; }
From source file:het.springapp.security.CsrfTokenGeneratorFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { //Create CSRF Token from request param CsrfToken token = (CsrfToken) request.getAttribute("_csrf"); //Set up CSRF Response Headers for: HEADER, TOKEN & PARAM //response.setHeader("X-CSRF-HEADER", token.getHeaderName()); //response.setHeader("X-CSRF-PARAM", token.getParameterName()); // response.setHeader("X-CSRF-TOKEN", token.getToken()); Cookie cookie = new Cookie("X-CSRF-TOKEN", token.getToken()); cookie.setPath("/"); response.addCookie(cookie);/*from ww w . j av a 2s . c om*/ //Filter filterChain.doFilter(request, response); }
From source file:com.pearson.pdn.demos.chainoflearning.CalendarServlet.java
@Override protected String getUserId(HttpServletRequest req) throws ServletException, IOException { // account for a forced re-register from doGet if (req.getAttribute("email") != null) { return (String) req.getAttribute("email"); }/* w w w . java2s . co m*/ // return user ID String email = req.getParameter("e"); String verifyCode = req.getParameter("v"); if (email != null && verifyCode != null) { // TODO - do this better. auth will not be in the session HttpSession session = req.getSession(); if (session != null) { String auth = (String) session.getAttribute("auth"); String authMatch = Base64.encodeBase64String((email + ":" + verifyCode).getBytes()); if (auth.equals(authMatch)) { session.removeAttribute("auth"); session.setAttribute("email", email); return email; } } } return null; }
From source file:grails.plugin.cache.web.filter.AbstractFilter.java
/** * Filters can be disabled programmatically by adding a {@link #NO_FILTER} * parameter to the request. This parameter is normally added to make * RequestDispatcher include and forwards work. * * @param httpRequest the request/*w ww . j a v a2 s . com*/ * @return true if NO_FILTER is not set. */ protected boolean filterNotDisabled(final HttpServletRequest request) { return request.getAttribute(NO_FILTER) == null; }
From source file:gov.nih.nci.cacis.xds.auth.axis.AbstractCacisXdsHandler.java
/** * //from w w w . java 2 s .c o m * @param msgContext Accepts the axis2 message context * @return returns the SubjectDN present in the x509 certificate presented by client. */ protected String getSubjectDN(MessageContext msgContext) { final HttpServletRequest req = (HttpServletRequest) msgContext .getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); final X509Certificate[] certificate = (X509Certificate[]) req .getAttribute("javax.servlet.request.X509Certificate"); if (certificate == null) { LOG.debug("javax.servlet.request.X509Certificate NOT AVAILABLE"); } else { final Principal clientDN = certificate[0].getSubjectDN(); // certificate[0] is the end of the chain. if (clientDN != null) { return clientDN.getName(); } } return null; }