【问题标题】:Force Https in Websphere 6.1在 Websphere 6.1 中强制使用 Https
【发布时间】:2008-09-25 12:12:10
【问题描述】:

我想知道如何强制使用 Http 请求页面的用户使用安全的 https 版本?

我使用 Websphere 6.1 作为我的应用服务器,使用 Rad 7 作为我的开发环境

谢谢 达米安

【问题讨论】:

    标签: servlets https websphere rad


    【解决方案1】:

    您可以在应用程序中而不是在服务器配置中执行此操作的一种方法是使用Filter(在您的 web.xml 中指定)来检查 ServletRequest.getScheme() 是“http”还是“https”,并将用户重定向到适当的 URL(使用HttpServletResponse.sendRedirect(String url))。

    【讨论】:

      【解决方案2】:

      您可以在 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>
      
      <!--********************************* -->
      

      【讨论】:

        【解决方案3】:

        Websphere 不是一个完整的 http 服务器。它确实有“传输链”,就像一个 HTTP 服务器。

        通常您会在前面放置一个 HTTP 服务器。 IBM 提供了 IHS(IBM HTTP Server),它是一个经过轻微修改的 Apache HTTP Server。 HTTP 服务器使用 httpd.conf 文件进行配置。您可以在其中添加重定向,以便将 http 请求重定向到 https。

        也许您可以提供一些有关您的基础架构的详细信息。

        【讨论】:

          【解决方案4】:

          我同意。我认为使用过滤器可以实现这一点。这是我为负载平衡和端口重定向编写的过滤器,但应该很容易弄清楚如何对其进行编辑以满足您的需求。

          公共类 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;
              }
          }
          

          }

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2012-08-01
            • 2012-08-22
            • 2020-12-11
            • 2021-06-24
            • 2016-05-07
            • 2019-05-25
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多