List of usage examples for javax.servlet ServletRequest setAttribute
public void setAttribute(String name, Object o);
From source file:org.geoserver.security.onelogin.OneloginAuthenticationFilter.java
/** * Injects current request into {@link SAMLUserDetailsServiceImpl} and sets {@link SAMLEntryPoint} as filter entry point */// www .ja va 2 s . c o m @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { req.setAttribute(GeoServerSecurityFilter.AUTHENTICATION_ENTRY_POINT_HEADER, this.samlEntryPoint); /* * Inject current request into SAML user details service */ SAMLUserDetailsServiceImpl usd = context.getBean(SAMLUserDetailsServiceImpl.class); usd.setRequest((HttpServletRequest) req); super.doFilter(req, res, chain); }
From source file:org.withinsea.izayoi.adapter.springmvc.SpringIzayoiDispatcherFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse resp, final FilterChain chain) throws IOException, ServletException { req.setAttribute(CARRIER_CHAIN_ATTR, chain); service(req, resp);//w w w. ja v a2s . c o m req.removeAttribute(CARRIER_CHAIN_ATTR); }
From source file:org.jsecurity.web.filter.authc.FormAuthenticationFilter.java
protected void setFailureAttribute(ServletRequest request, AuthenticationException ae) { String className = ae.getClass().getName(); request.setAttribute(getFailureKeyAttribute(), className); }
From source file:org.nuxeo.ecm.platform.ui.web.shield.NuxeoErrorInterceptor.java
@AroundInvoke public Object invokeAndWrapExceptions(InvocationContext invocation) throws Exception { try {/*from ww w . j a va2 s. c o m*/ // log.debug("Before invocation..."); return invocation.proceed(); } catch (Throwable t) { if (Transaction.instance().isActive()) { Transaction.instance().setRollbackOnly(); } FacesContext facesContext = FacesContext.getCurrentInstance(); if (FacesLifecycle.getPhaseId() == PhaseId.RENDER_RESPONSE) { if (ExceptionHelper.isSecurityError(t)) { if (facesContext != null) { Object req = facesContext.getExternalContext().getRequest(); if (req instanceof ServletRequest) { ServletRequest request = (ServletRequest) req; request.setAttribute("securityException", t); } } throw new DocumentSecurityException( "Security Error during call of " + invocation.getTarget().toString(), t); } } ClientException cException = new ClientException(t); // redirect is not allowed during render response phase => throw // the error without redirecting if (FacesLifecycle.getPhaseId() == PhaseId.RENDER_RESPONSE) { if (facesContext != null) { Object req = facesContext.getExternalContext().getRequest(); if (req instanceof ServletRequest) { ServletRequest request = (ServletRequest) req; request.setAttribute("applicationException", cException); } } throw cException; } // check if previous page was already an error page to avoid // redirect cycle if (facesContext != null) { ExternalContext externalContext = facesContext.getExternalContext(); if (externalContext != null) { Map<String, String[]> requestMap = externalContext.getRequestHeaderValuesMap(); if (requestMap != null) { String[] previousPage = requestMap.get("Referer"); if (previousPage != null && previousPage.length != 0) { String pageName = previousPage[0]; if (pageName != null && pageName.contains("error_page")) { redirectToErrorPage(UNTHEMED_ERROR_VIEW_ID); return null; } } } } } String redirectToViewId = null; try { log.error("Exception caught, redirecting to the error page...", cException); final Context sessionContext = Contexts.getSessionContext(); // set applicationException in session hoping // ErrorPageActionListener will inject it sessionContext.set("applicationException", cException); if (ExceptionHelper.isSecurityError(t) || cException.getCause() instanceof DocumentSecurityException) { redirectToViewId = LOGIN_VIEW_ID; } else { redirectToViewId = GENERIC_ERROR_VIEW_ID; } } catch (Throwable e) { // might be the case when session context is null log.error(e); redirectToViewId = UNTHEMED_ERROR_VIEW_ID; } if (redirectToErrorPage(redirectToViewId)) { return null; } else { log.info("Unable to handle exception in web-context. " + "It might be an external (soap) request. " + "Throwing further..."); log.error("Original error", t); throw cException; } } }
From source file:org.romaframework.aspect.view.html.transformer.jsp.JspTemplateManager.java
public void execute(String templateName, HtmlViewRenderable renderable, String part, Writer writer) { ServletRequest request = HtmlViewAspectHelper.getServletRequest(); final String classJsp = getTemplatesPath() + templateName; final Object previousComponent = request.getAttribute(RequestConstants.CURRENT_COMPONENT_IN_TRANSFORMER); request.setAttribute(RequestConstants.CURRENT_COMPONENT_IN_TRANSFORMER, renderable); final Object previousPart = request.getAttribute(RequestConstants.CURRENT_COMPONENT_PART_IN_TRANSFORMER); request.setAttribute(RequestConstants.CURRENT_COMPONENT_PART_IN_TRANSFORMER, part); try {// w ww .ja v a 2 s .c om HtmlViewAspectHelper.getHtmlFromJSP(request, classJsp, writer); } catch (ServletException e) { log.error("error in jsp transformer", e.getRootCause() == null ? e : e.getRootCause()); } catch (IOException e) { log.error("maybe wrong render defined", e); } request.setAttribute(RequestConstants.CURRENT_COMPONENT_IN_TRANSFORMER, previousComponent); request.setAttribute(RequestConstants.CURRENT_COMPONENT_PART_IN_TRANSFORMER, previousPart); }
From source file:com.weixin.core.util.ServletUtils.java
/** * ???Request Parameters./* ww w . ja va2s . c o m*/ * * Parameter???. */ @SuppressWarnings("unchecked") public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) { Assert.notNull(request, "Request must not be null"); Enumeration paramNames = request.getParameterNames(); Map<String, Object> params = new TreeMap<String, Object>(); Map<String, Object> param = new HashMap<String, Object>(); if (prefix == null) { prefix = ""; } while (paramNames != null && paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); if ("".equals(prefix) || paramName.startsWith(prefix)) { String unprefixed = paramName.substring(prefix.length()); String[] values = request.getParameterValues(paramName); if (values == null || values.length == 0) { // Do nothing, no values found at all. } else if (values.length > 1) { params.put(unprefixed, values); param.put(paramName, values); } else { params.put(unprefixed, values[0]); param.put(paramName, values[0]); } } } request.setAttribute("param", param); return params; }
From source file:cn.com.cowboy.nosql_mvc.web.filter.CustomFormAuthenticationFilter.java
@Override protected void setFailureAttribute(ServletRequest request, AuthenticationException ae) { logger.debug(ae.getMessage());/* w ww. ja v a 2s.co m*/ // session? ((HttpServletRequest) request).getSession().setAttribute(getFailureKeyAttribute(), ae); request.setAttribute(getFailureKeyAttribute(), ae); }
From source file:com.bibisco.filters.FileFilter.java
/** * Example of how to get useful things with the uploaded file structure. * Generally speaking, this method should be overrided by framework's users. * //from w w w. j a v a2 s .c om * <p>Here we demostrate how to extract useful infos * (<code>name, value, isInMemory, size, etc) </code>) * plus how to deal with memory- or disk-persisted cases. * * <li><p>We pass the whole <code>FileItem</code> structure * to the next <code>jsp</code> page, which gains the ability to extract * infos as well: via Request, under name: "file-" + fieldname * * <li><p>The file content can be retrieved here or later, <code>FileItem</code> * object can use its data-getters in <code>.jsp</code>s! * <p>In this code, we retrieve file content and pass it in Request * for next uses under the a general format of * array of bytes (<code>byte []</code>); with name equal to "file-" + fieldname. * * @param pItem * @throws IOException */ protected void processUploadedFile(FileItem pItem, ServletRequest pRequest) throws IOException { String name = pItem.getFieldName(); boolean isInMemory = pItem.isInMemory(); pRequest.setAttribute("file-" + name, pItem); if (isInMemory) { mLog.debug("the file ", name, " is in memory under the request attribute file-content-", name); byte[] data = pItem.get(); pRequest.setAttribute("file-content-" + name, data); } else { mLog.debug("the file ", name, " is in the file system and under the request attribute file-content-", name); InputStream uploadedStream = pItem.getInputStream(); byte[] data = (new StreamTokenizer(new BufferedReader(new InputStreamReader(uploadedStream)))) .toString().getBytes(); uploadedStream.close(); pRequest.setAttribute("file-content-" + name, data); } }
From source file:it.geosolutions.geoserver.authentication.filter.GeoFenceAuthFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setAttribute(GeoServerSecurityFilter.AUTHENTICATION_ENTRY_POINT_HEADER, aep); super.doFilter(request, response, chain); // Authentication auth = SecurityContextHolder.getContext().getAuthentication(); // if (auth == null) { // doAuth(request, response); // } else { // LOGGER.fine("Found existing Authentication in context: " + auth); // }/*from ww w . j a v a2s . c om*/ // // chain.doFilter(request, response); }
From source file:org.siyuyan.module.web.controller.HomeController.java
/** * ?/*from w w w . ja v a 2s.c o m*/ * @param category * @param page * @param size * @param request * @param response * @return * @throws Exception */ @RequestMapping(value = "category/{category}") public String category(@PathVariable String category, Integer page, Integer size, ServletRequest request, ServletResponse response) throws Exception { if (StringUtils.isNotBlank(category)) { request.setAttribute("category", category); HashMap<String, Object> query = new HashMap<>(); query.put("category", category); SearchResponse sr = searcher.query(query, "_timestamp", SortOrder.DESC, getStartPage(page = getPage(page), size = getSize(size)), size); List<HashMap<String, Object>> film = util.processSearchRespons(sr); // ? int total = (int) sr.getHits().totalHits(); int num = sr.getHits().getHits().length; if (num == 0) total = 0; Pagination pagination = new Pagination(Constant.defaultPageGroup, page, Constant.defaultPageSize, total); request.setAttribute("pager", pagination.getPagination()); // sr = searcher.newMovies(10); request.setAttribute("film", film); request.setAttribute("newFilm", util.processSearchRespons(sr)); // facetcount? request.setAttribute("catgoryName", ""); request.setAttribute("facet", facetService.facetSubcategory(category, 15)); request.setAttribute("page", page); } return "category"; }