您的位置:首页 > 理论基础 > 计算机网络

项目登陆使用https,其他使用http的方式一点尝试

2014-10-09 15:21 387 查看
由于项目需要,在登录的时候需要使用https对用户的数据进行加密,登录完后跳转的其他页面时使用http方式访问;

根据项目实际使用的安全框架shiro,在网上查了很多资料,使用步骤如下:

1.在tomcat中server.xml中配置ssl,可以默认使用443端口

生成一个keystore文件,后面配置tomcat会用到

<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />

<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" keystoreFile="D:\localhost.keystore" keystorePass="123456"/>

<Connector port="8009" protocol="AJP/1.3" redirectPort="443" />
2.使用shiro对登陆路径进行过滤

在spring_shiro.xml中增加

<bean id="sslFilter" class="org.apache.shiro.web.filter.authz.SslFilter">
<property name="port" value="443"/>
</bean>


在shiro主过滤器配置中新增
<property name="filters">
<map>
......
<entry key="ssl" value-ref="sslFilter"/>
<span style="white-space:pre">		</span>......
</map>
</property>
在过滤链中配置路径过滤

login/login=ssl

这样就保证在点击登陆时使用https访问

3.在登陆完后怎么重定向到http且session不丢失呢

重定向时,需要重新把sessionId重新放到cookie中,具体原因可查https http 跨域的问题
Cookie cookie = new Cookie("JSESSIONID", request.getSession().getId());
cookie.setPath(request.getContextPath());
response.addCookie(cookie);
这样就可登录使用https,其他链接使用http
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐