shiro
url拦截规则:
anno:匿名过滤器,表示通过了url配置的资源都可以访问
authc:基于表单的过滤器,表示通过了url配置的资源需要登陆验证,否则跳转到登陆
jfinal结合shiro:
- 导入依赖
- 在web.xml中加入配置
<listener>
<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
<context-param>
<param-name>shiroConfigLocations</param-name>
<param-value>classpath:shiro_plat.ini</param-value>
</context-param>
<filter>
<filter-name>shiro</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>shiro</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
- 在resource下创建 xxx.ini文件,进行shiro的配置
[main]
[urls] - 创建自己的 Realm 继承 AuthorizingRealm,重写认证与权限方法
在认证方法中会获得用户名和密码【shiro默认使用input的name为username与password】 - 拦截器【继承WebConfigListener 重写 onFixedInterceptorConfig 将我们自定义的shiro加入】
@Override
public void onFixedInterceptorConfig(FixedInterceptors fixedInterceptors) {
super.onFixedInterceptorConfig(fixedInterceptors);
fixedInterceptors.add(new 自定义shiro拦截器());
}