⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coreutil.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            return;
        }
        ActionMessages requestMessages = (ActionMessages) request.getAttribute(Constants.REQ_ATTR_VPN_CLIENT_MESSAGES);
        if (requestMessages == null) {
            requestMessages = new ActionMessages();
        }
        requestMessages.add(messages);
        if (requestMessages.isEmpty()) {
            request.removeAttribute(Constants.REQ_ATTR_VPN_CLIENT_MESSAGES);
            return;
        }
        request.setAttribute(Constants.REQ_ATTR_VPN_CLIENT_MESSAGES, requestMessages);
    }

    public static String getReferer(HttpServletRequest request) {
        String ref = request.getHeader("Referer");
        if (ref != null) {
            ref = processRefererString(ref);
        } else {
            /*
             * IE sometimes doesnt send the referer (from javascript for
             * instance) so we should try using our referer parameter
             * work-around.
             */
            if (request.getParameter("referer") != null) {
                ref = processRefererString(request.getParameter("referer"));
            }
        }
        return ref;
    }

    static String processRefererString(String redirect) {
        try {
            URL u = new URL(redirect);
            String query = u.getQuery();
            if (query != null && !query.equals("")) {
                StringBuffer nq = new StringBuffer();
                StringTokenizer t = new StringTokenizer(query, "&");
                String parm = null;
                while (t.hasMoreTokens()) {
                    parm = t.nextToken();
                    if (!parm.startsWith("referer=") && !parm.startsWith("vpnMessage=") && !parm.startsWith("vpnError=")) {
                        if (nq.length() > 0) {
                            nq.append("&");
                        }
                        nq.append(parm);
                    }
                }
                query = nq.length() == 0 ? null : nq.toString();
            }
            StringBuffer file = new StringBuffer();
            if (u.getPath() != null) {
                file.append(u.getPath());
            }
            if (query != null) {
                file.append("?");
                file.append(query);
            }
            if (u.getRef() != null) {
                file.append("#");
                file.append(u.getRef());
            }
            u = new URL(u.getProtocol(), u.getHost(), u.getPort(), file.toString());
            return u.toExternalForm();
        } catch (MalformedURLException mrule) {
            int idx = redirect.indexOf("?");
            if (idx != -1) {
                String query = redirect.substring(idx + 1);
                redirect = redirect.substring(0, idx);
                if (query.length() > 0) {
                    StringBuffer nq = new StringBuffer();
                    StringTokenizer t = new StringTokenizer(query, "&");
                    String parm = null;
                    while (t.hasMoreTokens()) {
                        parm = t.nextToken();
                        if (!parm.startsWith("vpnMessage=") && !parm.startsWith("vpnError=")) {
                            if (nq.length() > 0) {
                                nq.append("&");
                            }
                            nq.append(parm);
                        }
                    }
                    query = nq.length() == 0 ? null : nq.toString();
                    if (query != null) {
                        redirect = redirect + "?" + query;
                    }
                }
            }
            return redirect;
        }
    }

    public static void saveErrors(HttpServletRequest request, ActionMessages bundleErrors) {
        if ((bundleErrors == null) || bundleErrors.isEmpty()) {
            request.removeAttribute(Constants.BUNDLE_ERRORS_KEY);
            return;
        }
        request.setAttribute(Constants.BUNDLE_ERRORS_KEY, bundleErrors);
    }

    public static void saveMesages(HttpServletRequest request, ActionMessages bundleMessages) {
        if ((bundleMessages == null) || bundleMessages.isEmpty()) {
            request.removeAttribute(Constants.BUNDLE_MESSAGES_KEY);
            return;
        }
        request.setAttribute(Constants.BUNDLE_MESSAGES_KEY, bundleMessages);
    }

    /**
     * Add a new parameter to an already encoded request path
     * 
     * @param path orginal path
     * @param name new parameter name
     * @param value new parameter value
     * @return new path
     */
    public static String addParameterToPath(String path, String name, String value) {
        StringBuffer buf = new StringBuffer(path);
        int idx = path.indexOf("?");
        if (idx != -1) {
            buf.append("&");
        } else {
            buf.append("?");
        }
        buf.append(name);
        buf.append("=");
        buf.append(Util.urlEncode(value));
        return buf.toString();
    }

    public static ActionForward addParameterToForward(ActionForward forward, String name, String value) {
        ActionForward f = new ActionForward(forward);
        f.setPath(addParameterToPath(forward.getPath(), name, value));
        return f;
    }

    public static void dumpComponentContext(PageContext pageContext) {
        ComponentContext compContext = (ComponentContext) pageContext.getAttribute(ComponentConstants.COMPONENT_CONTEXT,
            PageContext.REQUEST_SCOPE);
        if (log.isInfoEnabled())
            log.info("Component context dump");
        for (Iterator e = compContext.getAttributeNames(); e.hasNext();) {
            String n = (String) e.next();
            Object value = compContext.getAttribute(n);
            if (log.isInfoEnabled())
                log.info("   " + n + " = " + value);
        }
    }

    /**
     * Get the proxy URL to use for a user.
     * 
     * @param user user
     * @param propertyProfile property profile ID (0 for default / global)
     * @throws Exception
     */
    public static String getProxyURL(User user, int propertyProfile) throws Exception {
        String type = getProperty("clientProxy.type", user, propertyProfile);
        if (type.equals("http") || type.equals("https")) {
            String hostname = getProperty("clientProxy.hostname", user, propertyProfile);
            if (!hostname.equals("")) {
                StringBuffer url = new StringBuffer();
                url.append(type);
                url.append("://");
                String username = getProperty("clientProxy.username", user, propertyProfile);
                String domain = getProperty("clientProxy.ntlmDomain", user, propertyProfile);
                String auth = getProperty("clientProxy.preferredAuthentication", user, propertyProfile);
                
                if (!username.equals("")) {
                    
                    if(!domain.equals("")) {
                        url.append(DAVUtilities.encodeURIUserInfo(domain + "\\"));
                    }
                    
                    url.append(DAVUtilities.encodeURIUserInfo(username));
                    String password = getProperty("clientProxy.password", user, propertyProfile);
                    if (!password.equals("")) {
                        url.append(":");
                        url.append(DAVUtilities.encodeURIUserInfo(password));
                    }
                    url.append("@");
                }
                url.append(hostname);
                int port = CoreServlet.getServlet().getPropertyDatabase().getPropertyInt(propertyProfile,
                    user == null ? null : user.getPrincipalName(), "clientProxy.port");
                if (port != 0) {
                    url.append(":");
                    url.append(port);
                }
                url.append("?");
                url.append(auth);
                return url.toString();
            }
        } else if (type.equals("browser")) {
            String auth = getProperty("clientProxy.preferredAuthentication", user, propertyProfile);
            return "browser://" + auth;
        }
        return null;
    }

    private static String getProperty(String name, User user, int propertyProfile) throws Exception {
        return CoreServlet.getServlet().getPropertyDatabase().getProperty(propertyProfile,
            user == null ? null : user.getPrincipalName(), name);
    }

    public static void checkNavigationContext(CoreAction action, ActionMapping mapping, ActionForm form,
                                              HttpServletRequest request, HttpServletResponse response) throws Exception {
        int navigationContext = action.getNavigationContext(mapping, form, request, response);
        if (!ContextHolder.getContext().isSetupMode()) {
            SessionInfo info = CoreServlet.getServlet().getLogonController().getSessionInfo(request);
            if ((navigationContext & info.getNavigationContext()) == 0) {
                if ((navigationContext & SessionInfo.MANAGEMENT_CONSOLE_CONTEXT) != 0) {
                    if (!CoreServlet.getServlet().getLogonController().isAdministrator(info.getUser())) {
                        throw new Exception("You do not have permission to use the management console.");
                    }
                    info.setNavigationContext(SessionInfo.MANAGEMENT_CONSOLE_CONTEXT);
                    CoreUtil.resetMainNavigation(request.getSession());
                } else if ((navigationContext & SessionInfo.USER_CONSOLE_CONTEXT) != 0) {
                    info.setNavigationContext(SessionInfo.USER_CONSOLE_CONTEXT);
                    CoreUtil.resetMainNavigation(request.getSession());
                } else if ((navigationContext & SessionInfo.HELP_CONTEXT) != 0) {
                    // do nothing
                } else {
                    throw new Exception("Action does not define any valid navigation contexts that it should be available in.");
                }
            }
        }
    }

    public static Properties parseActionParameter(String parameterList) throws ParseException {
        Properties p = new Properties();
        String[] properties = parameterList.split(",");
        for (int i = 0; i < properties.length; i++) {
            String n = properties[i];
            int idx = n.indexOf('=');
            if (idx == -1) {
                throw new ParseException("Parameter list in incorrect format. [<name>=<value>[,<name>=<value>] ..]", 0);
            }
            String v = n.substring(idx + 1);
            n = n.substring(0, idx);
            p.setProperty(n, v);
        }
        return p;
    }

    public static List getSelectedItems(List serverInterfaceItem) {
        List l = new ArrayList();
        for (Iterator i = serverInterfaceItem.iterator(); i.hasNext();) {
            CoreSelectableItem item = (CoreSelectableItem) i.next();
            if (item.getSelected()) {
                l.add(item);
            }
        }
        return l;
    }

    public static List getDeselectedItems(List serverInterfaceItem) {
        List l = new ArrayList();
        for (Iterator i = serverInterfaceItem.iterator(); i.hasNext();) {
            CoreSelectableItem item = (CoreSelectableItem) i.next();
            if (!item.getSelected()) {
                l.add(item);
            }
        }
        return l;
    }

    public static void deselectAllItems(List items) {
        for (Iterator i = items.iterator(); i.hasNext();) {
            CoreSelectableItem item = (CoreSelectableItem) i.next();
            item.setSelected(false);
        }
    }

    public static void selectAllItems(List items) {
        for (Iterator i = items.iterator(); i.hasNext();) {
            CoreSelectableItem item = (CoreSelectableItem) i.next();
            item.setSelected(false);
        }
    }

    /**
     * Check whether the session associated in the middle of wizard.
     * 
     * @param session session
     * @return in a wizard
     */
    public static boolean isInWizard(HttpSession session) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -