精华内容
下载资源
问答
  • 实现过程 1.创建角色、权限表及它们之间的关系中间表 角色: 权限: 关系: 2.在配置文件当中添加Shiro注解扫描 <!-- 配置为true即使用cglib继承的方式, false为jdk的接口动态...

    当我们在控制器方法写了 @RequiresPermissions

    Shiro在访问时, 就会判断有没有该权限,如果没有,就不会执行对应方法

     

    实现过程

    1.创建角色、权限表及它们之间的关系中间表

    角色:

    权限:

    关系:

    2.在配置文件当中添加Shiro注解扫描

    <!--
        配置为true即使用cglib继承的方式,
        false为jdk的接口动态代理   控制器没有实现接口
    -->
    <aop:config proxy-target-class="true" ></aop:config>
    
    <!-- 使用第三方去扫描shiro的注解 -->
    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor ">
        <property name="securityManager" ref="securityManager"></property>
    </bean>
    

    3.在Realm中添加授权信息

    // 授权
    // 1.发现访问路径的方法上面有授权的注解,就会调用这个方法
    // 2.页面当中有授权的标签,也会调用这个方法
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        // 获取用户的身份信息
        Employee employee = (Employee) principalCollection.getPrimaryPrincipal();
        // 根据当前角色查询权限
        List<String> roles = new ArrayList<>();
        List<String> permissions = new ArrayList<>();
        // 判断当前用是不是管理员,如果是管理员,拥有所有权限
        if(employee.getAdmin()){
            // 拥有所有权限
            permissions.add("*:*");
        }else{
            // 查询角色
            roles = employeeService.getRolesById(employee.getId());
            // 查询权限
            permissions = employeeService.getPermissionById(employee.getId());
        }
        // 给授权信息
        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
        info.addRoles(roles);
        info.addStringPermissions(permissions);
        return info;
    }
    

     

    没有权限处理方法

    1.请求

    @RequestMapping("/employee")
    @RequiresPermissions("employee:index")
    public String employee(){
        return "employee";
    }

    2.如果没有权限,在Controller里添加方法

    @ExceptionHandler(AuthorizationException.class)
    public void handleShiroException(HandlerMethod method,HttpServletResponse response) throws Exception{ // method  发生异常的方法
        // 跳转到一个界面界面提示没有权限
        // 判断当前的请求是不是Json请求,如果是 返回json给浏览器,让它自己来做跳转
        // 因为Ajax请求没有办法跳转服务当中的请求,只能通过浏览器当中来跳转
        // 获取方法上的注解,有ResponseBody注解就是Ajax请求
        ResponseBody methodAnnotation = method.getMethodAnnotation(ResponseBody.class);
        if (methodAnnotation != null){
            //Ajax
            AjaxRes ajaxRes = new AjaxRes();
            ajaxRes.setSuccess(false);
            ajaxRes.setMsg("你没有权限操作");
            String s = new ObjectMapper().writeValueAsString(ajaxRes);
            response.setCharacterEncoding("utf-8");
            response.getWriter().print(s);
        }else {
            // 重定向
            response.sendRedirect("nopermission.jsp");
        }
    }
    

    页面一些按钮权限处理

    ①在页面引入Shiro标签库(HTML页面可以通过thymeleaf来引入)

    <%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>

    ②在需要权限控制的地方添加对应的shiro标签

    <shrio:hasPermission name="employee:add">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" id="add">添加</a>
    </shrio:hasPermission>
    <shrio:hasPermission name="employee:edit">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" id="edit">编辑</a>
    </shrio:hasPermission>
    <shrio:hasPermission name="employee:delete">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" id="delete">离职</a>
    </shrio:hasPermission>
    

     

     

    展开全文
  • 1.我们先建一个maven项目,如图: 2.在pom.xml中添加如下依赖: &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.shiro&lt;/groupId&gt; &lt;...

    1.我们先建一个maven项目,如图:

    2.在pom.xml中添加如下依赖:

    <dependencies>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <version>1.4.0</version>
        </dependency>
    
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>RELEASE</version>
        </dependency>
    </dependencies>

    3.创建一个user.ini文件,该文件保存用户基本信息和权限信息,user.ini的基本信息如下:

    [users]
    \#提供了对用户/密码及其角色的配置,用户名=密码,角色1,角色2
    root=123456,admin
    [roles]
    \#提供了角色及权限之间关系的配置,角色=权限1,权限2
    admin=user:delete

    4.现在正式开始编码,包括检查登陆认证、含有权限,代码如下:

    package com.wkf;
    
    import org.apache.shiro.SecurityUtils;
    import org.apache.shiro.authc.UsernamePasswordToken;
    import org.apache.shiro.mgt.DefaultSecurityManager;
    import org.apache.shiro.realm.text.IniRealm;
    import org.apache.shiro.subject.Subject;
    import org.junit.Test;
    
    /**
     * 使用内置IniRealm类读取用户
     * @author wkf
     */
    public class IniRealmTest {
    
        @Test
        public void testAuthentication(){
    
            IniRealm iniRealm = new IniRealm("classpath:user.ini");//读取用户信息文件,IniRealm类:用户信息存储类
    
            //1.构建SecurityManager环境
            DefaultSecurityManager defaultSecurityManager = new DefaultSecurityManager();
            defaultSecurityManager.setRealm(iniRealm);
            //2.主体提交认证请求
            SecurityUtils.setSecurityManager(defaultSecurityManager);
            Subject subject = SecurityUtils.getSubject();
    
            UsernamePasswordToken token = new UsernamePasswordToken("root","123456");
            subject.login(token);//登陆认证
    
            System.out.println("认证结果:"+subject.isAuthenticated());
    
            subject.checkRole("admin");//检查角色授权(必须登陆认证后才行)
    
            subject.checkPermission("user:delete");//检查角色权限
    
        }
    }
    
    展开全文
  • 基于Maven+SSM整合shiro+Redis实现后台管理项目基于Maven+SSM整合shiro+Redis实现后台管理项目
  • 最近项目需要进行高要求的Web权限管理,在比较Spring security和Shiro之后由于Shiro更大的灵活度和更强的配置性选择了Shiro。 不过官方的文档写的对于集成spring不太清楚,尤其是Realm怎样实现。 因此,在查阅一...

    最近项目需要进行高要求的Web权限管理,在比较Spring security和Shiro之后由于Shiro更大的灵活度和更强的配置性选择了Shiro。

    不过官方的文档写的对于集成spring不太清楚,尤其是Realm怎样实现。

    因此,在查阅一系列资料之后,将目前集成的步骤总结出来。

    特别推荐博文:http://www.cnblogs.com/xql4j/archive/2013/03/30/2990841.html,此文对作者帮助极大,在此表示感谢!


    具体步骤抽象:




    修改配置文件:

    首先是pom.xml
    1. <!-- Version of jars -->  
    2.     <properties>  
    3.         <spring.version>3.2.3.RELEASE</spring.version>  
    4.         <hibernate.version>4.2.3.Final</hibernate.version>  
    5.         <slf4j.version>1.7.5</slf4j.version>  
    6.         <log4j.version>1.2.17</log4j.version>  
    7.         <junit.version>4.11</junit.version>  
    8.         <cglib.version>3.0</cglib.version>  
    9.         <velocity.version>1.7</velocity.version>  
    10.         <tiles.extras.version>3.0.1</tiles.extras.version>  
    11.         <jsonlib.version>2.4</jsonlib.version>  
    12.         <shiro.version>1.2.2</shiro.version>  
    13.     </properties>  
    14.   
    15.     <dependencies>  
    16.   
    17.         <!-- Spring jars -->  
    18.         <dependency>  
    19.             <groupId>org.springframework</groupId>  
    20.             <artifactId>spring-core</artifactId>  
    21.             <version>${spring.version}</version>  
    22.             <exclusions>  
    23.                 <exclusion>  
    24.                     <groupId>commons-logging</groupId>  
    25.                     <artifactId>commons-logging</artifactId>  
    26.                 </exclusion>  
    27.             </exclusions>  
    28.         </dependency>  
    29.         <dependency>  
    30.             <groupId>org.springframework</groupId>  
    31.             <artifactId>spring-beans</artifactId>  
    32.             <version>${spring.version}</version>  
    33.             <exclusions>  
    34.                 <exclusion>  
    35.                     <groupId>commons-logging</groupId>  
    36.                     <artifactId>commons-logging</artifactId>  
    37.                 </exclusion>  
    38.             </exclusions>  
    39.         </dependency>  
    40.         <dependency>  
    41.             <groupId>org.springframework</groupId>  
    42.             <artifactId>spring-context</artifactId>  
    43.             <version>${spring.version}</version>  
    44.             <exclusions>  
    45.                 <exclusion>  
    46.                     <groupId>commons-logging</groupId>  
    47.                     <artifactId>commons-logging</artifactId>  
    48.                 </exclusion>  
    49.             </exclusions>  
    50.         </dependency>  
    51.         <dependency>  
    52.             <groupId>org.springframework</groupId>  
    53.             <artifactId>spring-web</artifactId>  
    54.             <version>${spring.version}</version>  
    55.             <exclusions>  
    56.                 <exclusion>  
    57.                     <groupId>commons-logging</groupId>  
    58.                     <artifactId>commons-logging</artifactId>  
    59.                 </exclusion>  
    60.             </exclusions>  
    61.         </dependency>  
    62.         <dependency>  
    63.             <groupId>org.springframework</groupId>  
    64.             <artifactId>spring-test</artifactId>  
    65.             <version>${spring.version}</version>  
    66.             <scope>test</scope>  
    67.             <exclusions>  
    68.                 <exclusion>  
    69.                     <groupId>commons-logging</groupId>  
    70.                     <artifactId>commons-logging</artifactId>  
    71.                 </exclusion>  
    72.             </exclusions>  
    73.         </dependency>  
    74.         <dependency>  
    75.             <groupId>org.springframework</groupId>  
    76.             <artifactId>spring-aop</artifactId>  
    77.             <version>${spring.version}</version>  
    78.         </dependency>  
    79.         <dependency>  
    80.             <groupId>org.springframework</groupId>  
    81.             <artifactId>spring-webmvc</artifactId>  
    82.             <version>${spring.version}</version>  
    83.         </dependency>  
    84.         <dependency>  
    85.             <groupId>org.springframework</groupId>  
    86.             <artifactId>spring-context-support</artifactId>  
    87.             <version>${spring.version}</version>  
    88.         </dependency>  
    89.         <dependency>  
    90.             <groupId>org.springframework</groupId>  
    91.             <artifactId>spring-orm</artifactId>  
    92.             <version>${spring.version}</version>  
    93.             <type>jar</type>  
    94.             <scope>compile</scope>  
    95.         </dependency>  
    96.         <dependency>  
    97.             <groupId>org.springframework</groupId>  
    98.             <artifactId>spring-jdbc</artifactId>  
    99.             <version>${spring.version}</version>  
    100.             <type>jar</type>  
    101.             <scope>runtime</scope>  
    102.         </dependency>  
    103.         <dependency>  
    104.             <groupId>taglibs</groupId>  
    105.             <artifactId>standard</artifactId>  
    106.             <version>1.1.2</version>  
    107.         </dependency>  
    108.         <dependency>  
    109.             <groupId>javax.servlet</groupId>  
    110.             <artifactId>jstl</artifactId>  
    111.             <version>1.2</version>  
    112.         </dependency>  
    113.         <dependency>  
    114.             <groupId>commons-io</groupId>  
    115.             <artifactId>commons-io</artifactId>  
    116.             <version>2.1</version>  
    117.         </dependency>  
    118.         <!-- end of Spring jars -->  
    119.   
    120.         <!-- Shiro security -->  
    121.         <dependency>  
    122.             <groupId>org.apache.shiro</groupId>  
    123.             <artifactId>shiro-core</artifactId>  
    124.             <version>${shiro.version}</version>  
    125.         </dependency>  
    126.         <dependency>  
    127.             <groupId>org.apache.shiro</groupId>  
    128.             <artifactId>shiro-web</artifactId>  
    129.             <version>${shiro.version}</version>  
    130.         </dependency>  
    131.         <dependency>  
    132.             <groupId>org.apache.shiro</groupId>  
    133.             <artifactId>shiro-cas</artifactId>  
    134.             <version>${shiro.version}</version>  
    135.         </dependency>  
    136.         <dependency>  
    137.             <groupId>org.apache.shiro</groupId>  
    138.             <artifactId>shiro-spring</artifactId>  
    139.             <version>${shiro.version}</version>  
    140.         </dependency>  
    141.         <!-- end of Shiro security -->  
    142.   
    143.         <!-- Json -->  
    144.         <dependency>  
    145.             <groupId>org.codehaus.jackson</groupId>  
    146.             <artifactId>jackson-core-lgpl</artifactId>  
    147.             <version>1.8.1</version>  
    148.         </dependency>  
    149.         <dependency>  
    150.             <groupId>org.codehaus.jackson</groupId>  
    151.             <artifactId>jackson-mapper-lgpl</artifactId>  
    152.             <version>1.8.1</version>  
    153.         </dependency>  
    154.         <dependency>  
    155.             <groupId>net.sf.json-lib</groupId>  
    156.             <artifactId>json-lib</artifactId>  
    157.             <version>${jsonlib.version}</version>  
    158.             <classifier>jdk15</classifier>  
    159.         </dependency>  
    160.         <!-- end of Json -->  
    161.   
    162.         <!-- Hibernate4 -->  
    163.         <dependency>  
    164.             <groupId>org.hibernate</groupId>  
    165.             <artifactId>hibernate-core</artifactId>  
    166.             <version>${hibernate.version}</version>  
    167.         </dependency>  
    168.         <dependency>  
    169.             <groupId>org.hibernate</groupId>  
    170.             <artifactId>hibernate-entitymanager</artifactId>  
    171.             <version>${hibernate.version}</version>  
    172.         </dependency>  
    173.         <dependency>  
    174.             <groupId>javax.xml.bind</groupId>  
    175.             <artifactId>jaxb-api</artifactId>  
    176.             <version>2.1</version>  
    177.             <exclusions>  
    178.                 <exclusion>  
    179.                     <groupId>javax.xml.stream</groupId>  
    180.                     <artifactId>stax-api</artifactId>  
    181.                 </exclusion>  
    182.             </exclusions>  
    183.         </dependency>  
    184.         <dependency>  
    185.             <groupId>com.sun.xml.bind</groupId>  
    186.             <artifactId>jaxb-impl</artifactId>  
    187.             <version>2.1.10</version>  
    188.         </dependency>  
    189.         <dependency>  
    190.             <groupId>org.apache.openejb</groupId>  
    191.             <artifactId>javaee-api</artifactId>  
    192.             <version>5.0-1</version>  
    193.             <!--<scope>provided</scope> -->  
    194.         </dependency>  
    195.         <dependency>  
    196.             <groupId>commons-dbcp</groupId>  
    197.             <artifactId>commons-dbcp</artifactId>  
    198.             <version>1.4</version>  
    199.             <!--<scope>provided</scope> -->  
    200.         </dependency>  
    201.         <!-- end of Hibernate4 -->  
    202.   
    203.         <!-- logging -->  
    204.         <dependency>  
    205.             <groupId>org.slf4j</groupId>  
    206.             <artifactId>slf4j-api</artifactId>  
    207.             <version>${slf4j.version}</version>  
    208.         </dependency>  
    209.         <dependency>  
    210.             <groupId>org.slf4j</groupId>  
    211.             <artifactId>jcl-over-slf4j</artifactId>  
    212.             <version>${slf4j.version}</version>  
    213.         </dependency>  
    214.         <dependency>  
    215.             <groupId>org.slf4j</groupId>  
    216.             <artifactId>slf4j-log4j12</artifactId>  
    217.             <version>${slf4j.version}</version>  
    218.         </dependency>  
    219.         <dependency>  
    220.             <groupId>log4j</groupId>  
    221.             <artifactId>log4j</artifactId>  
    222.             <version>${log4j.version}</version>  
    223.             <!--<scope>provided</scope> -->  
    224.         </dependency>  
    225.         <!-- end of logging -->  
    226.   
    227.         <!-- provided -->  
    228.         <dependency>  
    229.             <groupId>javax.servlet</groupId>  
    230.             <artifactId>servlet-api</artifactId>  
    231.             <version>2.5</version>  
    232.             <scope>compile</scope>  
    233.         </dependency>  
    234.         <dependency>  
    235.             <groupId>cglib</groupId>  
    236.             <artifactId>cglib</artifactId>  
    237.             <version>${cglib.version}</version>  
    238.         </dependency>  
    239.         <dependency>  
    240.             <groupId>javax.servlet.jsp</groupId>  
    241.             <artifactId>jsp-api</artifactId>  
    242.             <version>2.1</version>  
    243.         </dependency>  
    244.         <!-- end of provided -->  
    245.   
    246.         <!-- Test -->  
    247.         <dependency>  
    248.             <groupId>junit</groupId>  
    249.             <artifactId>junit</artifactId>  
    250.             <version>${junit.version}</version>  
    251.             <scope>test</scope>  
    252.         </dependency>  
    253.         <!-- end of Test -->  
    254.   
    255.         <!-- Database -->  
    256.         <dependency>  
    257.             <groupId>com.mchange</groupId>  
    258.             <artifactId>c3p0</artifactId>  
    259.             <version>0.9.5-pre3</version>  
    260.             <type>jar</type>  
    261.             <scope>compile</scope>  
    262.         </dependency>  
    263.         <dependency>  
    264.             <groupId>mysql</groupId>  
    265.             <artifactId>mysql-connector-java</artifactId>  
    266.             <version>5.1.21</version>  
    267.             <type>jar</type>  
    268.             <scope>compile</scope>  
    269.         </dependency>  
    270.         <!-- end of Database -->  
    271.   
    272.         <!-- velocity -->  
    273.         <dependency>  
    274.             <groupId>org.apache.velocity</groupId>  
    275.             <artifactId>velocity</artifactId>  
    276.             <version>${velocity.version}</version>  
    277.         </dependency>  
    278.         <!-- end of velocity -->  
    279.   
    280.         <!-- fileUpload -->  
    281.         <dependency>  
    282.             <groupId>commons-fileupload</groupId>  
    283.             <artifactId>commons-fileupload</artifactId>  
    284.             <version>1.2.2</version>  
    285.         </dependency>  
    286.         <!--io -->  
    287.         <dependency>  
    288.             <groupId>commons-io</groupId>  
    289.             <artifactId>commons-io</artifactId>  
    290.             <version>2.4</version>  
    291.         </dependency>  
    292.         <!-- end of fileUpload -->  
    293.   
    294.         <!-- tiles -->  
    295.         <dependency>  
    296.             <groupId>org.apache.tiles</groupId>  
    297.             <artifactId>tiles-extras</artifactId>  
    298.             <version>${tiles.extras.version}</version>  
    299.             <!-- it will include the rest -->  
    300.         </dependency>  
    301.         <!-- end of tiles -->  
    302.     </dependencies>  
    303.   
    304.     <!-- Custom repositories -->  
    305.     <repositories>  
    306.         <repository>  
    307.             <id>springsource-milestones</id>  
    308.             <name>SpringSource Milestones Proxy</name>  
    309.             <url>https://oss.sonatype.org/content/repositories/springsource-milestones</url>  
    310.         </repository>  
    311.         <repository>  
    312.             <id>CentralM1</id>  
    313.             <name>sonatype maven repository</name>  
    314.             <url>https://repository.sonatype.org/content/shadows/centralm1/</url>  
    315.         </repository>  
    316.     </repositories>  
    317.     <!-- end of Custom repositories -->  
    318.   
    319.     <!-- Build support -->  
    320.     <build>  
    321.         <plugins>  
    322.             <plugin>  
    323.                 <groupId>org.mortbay.jetty</groupId>  
    324.                 <artifactId>maven-jetty-plugin</artifactId>  
    325.                 <version>7.0.0.pre5</version>  
    326.                 <configuration>  
    327.                     <encoding>UTF-8</encoding>  
    328.                 </configuration>  
    329.             </plugin>  
    330.         </plugins>  
    331.     </build>  
    332.     <!-- end of Build support -->  
    333. </project>  
    接下来:web.xml
    1. <?xml version="1.0" encoding="UTF-8" ?>  
    2. <web-app xmlns="http://java.sun.xml/ns/javaee"  
    3.                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    4.                  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
    5.                                                      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  
    6.     <display-name>haiercloud-webapp</display-name>  
    7.     <!-- context-params -->  
    8.     <!-- webAppRootKey -->  
    9.     <context-param>  
    10.         <param-name>webAppRootKey</param-name>  
    11.         <param-value>haiercloud-webapp</param-value>  
    12.     </context-param>  
    13.     <context-param>  
    14.         <param-name>log4jConfigLocation</param-name>  
    15.         <param-value>classpath:log4j.properties</param-value>  
    16.     </context-param>  
    17.     <!-- Spring configuration file location -->  
    18.     <context-param>  
    19.         <param-name>contextConfigLocation</param-name>  
    20.         <param-value>  
    21.             /WEB-INF/classes/applicationContext.xml,  
    22.             classpath*:applicationContext.xml  
    23.         </param-value>  
    24.     </context-param>  
    25.     <!-- end of context-params -->  
    26.       
    27.     <!-- Spring configuration -->  
    28.     <!-- filters -->  
    29.     <!-- Spring encoding filter -->  
    30.     <filter>  
    31.         <filter-name>encodingFilter</filter-name>  
    32.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
    33.         <init-param>  
    34.             <param-name>encoding</param-name>  
    35.             <param-value>UTF-8</param-value>  
    36.         </init-param>  
    37.     </filter>  
    38.     <!-- Shiro security filter -->  
    39.     <!-- The filter-name matches name of a 'shiroFilter' bean inside applicationContext.xml -->  
    40.     <filter>  
    41.         <filter-name>shiroFilter</filter-name>  
    42.         <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>  
    43.         <init-param>  
    44.             <param-name>targetFilterLifecycle</param-name>  
    45.             <param-value>true</param-value>  
    46.         </init-param>  
    47.     </filter>  
    48.     <!-- Make sure any request you want accessible to Shiro is filtered. /* catches all -->  
    49.     <!-- requests. Usually this filter mapping is defined first (before all others) to       -->  
    50.     <!-- ensure that Shiro works in subsequent filters in the filter chain: -->  
    51.      
    52.     <!-- Encoding URL mapping -->  
    53.     <filter-mapping>  
    54.         <filter-name>encodingFilter</filter-name>  
    55.         <url-pattern>/*</url-pattern>  
    56.     </filter-mapping>  
    57.      <filter-mapping>  
    58.         <filter-name>shiroFilter</filter-name>  
    59.         <url-pattern>/*</url-pattern>  
    60.     </filter-mapping>  
    61.     <!-- end of filters -->  
    62.       
    63.     <!-- Servlet configuration -->  
    64.     <servlet>  
    65.         <servlet-name>SpringDispatcher</servlet-name>  
    66.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
    67.         <init-param>  
    68.             <param-name>contextConfigLocation</param-name>  
    69.             <param-value>/WEB-INF/dispathcer-servlet.xml</param-value>  
    70.         </init-param>  
    71.         <load-on-startup>1</load-on-startup>  
    72.     </servlet>  
    73.       
    74.     <servlet-mapping>  
    75.         <servlet-name>default</servlet-name>  
    76.         <url-pattern>*.png</url-pattern>  
    77.     </servlet-mapping>  
    78.     <servlet-mapping>  
    79.         <servlet-name>SpringDispatcher</servlet-name>  
    80.         <url-pattern>/</url-pattern>  
    81.     </servlet-mapping>  
    82.       
    83.     <session-config>  
    84.         <session-timeout>30</session-timeout>  
    85.     </session-config>  
    86.     <!-- end of Servlet configuration -->  
    87.       
    88.     <!-- Listeners -->  
    89.     <listener>  
    90.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    91.     </listener>  
    92.     <listener>  
    93.         <listener-class>org.apache.tiles.extras.complete.CompleteAutoloadTilesListener</listener-class>  
    94.     </listener>  
    95.     <listener>  
    96.         <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>  
    97.     </listener>  
    98.     <!-- end of Listeners -->  
    99.       
    100.     <!-- jsp configuration -->  
    101.     <jsp-config>  
    102.         <jsp-property-group>  
    103.             <display-name>JSPConfiguration</display-name>  
    104.             <url-pattern>*.jsp</url-pattern>  
    105.             <el-ignored>false</el-ignored>  
    106.             <page-encoding>utf-8</page-encoding>  
    107.         </jsp-property-group>  
    108.     </jsp-config>  
    109.     <!-- end of jsp configuration -->  
    110.       
    111.     <!-- Error page definition -->  
    112.     <!--   
    113.     <error-page>  
    114.         <exception-type>java.lang.Throwable</exception-type>  
    115.         <location>/static_pages/error_pages/500.jsp</location>  
    116.     </error-page>  
    117.     <error-page>  
    118.         <error-code>500</error-code>  
    119.         <location>/static_pages/error_pages/500.jsp</location>  
    120.     </error-page>  
    121.     <error-page>  
    122.         <error-code>404</error-code>  
    123.         <location>/static_pages/error_pages/404.jsp</location>  
    124.     </error-page>  
    125.     -->  
    126.     <!-- end of Error page definition -->  
    127.       
    128.     <!-- Welcome page definition -->  
    129.     <!--    
    130.     <welcome-file-list>  
    131.         <welcome-file>index.jsp</welcome-file>  
    132.     </welcome-file-list>  
    133.     -->  
    134.     <!-- end of Welcome page definition -->  
    135. </web-app>  



    原文地址:http://blog.csdn.net/jokes000/article/details/10998109


    展开全文
  • 最近项目需要进行高要求的Web权限管理,在比较Spring security和Shiro之后由于Shiro更大的灵活度和更强的配置性选择了Shiro。 不过官方的文档写的对于集成spring不太清楚,尤其是Realm怎样实现...
    代码格式很不错,转载过来借鉴下。
    原文链接:http://blog.csdn.net/jokes000/article/details/10998109
    以下为原文:
    最近项目需要进行高要求的Web权限管理,在比较Spring security和Shiro之后由于Shiro更大的灵活度和更强的配置性选择了Shiro。
    不过官方的文档写的对于集成spring不太清楚,尤其是Realm怎样实现。
    因此,在查阅一系列资料之后,将目前集成的步骤总结出来。
    特别推荐博文:http://www.cnblogs.com/xql4j/archive/2013/03/30/2990841.html,此文对作者帮助极大,在此表示感谢!

    具体步骤抽象:


    修改配置文件:
    首先是pom.xml
    [html] view plain copy
    <!-- Version of jars -->
    <properties>
    <spring.version>3.2.3.RELEASE</spring.version>
    <hibernate.version>4.2.3.Final</hibernate.version>
    <slf4j.version>1.7.5</slf4j.version>
    <log4j.version>1.2.17</log4j.version>
    <junit.version>4.11</junit.version>
    <cglib.version>3.0</cglib.version>
    <velocity.version>1.7</velocity.version>
    <tiles.extras.version>3.0.1</tiles.extras.version>
    <jsonlib.version>2.4</jsonlib.version>
    <shiro.version>1.2.2</shiro.version>
    </properties>

    <dependencies>

    <!-- Spring jars -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
    <exclusions>
    <exclusion>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>${spring.version}</version>
    <exclusions>
    <exclusion>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
    <exclusions>
    <exclusion>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring.version}</version>
    <exclusions>
    <exclusion>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>${spring.version}</version>
    <scope>test</scope>
    <exclusions>
    <exclusion>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${spring.version}</version>
    <type>jar</type>
    <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>${spring.version}</version>
    <type>jar</type>
    <scope>runtime</scope>
    </dependency>
    <dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
    </dependency>
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
    </dependency>
    <dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.1</version>
    </dependency>
    <!-- end of Spring jars -->

    <!-- Shiro security -->
    <dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-core</artifactId>
    <version>${shiro.version}</version>
    </dependency>
    <dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-web</artifactId>
    <version>${shiro.version}</version>
    </dependency>
    <dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-cas</artifactId>
    <version>${shiro.version}</version>
    </dependency>
    <dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-spring</artifactId>
    <version>${shiro.version}</version>
    </dependency>
    <!-- end of Shiro security -->

    <!-- Json -->
    <dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-core-lgpl</artifactId>
    <version>1.8.1</version>
    </dependency>
    <dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-lgpl</artifactId>
    <version>1.8.1</version>
    </dependency>
    <dependency>
    <groupId>net.sf.json-lib</groupId>
    <artifactId>json-lib</artifactId>
    <version>${jsonlib.version}</version>
    <classifier>jdk15</classifier>
    </dependency>
    <!-- end of Json -->

    <!-- Hibernate4 -->
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>${hibernate.version}</version>
    </dependency>
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>${hibernate.version}</version>
    </dependency>
    <dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.1</version>
    <exclusions>
    <exclusion>
    <groupId>javax.xml.stream</groupId>
    <artifactId>stax-api</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.1.10</version>
    </dependency>
    <dependency>
    <groupId>org.apache.openejb</groupId>
    <artifactId>javaee-api</artifactId>
    <version>5.0-1</version>
    <!--<scope>provided</scope> -->
    </dependency>
    <dependency>
    <groupId>commons-dbcp</groupId>
    <artifactId>commons-dbcp</artifactId>
    <version>1.4</version>
    <!--<scope>provided</scope> -->
    </dependency>
    <!-- end of Hibernate4 -->

    <!-- logging -->
    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
    </dependency>
    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>${slf4j.version}</version>
    </dependency>
    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>${slf4j.version}</version>
    </dependency>
    <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>${log4j.version}</version>
    <!--<scope>provided</scope> -->
    </dependency>
    <!-- end of logging -->

    <!-- provided -->
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>${cglib.version}</version>
    </dependency>
    <dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.1</version>
    </dependency>
    <!-- end of provided -->

    <!-- Test -->
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>${junit.version}</version>
    <scope>test</scope>
    </dependency>
    <!-- end of Test -->

    <!-- Database -->
    <dependency>
    <groupId>com.mchange</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.5-pre3</version>
    <type>jar</type>
    <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.21</version>
    <type>jar</type>
    <scope>compile</scope>
    </dependency>
    <!-- end of Database -->

    <!-- velocity -->
    <dependency>
    <groupId>org.apache.velocity</groupId>
    <artifactId>velocity</artifactId>
    <version>${velocity.version}</version>
    </dependency>
    <!-- end of velocity -->

    <!-- fileUpload -->
    <dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.2.2</version>
    </dependency>
    <!--io -->
    <dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.4</version>
    </dependency>
    <!-- end of fileUpload -->

    <!-- tiles -->
    <dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-extras</artifactId>
    <version>${tiles.extras.version}</version>
    <!-- it will include the rest -->
    </dependency>
    <!-- end of tiles -->
    </dependencies>

    <!-- Custom repositories -->
    <repositories>
    <repository>
    <id>springsource-milestones</id>
    <name>SpringSource Milestones Proxy</name>
    <url>https://oss.sonatype.org/content/repositories/springsource-milestones</url>
    </repository>
    <repository>
    <id>CentralM1</id>
    <name>sonatype maven repository</name>
    <url>https://repository.sonatype.org/content/shadows/centralm1/</url>
    </repository>
    </repositories>
    <!-- end of Custom repositories -->

    <!-- Build support -->
    <build>
    <plugins>
    <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>7.0.0.pre5</version>
    <configuration>
    <encoding>UTF-8</encoding>
    </configuration>
    </plugin>
    </plugins>
    </build>
    <!-- end of Build support -->
    </project>
    接下来:web.xml
    [html] view plain copy
    <?xml version="1.0" encoding="UTF-8" ?>
    <web-app xmlns="http://java.sun.xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>haiercloud-webapp</display-name>
    <!-- context-params -->
    <!-- webAppRootKey -->
    <context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>haiercloud-webapp</param-value>
    </context-param>
    <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
    </context-param>
    <!-- Spring configuration file location -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/classes/applicationContext.xml,
    classpath*:applicationContext.xml
    </param-value>
    </context-param>
    <!-- end of context-params -->

    <!-- Spring configuration -->
    <!-- filters -->
    <!-- Spring encoding filter -->
    <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>UTF-8</param-value>
    </init-param>
    </filter>
    <!-- Shiro security filter -->
    <!-- The filter-name matches name of a 'shiroFilter' bean inside applicationContext.xml -->
    <filter>
    <filter-name>shiroFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
    <param-name>targetFilterLifecycle</param-name>
    <param-value>true</param-value>
    </init-param>
    </filter>
    <!-- Make sure any request you want accessible to Shiro is filtered. /* catches all -->
    <!-- requests. Usually this filter mapping is defined first (before all others) to -->
    <!-- ensure that Shiro works in subsequent filters in the filter chain: -->

    <!-- Encoding URL mapping -->
    <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>shiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- end of filters -->

    <!-- Servlet configuration -->
    <servlet>
    <servlet-name>SpringDispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/dispathcer-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.png</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>SpringDispatcher</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>

    <session-config>
    <session-timeout>30</session-timeout>
    </session-config>
    <!-- end of Servlet configuration -->

    <!-- Listeners -->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
    <listener-class>org.apache.tiles.extras.complete.CompleteAutoloadTilesListener</listener-class>
    </listener>
    <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <!-- end of Listeners -->

    <!-- jsp configuration -->
    <jsp-config>
    <jsp-property-group>
    <display-name>JSPConfiguration</display-name>
    <url-pattern>*.jsp</url-pattern>
    <el-ignored>false</el-ignored>
    <page-encoding>utf-8</page-encoding>
    </jsp-property-group>
    </jsp-config>
    <!-- end of jsp configuration -->

    <!-- Error page definition -->
    <!--
    <error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/static_pages/error_pages/500.jsp</location>
    </error-page>
    <error-page>
    <error-code>500</error-code>
    <location>/static_pages/error_pages/500.jsp</location>
    </error-page>
    <error-page>
    <error-code>404</error-code>
    <location>/static_pages/error_pages/404.jsp</location>
    </error-page>
    -->
    <!-- end of Error page definition -->

    <!-- Welcome page definition -->
    <!--
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    -->
    <!-- end of Welcome page definition -->
    </web-app>
    展开全文
  • 作者前言: 这几天在网上找了一些shiro相关的文章看了看,结合自己的理解写一篇文章以加深印象并希望能帮助...shiroDemo.rar项目下载地址 1.创建数据库 数据库准备三张表:t_user用户表,t_role角色表,t_perm...
  • Maven+SSM+Shiro

    2017-12-01 00:46:04
    Maven项目整合了Spring+SpringMVC+MyBatis+Shiro,该项目实现了登陆和权限验证功能。
  • 一、前言本文小编将基于 SpringBoot 集成 Shiro 实现动态uri权限,由前端vue在页面配置uri,Java后端动态刷新权限,不用重启项目,以及在页面分配给用户 角色 、 按钮 、uri 权限后,后端动态分配权限,用户无需在...
  • Shiro 是一个 Apache 下的一开源项目项目,旨在简化身份验证和授权,下面通过实例代码给大家分享springmvc+shiro+maven 实现登录认证与权限授权管理,感兴趣的朋友一起看看吧
  • 一、毫无头绪:一开始项目的整体构思,选择要实现的功能以及数据库的设计; 二、思路渐渐清晰:在完成了数据库的设计,以及模块的构思之后,就是想着从哪开始实现项目,先走通一条线再串起来 就比如:实现商品展示-...
  • erp项目 基于ssm+easyUI+mysql+maven+shiro开发 本系统实现目标如下: ## 项目技术架构(Spring+SpringMVC+Mybatis) ## - Maven - Spring(IOC DI AOP 声明式事务处理) - SpringMVC(支持Restful风格) - Hibernate...
  • erp项目 基于ssm+easyUI+mysql+maven+shiro开发 本系统实现目标如下: ## 项目技术架构(Spring+SpringMVC+Mybatis) ## - Maven - Spring(IOC DI AOP 声明式事务处理) - SpringMVC(支持Restful风格) - Hibernate...
  • 1:shiro的配置,通过maven加入shiro相关jar包 [java] view plain copy print?&amp;amp;lt;!–shiro–&amp;amp;gt;&amp;amp;lt;dependency&amp;amp;gt;&amp;amp;lt;groupId&amp;amp;gt;org....
  • ShiroShiro 是一个 Apache 下...1:shiro的配置,通过maven加入shiro相关jar包org.apache.shiroshiro-core1.2.1org.apache.shiroshiro-web1.2.1org.apache.shiroshiro-ehcache1.2.1org.apache.shiroshiro-spring...
  • 项目描述日常工作中,权限管理是管理系统必不可少的功能。网络上有各种各样的权限管理系统,不过用别人的总不如自己写一套来的踏实。之前本菜鸟分享的例子里有各种技术点的分项实例,这次做一个综合,形成自己的简单...
  • Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。 图1 TIOBE编程语言排行榜 从图1中我们可以看出,Java一直稳居第一,它具有简单性、面向对象.....
  • ,先空功能实现 一:流程图 gif演示:如下 二:每个任务拥有的角色与权限 一共需要5张表,user,role,user_role,permission,role_permission表格 项目主要用ssm框架搭建,这我就只放置查询语句 &lt;...
  • SpringMvc 集成 shiro 实现权限角色管理 1、项目清单展示 2、项目源码解析  1)spring-context.xml ------spring 父上下文 xmlns:xsi="http://www.w3.org/2001/XMLSchema-i
  • Shiro 是一个 Apache 下的一开源项目项目,旨在简化身份验证和授权。 spring,springMVC,maven,shiro shiro的配置,通过maven加入shiro相关jar包 1.shiro的配置,通过maven加入shiro相关jar包 1 <...
  • Spring+SpringMVC+Mybatis+Shiro+ Maven+AdminLTE(Bootstarp)整合项目 4、改造功能 (1)登录功能 (2)登录界面背景图片 (3)登录增加tab框 (4)登录成功后增加消息组件--未实现真正消息功能 (5)增加换肤...
  • 在前面几篇文章中讲述了SSM常用框架的搭建,现在加入html页面,实现简单web应用。...项目说明: (1) 使用freemarker模板,在html页面中可以获取attribute参数,替代jsp。 (2) 前端框架使用easyui,需要系统学习
  • SSM和Shiro项目

    2018-01-11 17:22:47
    SSM+shiro,简单集成项目,实现shiro安全验证,内部附有文档说明,项目为maven项目,通俗易懂,希望对大家有帮助
  • Eclipse中导入maven项目

    2020-09-29 09:26:28
    系统登录功能实现 后端菜单管理(模块)功能(前端菜单管理(模块)功能) 后端角色管理功能(前端角色管理功能) 后端用户管理功能(前端用户管理功能) 后端日志管理功能(前端日志管理功能) 准备工作1-2准备工作 1-2准备工作...
  • maven+springboot+jpa+shiro权限管理内有数据库sql,只要哪里这个基础代码之后的功能添加很方便,适合快速实现项目

空空如也

空空如也

1 2 3 4 5 ... 13
收藏数 247
精华内容 98
关键字:

maven项目实现shiro