询问下各位大牛,我想用Shiro实现对IP地址的拦截,然后做一个白名单和黑名单,能给个思路或者代码片段吗?
可以参考这篇文章的黑白名单实现方式,将其url换成ip地址。http://jinnianshilongnian.iteye.com/blog/1663481
使用Shiro安全框架只需要关注两部分:
1,如何获得subject
2.如何获得一个符合要求的Reaml域(密码比较器也是需要我们写的)
具体实现:
1.编写一个applicationContext-shiro.xml配置文件
2.这个是白名单和黑名单的结合:当等号后是anno时表示白名单,当等号后是authc时表示是黑名单,需要验证
<!-- filter-name这个名字的值来自于web.xml中filter的名字 -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<!--登录页面 -->
<property name="loginUrl" value="/index.jsp"></property>
<!-- 登录成功后 -->
<property name="successUrl" value="/home.action"></property>
<property name="filterChainDefinitions">
<!-- /**代表下面的多级目录也过滤 -->
<value>
/index.jsp* = anon
/home* = anon
/sysadmin/login/login.jsp* = anon
/sysadmin/login/logout.jsp* = anon
/login* = anon
/logout* = anon
/components/** = anon
/css/** = anon
/images/** = anon
/js/** = anon
/make/** = anon
/skin/** = anon
/stat/** = anon
/ufiles/** = anon
/validator/** = anon
/resource/** = anon
/sysadmin/deptAction_* = perms["部门管理"]
/** = authc
/*.* = authc
</value>
</property>
</bean>