博客详情

shiro集成web (原创)

作者: 朝如青丝暮成雪
发布时间:2019-03-25 10:56:55  文章分类:shiro   阅读(1007)  评论(0)

一、shiro集成web的步骤

参考 http://shiro.apache.org/web.html


1、在pom.xml中引入 shro-web.jar

<!-- shiro-web引入  -->
    <dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>1.3.2</version>
</dependency>


2、web.xml中配置shiro的监听器和过滤器

<!--shiro web环境监听器 -->
<listener>
    <listener-class >org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
<!-- 添加shiro 过滤器 -->
<filter>
    <filter-name>ShiroFilter</filter-name>
    <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>ShiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>
  


3、在classpath或/WEB-INF/目录中配置shiro.ini文件。 例如:


[main]
authc.loginUrl=/login
roles.unauthorizedUrl=/unauthorized
perms.unauthorizedUrl=/unauthorized

[users]
zhangsan=zs123456,student
lisi=ls123456,teacher

[roles]
student=student:*
teacher=teacher:*

[urls]
#webapp中的静态资源(js、css、img等)可以直接访问
/resources/**=anon
/login=anon
/logout=logout
#/student/**=roles[student]
#/teacher/**=roles[teacher]
/student/**=perms[student:*]
/teacher/**=perms[teacher:*]
/**=authc


另,log4j.properties配置(可选)


#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
log4j.rootLogger=INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m %n

# General Apache libraries
log4j.logger.org.apache=WARN

# Spring
log4j.logger.org.springframework=WARN

# Default Shiro logging
log4j.logger.org.apache.shiro=TRACE

# Disable verbose logging
log4j.logger.org.apache.shiro.util.ThreadContext=WARN
log4j.logger.org.apache.shiro.cache.ehcache.EhCache=WARN



二、shiro集成web示例代码

参考 gitee仓库

https://gitee.com/mmxl/shiroWeb.git 




关键字:  shiro  web
评论信息
暂无评论
发表评论

亲,您还没有登陆,暂不能评论哦! 去 登陆 | 注册

博主信息
   
数据加载中,请稍候...
文章分类
   
数据加载中,请稍候...
阅读排行
 
数据加载中,请稍候...
评论排行
 
数据加载中,请稍候...

Copyright © 叮叮声的奶酪 版权所有
备案号:鄂ICP备17018671号-1

鄂公网安备 42011102000739号