سؤال

كنت أتساءل كيف يمكن أن تجبر المستخدم الذي لديه طلب صفحة باستخدام Http الاستخدام الآمن https الإصدار ؟

أنا باستخدام Websphere 6.1 بلدي "ملقم التطبيق" و راد 7 بلدي بيئة التطوير

شكرا داميان

هل كانت مفيدة؟

المحلول

طريقة واحدة يمكنك أن تفعل هذا في التطبيق الخاص بك بدلا من تكوين الملقم سيتم استخدام فلتر (المحدد في web.xml) للتحقق مما إذا ServletRequest.getScheme() هو "http" أو "https" ، وإعادة توجيه المستخدم إلى عنوان URL المناسب (باستخدام HttpServletResponse.sendRedirect(String url)).

نصائح أخرى

يمكنك إضافة الإدخال التالي في ملف web.xml وسوف تأكد من أن جميع الطلبات يتم تحويلها إلى https

<!--********************************
   *** SSL Security Constraint  ***
   *****************************-->
   <security-constraint>
       <web-resource-collection>
           <web-resource-name>SSL</web-resource-name>
           <url-pattern>/*</url-pattern>
       </web-resource-collection>
       <user-data-constraint>
           <transport-guarantee>CONFIDENTIAL</transport-guarantee>
       </user-data-constraint>
   </security-constraint>

<!--********************************* -->

Websphere ليست كاملة http server.فإنه لا يكون 'النقل سلاسل', التي تعمل مثل ملقم HTTP.

عادة سوف أضع HTTP server في الجبهة.IBM تقدم IHS (IBM HTTP Server) وهو بخفة تعديل Apache HTTP Server.HTTP ملقم تم تكوينه مع httpd.الملف conf.هناك يمكنك إضافة عمليات إعادة التوجيه في مثل هذه الطريقة التي طلب يتم إعادة توجيه http إلى https.

ربما كنت يمكن أن تعطي معلومات مفصلة عن البنية التحتية الخاصة بك.

وأنا أتفق.أعتقد أن استخدام فلتر تحقيق ذلك.هنا هو مرشح كتبت من أجل موازنة تحميل توجيه منفذ ولكن ينبغي أن يكون من السهل معرفة كيفية تعديلها لتناسب احتياجاتك.

الطبقة العامة RequestWrapperFilter تنفذ تصفية {

public void doFilter(ServletRequest servletRequest,
        ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {

    HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
    HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;

    String requestWrapperClassName = (String) (httpRequest
            .getAttribute(LoadBalancerRequestWrapper.class.getName()));

    String initiatingServerName = httpRequest.getServerName();

    if (requestWrapperClassName == null
            && initiatingServerName.equals(loadBalancerHostName)) {

        httpRequest = new LoadBalancerRequestWrapper(AuthenticationUtil
                .getHttpServletRequest(httpRequest));
    }

    filterChain.doFilter(httpRequest, httpResponse);
}

}

/**
 * The custom implementation of the request wrapper. It simply overrides the
 * getScheme() and getServerPort() methods to perform the redirect
 * filtering.
 * 
 * 
 */
private static class LoadBalancerRequestWrapper extends
        HttpServletRequestWrapper {

    /**
     * Default Constructor. Simply declares the Wrapper as injected.
     * 
     * @param httpServletRequest
     *            the app-server HttpServletRequest.
     * 
     */
    public LoadBalancerRequestWrapper(HttpServletRequest httpServletRequest) {
        super(httpServletRequest);
    }

    /**
     * The overridden scheme.
     * 
     */
    public final String getScheme() {
        if (loadBalancerHttpScheme.equals(EMPTY_STRING)) {
            return super.getScheme();
        }

        return loadBalancerHttpScheme;
    }
}

}

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top