public static UIComponent addTransient( FacesContext context, ServletRequest req, UIComponent parent, String prevId, Class childClass) throws Exception { if (context == null) context = FacesContext.getCurrentInstance(); if (parent == null) { UIComponentClassicTagBase parentTag = (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent"); parent = parentTag.getComponentInstance(); BodyContent body = parentTag.getBodyContent(); if (body != null) addVerbatim(parent, body); } UIComponent child = null; ; if (child == null) child = (UIComponent) childClass.newInstance(); child.setTransient(true); addChild(parent, prevId, child); return child; }
public static UIComponent addFacet( FacesContext context, ServletRequest req, UIComponent parent, String facetName, ValueExpression binding, Class childClass) throws Exception { if (context == null) context = FacesContext.getCurrentInstance(); if (parent == null) { UIComponentClassicTagBase parentTag = (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent"); parent = parentTag.getComponentInstance(); } UIComponent child = null; if (binding != null) child = (UIComponent) binding.getValue(context.getELContext()); if (child == null) child = (UIComponent) childClass.newInstance(); if (parent != null) parent.getFacets().put(facetName, child); if (binding != null) binding.setValue(context.getELContext(), child); return child; }
public static UIComponent addPersistent( FacesContext context, ServletRequest req, UIComponent parent, ValueExpression binding, Class childClass) throws Exception { if (context == null) context = FacesContext.getCurrentInstance(); if (parent == null) { UIComponentClassicTagBase parentTag = (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent"); parent = parentTag.getComponentInstance(); BodyContent body = parentTag.getBodyContent(); addVerbatim(parent, body); } UIComponent child = null; if (binding != null) child = (UIComponent) binding.getValue(context.getELContext()); if (child == null) { child = (UIComponent) childClass.newInstance(); // jsf/3251 if (binding != null) binding.setValue(context.getELContext(), child); } if (parent != null) parent.getChildren().add(child); return child; }
public static UIComponent findPersistent( FacesContext context, ServletRequest req, UIComponent parent, String id) throws Exception { if (context == null) context = FacesContext.getCurrentInstance(); BodyContent body = null; if (parent == null) { UIComponentClassicTagBase parentTag = (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent"); parent = parentTag.getComponentInstance(); body = parentTag.getBodyContent(); } if (parent != null) { List<UIComponent> children = parent.getChildren(); int size = children.size(); String prevId = null; for (int i = 0; i < size; i++) { UIComponent child = children.get(i); if (id.equals(child.getId())) { if (body != null) addVerbatim(parent, prevId, body); return child; } if (child.getId() != null) prevId = child.getId(); } } return null; }
/** * Login as the admin user so that a yazd user account can be administered. * * <p>Includes body of tag if admin user was authorized based on the yazd.tag.properties * yazd.admin.username and yazd.admin.password, and a valid yazd username was found in the HTTP * input parameter "username". * * @throws JspException on system level error * @return <b>SKIP_BODY</b> on failure to authorize as admin user or user to administer could not * be found, <b>EVAL_BODY_INCLUDE</b> if admin succeeded */ public final int doStartTag() throws JspException { // Initialize YazdState js = (YazdState) pageContext.getAttribute("yazdUserState", PageContext.SESSION_SCOPE); if (js == null) { throw new JspException("Yazd admin tag could not get yazd state."); } // Initialize YazdRequest jr = (YazdRequest) pageContext.getAttribute("yazdUserRequest", PageContext.REQUEST_SCOPE); if (jr == null) { throw new JspException("Yazd admin tag could not get yazd request."); } // Get username and password of admin String username = TagPropertyManager.getTagProperty("yazd.admin.username"); String password = TagPropertyManager.getTagProperty("yazd.admin.password"); if (username == null || username.length() == 0 || password == null || password.length() == 0) return SKIP_BODY; // Get admin user authorization try { auth = AuthorizationFactory.getAuthorization(username, password); } catch (UnauthorizedException ue) { return SKIP_BODY; } // Get the user to administer from the "username" HTTP input parameter ServletRequest req = pageContext.getRequest(); String tmp; if ((tmp = req.getParameter("username")) != null) return SKIP_BODY; try { ForumFactory ff = ForumFactory.getInstance(auth); ProfileManager pm = ff.getProfileManager(); user = pm.getUser(tmp); } catch (Exception e) { } if (user == null) { jr.addError("User \"" + tmp + "\" not found"); return SKIP_BODY; } return EVAL_BODY_INCLUDE; }
/** * Parses HTTP parameters in an appropriate format and return back map of values to predefined * list of names. * * @param req Request. * @return Map of parsed parameters. */ @SuppressWarnings({"unchecked"}) private Map<String, Object> parameters(ServletRequest req) { Map<String, String[]> params = req.getParameterMap(); if (F.isEmpty(params)) return Collections.emptyMap(); Map<String, Object> map = U.newHashMap(params.size()); for (Map.Entry<String, String[]> entry : params.entrySet()) map.put(entry.getKey(), parameter(entry.getValue())); return map; }
public static UIComponent findFacet( FacesContext context, ServletRequest req, UIComponent parent, String facetName) throws Exception { if (context == null) FacesContext.getCurrentInstance(); if (parent == null) { UIComponentClassicTagBase parentTag = (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent"); parent = parentTag.getComponentInstance(); } if (parent != null) return parent.getFacet(facetName); else return null; }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // session属于http范畴,所以要将ServletRequest转换成httpServletRequest try { HttpServletRequest req = (HttpServletRequest) request; HttpSession session = req.getSession(); if (session.getAttribute("username") != null) { chain.doFilter(request, response); } else { request.getRequestDispatcher("error.jsp").forward(request, response); } } catch (RuntimeException e) { e.printStackTrace(); } }
/** * @param req Request. * @return Command. */ @Nullable GridRestCommand command(ServletRequest req) { String cmd = req.getParameter("cmd"); return cmd == null ? null : GridRestCommand.fromKey(cmd.toLowerCase()); }
/** * Creates REST request. * * @param cmd Command. * @param params Parameters. * @return REST request. * @throws GridException If creation failed. */ @Nullable private GridRestRequest createRequest( GridRestCommand cmd, Map<String, Object> params, ServletRequest req) throws GridException { GridRestRequest restReq; switch (cmd) { case CACHE_GET: case CACHE_GET_ALL: case CACHE_PUT: case CACHE_PUT_ALL: case CACHE_REMOVE: case CACHE_REMOVE_ALL: case CACHE_ADD: case CACHE_CAS: case CACHE_METRICS: case CACHE_REPLACE: case CACHE_DECREMENT: case CACHE_INCREMENT: case CACHE_APPEND: case CACHE_PREPEND: { GridRestCacheRequest restReq0 = new GridRestCacheRequest(); restReq0.cacheName((String) params.get("cacheName")); restReq0.key(params.get("key")); restReq0.value(params.get("val")); restReq0.value2(params.get("val2")); Object val1 = params.get("val1"); if (val1 != null) restReq0.value(val1); restReq0.cacheFlags(intValue("cacheFlags", params, 0)); restReq0.ttl(longValue("exp", params, null)); restReq0.initial(longValue("init", params, null)); restReq0.delta(longValue("delta", params, null)); if (cmd == CACHE_GET_ALL || cmd == CACHE_PUT_ALL || cmd == CACHE_REMOVE_ALL) { List<Object> keys = values("k", params); List<Object> vals = values("v", params); if (keys.size() < vals.size()) throw new GridException( "Number of keys must be greater or equals to number of values."); Map<Object, Object> map = U.newHashMap(keys.size()); Iterator<Object> keyIt = keys.iterator(); Iterator<Object> valIt = vals.iterator(); while (keyIt.hasNext()) map.put(keyIt.next(), valIt.hasNext() ? valIt.next() : null); restReq0.values(map); } restReq = restReq0; break; } case TOPOLOGY: case NODE: { GridRestTopologyRequest restReq0 = new GridRestTopologyRequest(); restReq0.includeMetrics(Boolean.parseBoolean((String) params.get("mtr"))); restReq0.includeAttributes(Boolean.parseBoolean((String) params.get("attr"))); restReq0.nodeIp((String) params.get("ip")); restReq0.nodeId(uuidValue("id", params)); restReq = restReq0; break; } case EXE: case RESULT: case NOOP: { GridRestTaskRequest restReq0 = new GridRestTaskRequest(); restReq0.taskId((String) params.get("id")); restReq0.taskName((String) params.get("name")); restReq0.params(values("p", params)); restReq0.async(Boolean.parseBoolean((String) params.get("async"))); restReq0.timeout(longValue("timeout", params, 0L)); restReq = restReq0; break; } case LOG: { GridRestLogRequest restReq0 = new GridRestLogRequest(); restReq0.path((String) params.get("path")); restReq0.from(intValue("from", params, -1)); restReq0.to(intValue("to", params, -1)); restReq = restReq0; break; } case VERSION: { restReq = new GridRestRequest(); break; } default: throw new GridException("Invalid command: " + cmd); } restReq.address(new InetSocketAddress(req.getRemoteAddr(), req.getRemotePort())); restReq.command(cmd); if (params.containsKey("gridgain.login") || params.containsKey("gridgain.password")) { GridSecurityCredentials cred = new GridSecurityCredentials( (String) params.get("gridgain.login"), (String) params.get("gridgain.password")); restReq.credentials(cred); } String clientId = (String) params.get("clientId"); try { if (clientId != null) restReq.clientId(UUID.fromString(clientId)); } catch (Exception ignored) { // Ignore invalid client id. Rest handler will process this logic. } String destId = (String) params.get("destId"); try { if (destId != null) restReq.destinationId(UUID.fromString(destId)); } catch (IllegalArgumentException ignored) { // Don't fail - try to execute locally. } String sesTokStr = (String) params.get("sessionToken"); try { if (sesTokStr != null) restReq.sessionToken(U.hexString2ByteArray(sesTokStr)); } catch (IllegalArgumentException ignored) { // Ignore invalid session token. } return restReq; }