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

📄 intramartconnectfilter.java

📁 intra_mart是日本NDD公司开发的著名企业应用解决方案中间件。集成了J2ee服务器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**
     * Filter Config
     */
    private FilterConfig filterConfig;

    /**
     * 僒乕價僗儅僱乕僕儍
     */
    private ServiceManager serviceManager;

    /**
     * 僒乕價僗僾儘僷僥傿僴儞僪儔
     */
    private ServicePropertyHandler serviceHandler;

    /**
     * 僙僢僔儑儞儅僱乕僕儍
     */
    private SessionManager sessionManager;

    /**
     * 僙僢僔儑儞僾儘僷僥傿僴儞僪儔
     */
    private SessionPropertyHandler sessionHandler;

    /**
     * referrer偺僼僅乕儅僢僩
     *
     * @since 4.1.5
     */
    private boolean referrerFormatShort;

    /**
     * 僙僉儏儕僥傿偺奼挘巕
     *
     * @since 4.3
     */
    private String securityExt;

    /**
     * 棯幃偺URL傪巊梡偡傞偐偳偆偐傪敾掕偟傑偡丅
     *
     * @return <code>true</code>丗棯幃偺URL傪巊梡丄<code>false</code>丗慡晹偺URL傪巊梡
     * @since 4.1.5
     */
    private boolean isReferrerFormatShort() {
        return this.referrerFormatShort;
    }

    /**
     * 棯幃偺URL傪巊梡偡傞偐偳偆偐傪愝掕偟傑偡丅
     *
     * @param referrerFormatShort <code>true</code>丗棯幃偺URL傪巊梡丄<code>false</code>丗慡晹偺URL傪巊梡
     * @since 4.1.5
     */
    private void setReferrerFormatShort(boolean referrerFormatShort) {
        this.referrerFormatShort = referrerFormatShort;
    }

    /**
     * 僙僉儏儕僥傿偺奼挘巕傪庢摼偟傑偡丅
     *
     * @return 僙僉儏儕僥傿偺奼挘巕
     */
    public String getSecurityExt() {
        return this.securityExt;
    }

    /**
     * 僙僉儏儕僥傿偺奼挘巕傪愝掕偟傑偡丅
     *
     * @param securityExt 僙僉儏儕僥傿偺奼挘巕
     */
    public void setSecurityExt(String securityExt) {
        this.securityExt = securityExt;
    }

    /**
     * 偙偺僼傿儖僞傪弶婜壔偟傑偡丅
     *
     * @param filterConfig FilterConfig
     * @throws ServletException 僼傿儖僞撪偱椺奜偑敪惗
     */
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;

        // 僒乕價僗儅僱乕僕儍偺愝掕
        try {
            this.serviceManager = ServiceManager.getServiceManager();
        } catch (ServiceManagerException e) {
            throw new ServletException(e.getMessage(), e);
        }

        // 僒乕價僗僾儘僷僥傿僴儞僪儔偺愝掕
        this.serviceHandler = this.serviceManager.getServicePropertyHandler();

        // 僙僢僔儑儞儅僱乕僕儍偺愝掕
        try {
            this.sessionManager = SessionManager.getSessionManager();
        } catch (SessionManagerException e) {
            throw new ServletException(e.getMessage(), e);
        }

        // 僙僢僔儑儞僾儘僷僥傿僴儞僪儔偺愝掕
        this.sessionHandler = this.sessionManager.getSessionPropertyHandler();

        // URL僞僀僾偺愝掕
        String urlType = filterConfig.getInitParameter(PARAM_REFERER_FORMAT);
        setReferrerFormatShort(false);
        if (urlType != null && urlType.equalsIgnoreCase("short")) {
            setReferrerFormatShort(true);
        }

        // 僙僉儏儕僥傿奼挘巕偺愝掕
        String secureExt = filterConfig.getInitParameter(PARAM_SECURITY_EXT);
        if (secureExt == null || secureExt.equals("")) {
            this.securityExt = null;
        } else {
            this.securityExt = secureExt;
        }
    }

    /**
     * intra-mart偐傜棃傞儕僋僄僗僩傪im-J2EE Framework偱埖偆宍幃偵曄姺偟傑偡丅
     *
     * @param servletRequest 儕僋僄僗僩
     * @param servletResponse 儗僗億儞僗
     * @param filterChain 僼傿儖僞僠僃僀儞
     * @throws IOException 僼傿儖僞張棟幚峴帪偵IOException偑敪惗
     * @throws ServletException 僼傿儖僞張棟幚峴帪偵ServletException偑敪惗
     */
    public void doFilter(
        ServletRequest servletRequest,
        ServletResponse servletResponse,
        FilterChain filterChain)
        throws IOException, ServletException {

        HttpServletRequest request = (HttpServletRequest)servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;

        String loginUserIDKey = null;
        String loginUserID = null;
        String loginGroupIDKey = null;
        String loginGroupID = null;
        String errorPage = null;
        String application = null;
        String service = null;

        // 傾僾儕働乕僔儑儞ID偲僒乕價僗ID偺庢摼
        IntramartConnectUtil.RequestInfo requestInfo =
            IntramartConnectUtil.getRequestInfo(request, response);
        application = requestInfo.getApplication();
        service = requestInfo.getService();

        // 儘僌僀儞儐乕僓ID傪庢摼
        try {
            loginUserIDKey = this.sessionHandler.getLoginUserIDKey();
        } catch (SessionPropertyException e) {
            throw new ServletException(e.getMessage(), e);
        }
        loginUserID = request.getParameter(PARAM_LOGIN_USER_ID);
        if (loginUserID == null || loginUserID.equals("")) {
            // 儘僌僀儞儐乕僓偑愝掕偝傟偰偄側偄応崌丄僙僢僔儑儞僄儔乕儁乕僕偵慗堏
            try {
                errorPage = this.sessionHandler.getSessionErrorPagePath();
            } catch (SessionPropertyException e) {
                throw new ServletException(e.getMessage(), e);
            }
            request.getRequestDispatcher(errorPage).forward(request, response);

            return;
        }

        // 儘僌僀儞僌儖乕僾ID傪庢摼
        try {
            loginGroupIDKey =
                SessionManager
                    .getSessionManager()
                    .getSessionPropertyHandler()
                    .getLoginGroupIDKey();
        } catch (Exception e) {
            throw new ServletException(e.getMessage(), e);
        }
        loginGroupID = request.getParameter(PARAM_LOGIN_GROUP_ID);
        if (loginGroupID == null || loginGroupID.equals("")) {
            // 儘僌僀儞僌儖乕僾偑愝掕偝傟偰偄側偄応崌丄僙僢僔儑儞僄儔乕儁乕僕偵慗堏
            try {
                errorPage = this.sessionHandler.getSessionErrorPagePath();
            } catch (SessionPropertyException e) {
                throw new ServletException(e.getMessage(), e);
            }
            request.getRequestDispatcher(errorPage).forward(request, response);

            return;
        }

        // 僙僢僔儑儞僆僽僕僃僋僩傪儕僋僄僗僩傪傕偲偵庢摼丒惗惉
        boolean sessionCreated =
            IntramartConnectUtil.configSession(
                request,
                response,
                loginUserIDKey,
                loginUserID,
                loginGroupIDKey,
                loginGroupID,
                isReferrerFormatShort());
        if (!sessionCreated) {
            // 僙僢僔儑儞偺惗惉偵幐攕偟偨応崌壗傕偟側偄偱廔椆
            return;
        }

        // 傾僾儕働乕僔儑儞ID僷儔儊乕僞柤偺庢摼
        String applicationParamName = null;
        try {
            applicationParamName =
                this.serviceHandler.getApplicationParamName();
        } catch (Exception e) {
            throw new ServletException(e.getMessage(), e);
        }

        // 僒乕價僗ID僷儔儊乕僞柤偺庢摼
        String serviceParamName = null;
        try {
            serviceParamName = this.serviceHandler.getServiceParamName();
        } catch (Exception e) {
            throw new ServletException(e.getMessage(), e);
        }

        // 儕僋僄僗僩傪惗惉
        IntramartConnectRequest newRequest =
            new IntramartConnectRequest(
                request,
                applicationParamName,
                application,
                serviceParamName,
                service);

        // 僙僉儏儕僥傿偑桳岠偺応崌僼儔僌傪愝掕
        if (getSecurityExt() != null) {
            newRequest.setAttribute(
                ServiceSecurityFilter.ID_SERVICE_SECURITY_FILTER,
                getSecurityExt());
        }

        filterChain.doFilter(newRequest, response);
    }

    /**
     * 僼傿儖僞傪攋婞偟傑偡丅
     */
    public void destroy() {
        this.filterConfig = null;

        // 僒乕價僗儅僱乕僕儍偺愝掕
        this.serviceManager = null;

        // 僒乕價僗僾儘僷僥傿僴儞僪儔偺愝掕
        this.serviceHandler = null;

        // 僙僢僔儑儞儅僱乕僕儍偺愝掕
        this.sessionManager = null;

        // 僙僢僔儑儞僾儘僷僥傿僴儞僪儔偺愝掕
        this.sessionHandler = null;
    }
}

⌨️ 快捷键说明

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