HTTP自动跳转至HTTPS

xiaoxiao2021-03-01  71

方法一:在应用项目中修改web.xml,增加授权区。 web.xml: <!-- 所有链接自动跳转到https --> <security-constraint> <web-resource-collection> <web-resource-name>sslapp</web-resource-name> <url-pattern>/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint> 以上这种方式,会导致在IE中无法下载xls\swf等文件,但在firefox中没有问题 方法二:是在用户登录时,用acegi配置处理,强制使用https 项目中的welcome file:index.jsp跳转至一个不允许匿名访问的地址,index.jsp如下列: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><html><head><script> function redirect() { self.location='menu/homepage.jsp'; } redirect();</script></head></html> 而在验证配置中,允许匿名(未登录)访问的只有login.jsp <bean id="filterInvocationInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor"> <property name="authenticationManager" ref="authenticationManager"/> <property name="accessDecisionManager"> <bean class="org.acegisecurity.vote.UnanimousBased"> <property name="allowIfAllAbstainDecisions" value="true"/> <property name="decisionVoters"> <list> <ref local="authService"/> <bean class="org.acegisecurity.vote.AuthenticatedVoter"/> </list> </property> </bean> </property> <property name="objectDefinitionSource"> <value> <!-- CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON--> PATTERN_TYPE_APACHE_ANT /login.jsp=IS_AUTHENTICATED_ANONYMOUSLY /**=IS_AUTHENTICATED_REMEMBERED </value> </property> </bean> 所以用户在未登录情况下所进行的连接均会经过exceptionTranslationFilter <bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter"> <property name="authenticationEntryPoint"> <bean class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint"> <property name="loginFormUrl" value="/login.jsp"/> <property name="forceHttps" value="true"/> </bean> </property> <property name="accessDeniedHandler"> <bean class="org.acegisecurity.ui.AccessDeniedHandlerImpl"> <property name="errorPage" value="/403.jsp"/> </bean> </property> </bean> 因为[color=red]forceHttps=true[/color],所以会直接连接到https的登录界面,登录后将会一直使用的是http连接 此种情况只有在用户登录后,又手动输入http连接的情况下无法跳转至https 此种方式在用户登录后的页面中如果存在非https的链接,IE可能会提示下列信息: “是否只查看安全传送的网页内容?网页包含的内容将不使用安全的https连接传送,可能危及到整个网页的安全” 遇到上述IE的提示时,对IE进行以下设置即不会再出现提示: 在IE中选择“工具”-->"Internet选项"-->“安全”-->“自定义安全级别”-->在“其他”分类里找到“显示混合内容”选“启用”即可。(可参见附件)
转载请注明原文地址: https://www.6miu.com/read-4150261.html

最新回复(0)