• 大小: 19.41MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-08-02
  • 语言: 其他
  • 标签: shiro  

资源简介

ssm整合shiro通过自定义Realm实现认证登录、权限处理、自定义role拦截、MD5加密

资源截图

代码片段和文件信息

package top.maniy.demo.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import top.maniy.demo.entity.User;


/**
 * @author liuzonghua
 * @Package top.maniy.controller
 * @Description:
 * @date 2018/10/6 15:36
 */
@Controller
public class UserController {
    @RequestMapping(value = “/subLogin“ method = RequestMethod.POST
    produces = “application/json;charset=utf-8“)
    @ResponseBody
    public String subLogin(User user){
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token =new UsernamePasswordToken(user.getUsername()
                user.getPassword());
        try {
            token.setRememberMe(user.isRememberMe());
            subject.login(token);
        } catch (AuthenticationException e) {
            return  e.getMessage();
        }
        if(subject.hasRole(“admin“)){
            if (subject.isPermitted(“user:select“)){
                return “权限为user:select“;
            }
            return “有admin权限“;
        }
        return “无admin权限“;
    }

    /**
     * 通过注解配置授权
     * 用户角色必须具备admin权限才能访问
     * @return
     */
    @RequiresRoles(“admin“)
    //@RequiresPermissions(“xxxx“)
    @RequestMapping(value = “/testRole“method = RequestMethod.GET)
    @ResponseBody
    public String TestRole(){
        return “testRole success“;
    }

    /**
     * 通过注解配置授权
     * 用户角色必须具备admin权限才能访问
     * @return
     */
    @RequiresRoles(“admin1“)
    @RequestMapping(value = “/testRole1“method = RequestMethod.GET)
    @ResponseBody
    public String TestRole1(){
        return “testRole1 success“;
    }

    @RequestMapping(value = “/testRole2“method = RequestMethod.GET)
    @ResponseBody
    public String TestRole2(){
        return “testRole2 success“;
    }
    @RequestMapping(value = “/testRole3“method = RequestMethod.GET)
    @ResponseBody
    public String TestRole3(){
        return “testRole3 success“;
    }

    @RequestMapping(value = “/testPerms“method = RequestMethod.GET)
    @ResponseBody
    public String TestPerms(){
        return “testPerms success“;
    }
    @RequestMapping(value = “/testPerms1“method = RequestMethod.GET)
    @ResponseBody
    public String TestPerms1(){
        return “testPerms1 success“;
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-10-11 11:47  shiro-ssm\
     目录           0  2018-10-11 13:22  shiro-ssm\.idea\
     目录           0  2018-10-11 10:41  shiro-ssm\.idea\artifacts\
     文件        4693  2018-10-11 10:41  shiro-ssm\.idea\artifacts\shiro_ssm_war_exploded.xml
     文件         630  2018-10-11 09:21  shiro-ssm\.idea\compiler.xml
     目录           0  2018-10-11 09:21  shiro-ssm\.idea\inspectionProfiles\
     文件        5973  2018-10-11 11:05  shiro-ssm\.idea\junitgenerator-prj-settings.xml
     目录           0  2018-10-11 10:07  shiro-ssm\.idea\libraries\
     文件         514  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__aopalliance_aopalliance_1_0.xml
     文件         594  2018-10-11 10:07  shiro-ssm\.idea\libraries\Maven__commons_beanutils_commons_beanutils_1_8_3.xml
     文件         517  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__commons_io_commons_io_1_3_2.xml
     文件         558  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__commons_logging_commons_logging_1_2.xml
     文件         514  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__commons_net_commons_net_3_3.xml
     文件         486  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__com_alibaba_druid_1_0_9.xml
     文件         644  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_annotations_2_4_0.xml
     文件         595  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_core_2_4_2.xml
     文件         623  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_databind_2_4_2.xml
     文件         613  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__com_github_miemiedev_mybatis_paginator_1_2_15.xml
     文件         561  2018-10-11 09:27  shiro-ssm\.idea\libraries\Maven__com_github_pagehelper_pagehelper_3_4_1.xml
     文件         494  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__javax_servlet_jsp_api_2_0.xml
     文件         522  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__javax_servlet_servlet_api_2_5.xml
     文件         437  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__jstl_jstl_1_2.xml
     文件         455  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__junit_junit_4_12.xml
     文件         469  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__log4j_log4j_1_2_16.xml
     文件         574  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__mysql_mysql_connector_java_5_1_32.xml
     文件         570  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__org_apache_commons_commons_lang3_3_3_2.xml
     文件         541  2018-10-11 10:07  shiro-ssm\.idea\libraries\Maven__org_apache_shiro_shiro_core_1_2_3.xml
     文件         555  2018-10-11 10:07  shiro-ssm\.idea\libraries\Maven__org_apache_shiro_shiro_spring_1_2_3.xml
     文件         534  2018-10-11 10:07  shiro-ssm\.idea\libraries\Maven__org_apache_shiro_shiro_web_1_2_3.xml
     文件         542  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__org_aspectj_aspectjweaver_1_8_4.xml
     文件         532  2018-10-11 09:25  shiro-ssm\.idea\libraries\Maven__org_hamcrest_hamcrest_core_1_3.xml
............此处省略182个文件信息

评论

共有 条评论