目录贴: 跟我学Shiro目录贴
对于SSL的支持,Shiro只是判断当前url是否需要SSL登录,如果需要自动重定向到https进行访问。
首先生成数字证书,生成证书到D:\localhost.keystore
使用JDK的keytool命令,生成证书(包含证书/公钥/私钥)到D:\localhost.keystore:
keytool -genkey -keystore "D:\localhost.keystore" -alias localhost -keyalg RSA
输入密钥库口令:
再次输入新口令:
您的名字与姓氏是什么?
[Unknown]: localhost
您的组织单位名称是什么?
[Unknown]: sishuok.com
您的组织名称是什么?
[Unknown]: sishuok.com
您所在的城市或区域名称是什么?
[Unknown]: beijing
您所在的省/市/自治区名称是什么?
[Unknown]: beijing
该单位的双字母国家/地区代码是什么?
[Unknown]: cn
CN=localhost, OU=sishuok.com, O=sishuok.com, L=beijing, ST=beijing, C=cn是否正确
?
[否]: y
输入 <localhost> 的密钥口令
(如果和密钥库口令相同, 按回车):
再次输入新口令:
通过如上步骤,生成证书到D:\ localhost.keystore;
然后设置tomcat下的server.xml
此处使用了apache-tomcat-7.0.40版本,打开conf/server.xml,找到:
<!-- <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" /> -->
替换为
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="D:\localhost.keystore" keystorePass="123456"/>
keystorePass就是生成keystore时设置的密码。
添加SSL到配置文件(spring-shiro-web.xml)
此处使用了和十三章一样的代码:
<bean id="sslFilter" class="org.apache.shiro.web.filter.authz.SslFilter"> <property name="port" value="8443"/> </bean> <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> …… <property name="filters"> <util:map> <entry key="authc" value-ref="formAuthenticationFilter"/> <entry key="ssl" value-ref="sslFilter"/> </util:map> </property> <property name="filterChainDefinitions"> <value> /login.jsp = ssl,authc /logout = logout /authenticated.jsp = authc /** = user </value> </property> </bean>
SslFilter默认端口是443,此处使用了8443;“/login.jsp = ssl,authc”表示访问登录页面时需要走SSL。
测试
最后把shiro-example-chapter14打成war包(mvn:package),放到tomcat下的webapps中,启动服务器测试,如访问localhost:9080/chapter14/,会自动跳转到https://localhost:8443/chapter14/login.jsp。
如果使用Maven Jetty插件,可以直接如下插件配置:
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.8.v20121106</version> <configuration> <webAppConfig> <contextPath>/${project.build.finalName}</contextPath> </webAppConfig> <connectors> <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> <port>8080</port> </connector> <connector implementation="org.eclipse.jetty.server.ssl.SslSocketConnector"> <port>8443</port> <keystore>${project.basedir}/localhost.keystore</keystore> <password>123456</password> <keyPassword>123456</keyPassword> </connector> </connectors> </configuration> </plugin>
示例源代码:https://github.com/zhangkaitao/shiro-example;可加群 231889722 探讨Spring/Shiro技术。
请你欣赏春天美景 http://user.qzone.qq.com/314154083/photo/V10a4ot72FxYVR?ptlang=2052
相关推荐
第十七章 OAuth2集成——《跟我学Shiro》 - 开涛的博客 - IT...第1页 共13页本文把授权服务器和资源服务器整合在一起实现。依赖此处我们使用a
跟我学Shiro
跟我学shiro学习资料。
跟我学Shiro跟我学Shiro
***txt文件中含有下载地址** 《跟我学Shiro》- 张开涛,PDF版本,带目录,清晰。 示例源代码:https://github.com/zhangkaitao/shiro-example; 加qun 231889722 探讨Spring/Shiro技术。
This compressed file is a detailed description of Shiro
Apache Shiro是一个强大易用的Java安全框架,...我找了一版 跟我学Shiro教程PDF,里面讲的很详细.里面还附带了每个章节的源码.值得你收藏哟!饮水思源——原文出自:http://jinnianshilongnian.iteye.com/blog/2049092
《跟我学Shiro》PDF完结版下载, Apache Shiro是Java的一个安全框架。目前,使用Apache Shiro的人越来越多,因为它相当简单,对比Spring Security,可能没有Spring Security做的功能强大,但是在实际工作时可能并不...
张开涛
本资源包含: Apache_Shiro参考手册中文版.pdf; Shiro教程.pdf; shrio-example.rar; 跟我学Shiro教程.zip
跟我学Shiro源码
Apache Shiro 是 Java 的一个安全框架。目前,使用 Apache Shiro 的人越来越多,因为它相当简单,对比 Sp ring Security,可能没有 Spring Security 做的功能强大,但是在实际工作时可能并不需要那么复杂的东西,所 ...
Shiro是一个Java平台的开源权限框架,用于认证和访问授权
使用新版springboot改写跟我学shiro第16章源码。 springboot+shiro+jsp整合
跟我一起学shiro张开涛,含PDF及源码,入门shiro的最好书籍。
跟我学Shiro第11章Demo,本人亲自编写,完全可运行,运用了Shiro提供的Cache缓存和Session缓存两大部分,大家慢慢品尝。。
Apache Shiro 是一个框架,可用于身份验证和授权,是一个简单易学的框架,跟我学shiro详细讲解了shiro的开发,这里是该书的全部源代码