在Websphere 6.1中强制使用Https
时间:2020-03-06 14:43:01 来源:igfitidea点击:
我想知道如何强制使用Http请求页面的用户使用安全的https版本?
我正在使用Websphere 6.1作为我的应用程序服务器,并使用Rad 7作为我的开发环境。
谢谢
达米安
解决方案
Websphere不是完整的http服务器。它确实具有"传输链",其作用类似于HTTP Server。
通常,我们会将HTTP服务器放在前面。 IBM提供了IHS(IBM HTTP Server),它是经过轻微修改的Apache HTTP Server。 HTTP服务器使用httpd.conf文件配置。在此处,我们可以通过以下方式添加重定向:将对http的请求重定向到https。
也许我们可以提供一些有关基础架构的详细信息。
我们可以在应用程序中而不是在服务器配置中执行此操作的一种方法是使用过滤器(在web.xml中指定)检查ServletRequest.getScheme()是" http"还是" https",并且将用户重定向到适当的URL(使用HttpServletResponse.sendRedirect(String url))。
我同意。我认为使用过滤器可以实现这一目标。这是我为负载平衡和端口重定向编写的过滤器,但应该很容易弄清楚如何对其进行编辑以满足需求。
公共类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;
}
}
}

