List of usage examples for javax.servlet ServletRequest setAttribute
public void setAttribute(String name, Object o);
From source file:com.jaspersoft.jasperserver.war.tags.BaseTagSupport.java
protected void restoreRequestAttributes(Map restoreMap) { ServletRequest request = pageContext.getRequest(); for (Iterator it = restoreMap.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String attribute = (String) entry.getKey(); Object value = entry.getValue(); if (value == NO_ATTRIBUTE) { request.removeAttribute(attribute); } else {//from w w w . j a va2s .c o m request.setAttribute(attribute, value); } } }
From source file:jp.terasoluna.fw.web.thin.BlockageControlFilter.java
/** * ?`FbN?s?B//from w w w.j a v a2s.c o m * * @param req HTTPNGXg * @param res HTTPX|X * @param chain tB^`F?[ * * @throws IOException I/OG?[ * @throws ServletException T?[ubgO * * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) */ @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { // NGXgtB^?B if (req.getAttribute(BLOCKAGE_THRU_KEY) == null) { // tB^?Zbg req.setAttribute(BLOCKAGE_THRU_KEY, "true"); if (controller.isCheckRequired(req)) { // ?`FbN if (controller.isBlockaded(RequestUtil.getPathInfo(req), req)) { if (log.isDebugEnabled()) { log.debug("isBlockaded() failed."); } throw new BlockageException(); } } } // tB^T?[ubg chain.doFilter(req, res); }
From source file:de.itsvs.cwtrpc.security.RpcSessionManagementFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final boolean continueChain; if (request.getAttribute(PROCESSED_ALREADY_ATTR_NAME) == null) { request.setAttribute(PROCESSED_ALREADY_ATTR_NAME, Boolean.TRUE); continueChain = process((HttpServletRequest) request, (HttpServletResponse) response); } else {//from w ww. j av a 2s .c om continueChain = true; } if (continueChain) { chain.doFilter(request, response); } }
From source file:org.eurekaclinical.user.webapp.servlet.filter.UserFilter.java
@Override public void doFilter(ServletRequest inRequest, ServletResponse inResponse, FilterChain inFilterChain) throws IOException, ServletException { HttpServletRequest servletRequest = (HttpServletRequest) inRequest; HttpServletResponse servletResponse = (HttpServletResponse) inResponse; String remoteUser = servletRequest.getRemoteUser(); inRequest.setAttribute(RequestAttributes.Eureka_Webapp_URL, this.properties.getEurekaWebappUrl()); inRequest.setAttribute(RequestAttributes.Eureka_Services_URL, this.properties.getEurekaServicesUrl()); if (!StringUtils.isEmpty(remoteUser)) { try {//from ww w . j av a2s .c o m HttpSession session = servletRequest.getSession(false); if (session != null) { User user = this.servicesClient.getMe(); if (!user.isActive()) { session.invalidate(); sendForbiddenError(servletResponse, servletRequest, true); } else { inRequest.setAttribute(RequestAttributes.USER, user); inRequest.setAttribute(RequestAttributes.USER_IS_ACTIVATED, user.isActive()); inFilterChain.doFilter(inRequest, inResponse); } } else { goHome(servletRequest, servletResponse); } } catch (ClientException ex) { if (null != ex.getResponseStatus()) { switch (ex.getResponseStatus()) { case FORBIDDEN: { HttpSession session = servletRequest.getSession(false); if (session != null) { session.invalidate(); } sendForbiddenError(servletResponse, servletRequest, false); break; } case UNAUTHORIZED: { HttpSession session = servletRequest.getSession(false); if (session != null) { session.invalidate(); } goHome(servletRequest, servletResponse); break; } default: throw new ServletException("Error getting user " + servletRequest.getRemoteUser(), ex); } } } } else { inFilterChain.doFilter(inRequest, inResponse); } }
From source file:jp.terasoluna.fw.web.thin.AuthorizationControlFilter.java
/** * ANZX`FbN?s?B// w ww . ja v a2 s . co m * * @param req HTTPNGXg * @param res HTTPX|X * @param chain tB^`F?[ * * @throws IOException I/OG?[ * @throws ServletException T?[ubgO * * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, * javax.servlet.ServletResponse, * javax.servlet.FilterChain) */ @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { // NGXgtB^?B if (req.getAttribute(AUTHORIZATION_THRU_KEY) == null) { // tB^?Zbg req.setAttribute(AUTHORIZATION_THRU_KEY, "true"); // pX`FbN?B if (controller.isCheckRequired(req)) { // ANZX`FbN if (!controller.isAuthorized(RequestUtil.getPathInfo(req), req)) { if (log.isDebugEnabled()) { log.debug("isAuthorized() failed."); } throw new UnauthorizedException(); } } } // tB^T?[ubg chain.doFilter(req, res); }
From source file:jp.terasoluna.fw.web.thin.AuthenticationControlFilter.java
/** * ?OI?`FbN?s?B/*from w ww.j a v a2 s .co m*/ * * @param req HTTPNGXg * @param res HTTPX|X * @param chain tB^`F?[ * * @throws IOException I/OG?[ * @throws ServletException T?[ubgO * * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, * javax.servlet.ServletResponse, * javax.servlet.FilterChain) */ @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { // NGXgtB^?B if (req.getAttribute(AUTHENTICATION_THRU_KEY) == null) { // tB^?Zbg req.setAttribute(AUTHENTICATION_THRU_KEY, "true"); // pX`FbN?B if (controller.isCheckRequired(req)) { // ?OI?`FbN if (!controller.isAuthenticated(RequestUtil.getPathInfo(req), req)) { if (log.isDebugEnabled()) { log.debug("isAuthenticated() failed."); } throw new UnauthenticatedException(); } } } // tB^T?[ubg chain.doFilter(req, res); }
From source file:edu.emory.cci.aiw.cvrg.eureka.servlet.filter.UserFilter.java
@Override public void doFilter(ServletRequest inRequest, ServletResponse inResponse, FilterChain inFilterChain) throws IOException, ServletException { HttpServletRequest servletRequest = (HttpServletRequest) inRequest; HttpServletResponse servletResponse = (HttpServletResponse) inResponse; String remoteUser = servletRequest.getRemoteUser(); inRequest.setAttribute(RequestAttributes.User_Webapp_URL, this.properties.getUserWebappUrl()); inRequest.setAttribute(RequestAttributes.User_Service_URL, this.properties.getUserServiceUrl()); Boolean userIsActive = true;/*from www .j ava 2 s . c om*/ if (!StringUtils.isEmpty(remoteUser)) { try { HttpSession session = servletRequest.getSession(false); if (session != null) { User user = this.inUserClient.getMe(); userIsActive = this.inUserClient.getMe().isActive(); if (!userIsActive) { session.invalidate(); sendForbiddenError(servletResponse, servletRequest, true); } else { inRequest.setAttribute(RequestAttributes.USER, user); inRequest.setAttribute(RequestAttributes.USER_IS_ACTIVATED, userIsActive); inFilterChain.doFilter(inRequest, inResponse); } } else { goHome(servletRequest, servletResponse); } } catch (ClientException ex) { if (null != ex.getResponseStatus()) { switch (ex.getResponseStatus()) { case FORBIDDEN: { HttpSession session = servletRequest.getSession(false); if (session != null) { session.invalidate(); } sendForbiddenError(servletResponse, servletRequest, false); break; } case UNAUTHORIZED: { HttpSession session = servletRequest.getSession(false); if (session != null) { session.invalidate(); } goHome(servletRequest, servletResponse); break; } default: throw new ServletException("Error getting user " + servletRequest.getRemoteUser(), ex); } } } } else { inFilterChain.doFilter(inRequest, inResponse); } }
From source file:org.opencms.xml.page.CmsXmlPageFactory.java
/** * Factory method to unmarshal (read) a XML document instance from * a filename in the VFS, using the request attributes as cache.<p> * /*www . java 2 s.c o m*/ * @param cms the current OpenCms user context * @param filename the filename of the resource to unmarshal * @param req the current request * * @return the unmarshaled XML document, or <code>null</code> if the given resource was not of type {@link I_CmsXmlDocument} * * @throws CmsException in something goes wrong */ public static I_CmsXmlDocument unmarshal(CmsObject cms, String filename, ServletRequest req) throws CmsException { // add site root to filename String rootPath = cms.getRequestContext().addSiteRoot(filename); // try to get the requested page form the current request attributes I_CmsXmlDocument doc = (I_CmsXmlDocument) req.getAttribute(rootPath); if (doc != null) { return doc; } // always use "ignore expiration" filter, date validity must be checked before calling this if required CmsFile file = cms.readFile(filename, CmsResourceFilter.IGNORE_EXPIRATION); if (CmsResourceTypeXmlPage.isXmlPage(file)) { // file is of type XML page doc = CmsXmlPageFactory.unmarshal(cms, file); } else if (CmsResourceTypeXmlContent.isXmlContent(file)) { // file is of type XML content doc = CmsXmlContentFactory.unmarshal(cms, file); } else { // sanity check: file type not an A_CmsXmlDocument throw new CmsXmlException(Messages.get().container(Messages.ERR_XML_PAGE_FACT_NO_XML_DOCUMENT_1, file)); } // store the page that was read as request attribute for future read requests req.setAttribute(rootPath, doc); return doc; }
From source file:cn.vlabs.duckling.vwb.CPSFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { int advSiteId = Integer.parseInt(StringUtils.defaultIfEmpty(request.getParameter("as"), "-1")); if (advSiteId <= 0) { chain.doFilter(request, response); return;/*from www.j av a2 s. c om*/ } HttpServletResponse rep = (HttpServletResponse) response; HttpServletRequest req = (HttpServletRequest) request; request.setAttribute("cps", advSiteId); Cookie[] cookies = req.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (StringUtils.equals(CPS_ADV, cookie.getName())) { cookie.setPath(req.getContextPath()); cookie.setMaxAge(0); } } } Cookie myCookie = new Cookie(CPS_ADV, advSiteId + ""); myCookie.setMaxAge(60 * 60 * 24);// myCookie.setPath(req.getContextPath()); rep.addCookie(myCookie); chain.doFilter(request, response); }
From source file:org.b3log.solo.filter.PermalinkFilter.java
/** * Dispatches the specified request to the specified article or page * processor with the specified response. * //from w w w . j a va2s. co m * @param request the specified request * @param response the specified response * @param article the specified article * @param page the specified page * @throws ServletException servlet exception * @throws IOException io exception * @see HTTPRequestDispatcher#dispatch(org.b3log.latke.servlet.HTTPRequestContext) */ private void dispatchToArticleOrPageProcessor(final ServletRequest request, final ServletResponse response, final JSONObject article, final JSONObject page) throws ServletException, IOException { final HTTPRequestContext context = new HTTPRequestContext(); context.setRequest((HttpServletRequest) request); context.setResponse((HttpServletResponse) response); if (null != article) { request.setAttribute(Article.ARTICLE, article); request.setAttribute(Keys.HttpRequest.REQUEST_URI, Latkes.getContextPath() + "/article"); } else { request.setAttribute(Page.PAGE, page); request.setAttribute(Keys.HttpRequest.REQUEST_URI, Latkes.getContextPath() + "/page"); } request.setAttribute(Keys.HttpRequest.REQUEST_METHOD, HTTPRequestMethod.GET.name()); HTTPRequestDispatcher.dispatch(context); }