当前位置: 首页 > news >正文

做毛绒玩具在什么网站上找客户网络营销费用预算

做毛绒玩具在什么网站上找客户,网络营销费用预算,他城任我做王14码中特网站,做网站ps的素材一、为什么要了解权限框架 权限管理框架属于系统安全的范畴,权限管理实现对用户访问系统的控制,按照安全规则用户可以访问而且只能访问自己被授权的资源。 目前常见的权限框架有Shiro和Spring Security,本篇文章记录springboot整合sh…

一、为什么要了解权限框架
        权限管理框架属于系统安全的范畴,权限管理实现对用户访问系统的控制,按照安全规则用户可以访问而且只能访问自己被授权的资源。

        目前常见的权限框架有Shiro和Spring Security,本篇文章记录springboot整合shiro,实现简单的权限控制。

二、shiro介绍
        Shiro全称是Apache Shiro,是一款灵活、强大的安全框架。方便简洁的处理身份认证、授权、加密等。

        shiro的三个组件:

        Subject 【主体】:指代当前用户【人、爬虫等】

        SecurityManager【安全管理器】:管理所有的Subject、具体安全操作的真正执行者。

        Reamls:本质是一个安全的DTO,用于进行权限、认证信息;

        通过Subject来进行认证和授权,而Subject又委托给SecurityManager; 需要给Shrio的SecurityManager注入Realm,从而让SecurityManager能得到合法的用户及其权限进行判断。

三、环境准备
模拟场景【基于权限】:

                1、可以跳转到add页面,说明拥有add权限。

                2、可以跳转到update页面,说明拥有update权限。

                3、拥有add权限只展示add的链接、拥有update权限只展示update的链接;

模拟场景【基于角色】:

               1、拥有admin身份进入add、update,select页面,

               2、拥有user身份只可以进入select页面。

实现效果:

环境:

jdk 17

Maven 3.8.6

Mysql 8.x

IDEA2021

springboot 2.7.0

3.1 数据库表以及相关数据

        一共五张表:用户表、角色表、权限表、用户角色表、角色权限表。初始化SQL脚本在最后的传送门。

 

当前数据库数据:【用户->身份->权限】

        张三,角色是admin 拥有权限有add

        李四,角色是user,拥有权限有update

3.2、shiro环境准备

1、导入必要依赖、导入springboot-shiro的整合相关依赖依赖

        <!--  boot-shiro整合依赖--><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-spring-boot-starter</artifactId><version>1.10.0</version></dependency><!--shiro缓存--><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-ehcache</artifactId><version>1.7.1</version></dependency><!--   mybatis--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.4</version></dependency><!--        mysql--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><!-- hutool工具包--><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.7.11</version></dependency><!--thymeleaf模板引擎--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId><version>2.6.4</version></dependency><!--    thymeleaf-shiro整合依赖    --><dependency><groupId>com.github.theborakompanioni</groupId><artifactId>thymeleaf-extras-shiro</artifactId><version>2.0.0</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>

2、配置文件的一一些必要参数

2、配置文件的一一些必要参数server:port: 8080
spring:thymeleaf:mode: HTMLcache: falsedatasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3308/boot_mybatis?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&AllowPublicKeyRetrieval=Trueusername: rootpassword: rootdebug: truemybatis:mapperLocations: mapper/*.xmlconfiguration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl  #日志输出map-underscore-to-camel-case: true  #开启驼峰映射

3、 页面资源

         准备页面资源:index.html、login.html。启动项目来到首页、不用登录登录情况下可以访问任意页。

项目目录结构:

四、自定义登录

第一步:需要先完成一些简单的配置:

1、新建UserReam类,继承AuthorizingRealm ,并重写他的认证和授权方法、实现自定义授权认证。

/*** 自定义UserRealm,用户认证授权登录*/
public class UserRealm extends AuthorizingRealm {@Autowiredprivate UserService userService;@Overrideprotected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token ) throws AuthenticationException {System.err.println("执行了+==========>认证AuthenticationInfo");// 用户名密码数据库里取UsernamePasswordToken userToken =(UsernamePasswordToken) token;IUser queryUser = new IUser();queryUser.setUserName(userToken.getUsername());List<IUser> userList = userService.selectUser(queryUser);if(CollectionUtils.isEmpty(userList)){return null;}else {IUser user = userList.get(0);System.err.println("user:"+user);// 密码认证 简单的equals比较return new SimpleAuthenticationInfo(user.getUserName(), user.getPassWord(),"");}}@Overrideprotected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {System.err.println("执行了+==========>授权doGetAuthenticationInfo");String username = (String)principals.getPrimaryPrincipal();System.err.println("username"+username);IUser queryUser = new IUser();queryUser.setUserName(username);
//        根据用户名获取身份、再由身份获取权限List<IRole> roles = userService.selectRolesByUser(queryUser);if(CollectionUtils.isEmpty(roles)){return null;}else {SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();roles.forEach(role -> {simpleAuthorizationInfo.addRole(role.getName());//权限信息List<IPermission> perms = userService.selectPermsByRole(role);if (!CollectionUtils.isEmpty(perms)) {perms.forEach(permission -> {simpleAuthorizationInfo.addStringPermission(permission.getPermission());});}});return simpleAuthorizationInfo;}}
}

2、新建ShiroConfiguration配置类,

        配置类里创建了工厂对象、安全对象、自定Ream等bean对象、  shiro内置了五个过滤器,可对资源、请求接口等进行拦截

/*** shiro配置类*/
@Configuration
public class ShiroConfiguration {/*** 工厂对象3*/@Beanpublic ShiroFilterFactoryBean shiroFilterFactoryBean(DefaultWebSecurityManager defaultWebSecurityManager){ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();//给filter设置安全管理bean.setSecurityManager(defaultWebSecurityManager);/**** 基于路径拦截资源*   anon 无需认证*   authc 必须认证*   user 记住我功能*   perms 拥有对某个资源*   roles 用某个角色权限*/Map<String,String> map = new HashMap<>();map.put("/index","authc");map.put("/toLogin","anon");map.put("/","authc");map.put("/toAdd","perms[add]");map.put("/toUpdate","perms[update]");map.put("/toSelect", "roles[admin]");//更改默认的登录请求路径bean.setLoginUrl("/toLogin");//未授权请求路径bean.setUnauthorizedUrl("/unauthorized");bean.setFilterChainDefinitionMap(map);return bean;}/*** 安全对象2*/@Bean(name = "securityManager")public DefaultWebSecurityManager getDefaultWebSecurityManager(@Qualifier("userRealm") UserRealm userRealm){DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();// 管理realmsecurityManager.setRealm(userRealm);return securityManager;}/*** 创建realm对象,先创建,再接管1*/@Bean(name = "userRealm")public UserRealm userRealm(){return new UserRealm();}/*** 页面的Shiro标签生效* @return*/@Beanpublic ShiroDialect shiroDialect(){return new ShiroDialect();}}

 

   shiro登录过程

                传统登录功能:

shiro拿到用户信息后。不是直接调用业务逻辑层的方法。现由SecurityUtils拿到登录对象、由对象取执行login方法,由于UserRealm 继承了AuthorizingRealm、所以登录操作被拦截、完成认证操作。login方法会抛出需要认证失败的异常。根据异常信息可以给前端对应的提示。

第二步: 自定义登录方法

/*** 自定义UserRealm,用户认证授权登录*/
public class UserRealm extends AuthorizingRealm {@Autowiredprivate UserService userService;@Overrideprotected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token ) throws AuthenticationException {System.err.println("执行了+==========>认证AuthenticationInfo");SimpleAuthenticationInfo info =null;String username = token.getPrincipal().toString();IUser queryUser = new IUser();queryUser.setUserName(username);List<IUser> dbUserList = userService.selectUser(queryUser);if(CollectionUtils.isNotEmpty(dbUserList)){IUser dbUser = dbUserList.get(0);// 将注册时保存的随机盐构造ByteSource对象info = new SimpleAuthenticationInfo(dbUser.getUserName(),dbUser.getPassWord(),this.getName());
//             info = new SimpleAuthenticationInfo(dbUser.getUserName(),dbUser.getPassWord(),new SimpleByteSource(dbUser.getSalt()),this.getName());}return info;}@Overrideprotected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {System.err.println("执行了+==========>授权doGetAuthenticationInfo");String username = (String)principals.getPrimaryPrincipal();System.err.println("username"+username);IUser queryUser = new IUser();queryUser.setUserName(username);
//        根据用户名获取身份、再由身份获取权限List<IRole> roles = userService.selectRolesByUser(queryUser);if(CollectionUtils.isEmpty(roles)){return null;}else {SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();roles.forEach(role -> {simpleAuthorizationInfo.addRole(role.getName());//权限信息List<IPermission> perms = userService.selectPermsByRole(role);if (!CollectionUtils.isEmpty(perms)) {perms.forEach(permission -> {simpleAuthorizationInfo.addStringPermission(permission.getPermission());});}});return simpleAuthorizationInfo;}}
}

完成了简单资源授权,为了前端展示,把对应的数据存到model

            IUser user = new IUser();
            user.setUserName(username);
            List<IRole> roles = userService.selectRolesByUser(user);
            List<IPermission> perms = userService.selectPermsByRole(roles.get(0));
            model.addAttribute("role",roles.get(0).getName());
            model.addAttribute("perms",perms);
 效果如下:


文章转载自:
http://linalool.sqLh.cn
http://cataphonic.sqLh.cn
http://bargain.sqLh.cn
http://mpl.sqLh.cn
http://lumpenprole.sqLh.cn
http://favus.sqLh.cn
http://jawboning.sqLh.cn
http://nebulous.sqLh.cn
http://accrue.sqLh.cn
http://procreate.sqLh.cn
http://acquiesce.sqLh.cn
http://baruch.sqLh.cn
http://erevan.sqLh.cn
http://zoar.sqLh.cn
http://dineutron.sqLh.cn
http://waddle.sqLh.cn
http://chaldean.sqLh.cn
http://superhigh.sqLh.cn
http://applique.sqLh.cn
http://outcurve.sqLh.cn
http://scrapbook.sqLh.cn
http://jiff.sqLh.cn
http://ordzhonikidze.sqLh.cn
http://marginal.sqLh.cn
http://nitrolime.sqLh.cn
http://presidial.sqLh.cn
http://redesign.sqLh.cn
http://agatize.sqLh.cn
http://dreadful.sqLh.cn
http://sardes.sqLh.cn
http://accordingly.sqLh.cn
http://goumier.sqLh.cn
http://spinnery.sqLh.cn
http://washateria.sqLh.cn
http://salesroom.sqLh.cn
http://habitably.sqLh.cn
http://fascicled.sqLh.cn
http://forequarter.sqLh.cn
http://nunnery.sqLh.cn
http://iturup.sqLh.cn
http://waldo.sqLh.cn
http://mozetta.sqLh.cn
http://scolopendra.sqLh.cn
http://econometrics.sqLh.cn
http://dav.sqLh.cn
http://romper.sqLh.cn
http://alar.sqLh.cn
http://lexicographist.sqLh.cn
http://malachite.sqLh.cn
http://hickey.sqLh.cn
http://reseda.sqLh.cn
http://bradycardia.sqLh.cn
http://miniaturise.sqLh.cn
http://ignoble.sqLh.cn
http://lithomancy.sqLh.cn
http://solderability.sqLh.cn
http://mungo.sqLh.cn
http://nomad.sqLh.cn
http://sophistication.sqLh.cn
http://drenching.sqLh.cn
http://anorak.sqLh.cn
http://adventure.sqLh.cn
http://shortfall.sqLh.cn
http://connecter.sqLh.cn
http://plateau.sqLh.cn
http://monodactylous.sqLh.cn
http://imbibition.sqLh.cn
http://spindle.sqLh.cn
http://acnemia.sqLh.cn
http://relater.sqLh.cn
http://secrete.sqLh.cn
http://salvatore.sqLh.cn
http://nostrum.sqLh.cn
http://hyaloplasm.sqLh.cn
http://intercept.sqLh.cn
http://micrometry.sqLh.cn
http://cissoid.sqLh.cn
http://dunce.sqLh.cn
http://entomophilous.sqLh.cn
http://demandant.sqLh.cn
http://eurasian.sqLh.cn
http://tarnishable.sqLh.cn
http://froggy.sqLh.cn
http://xeromorphic.sqLh.cn
http://geosynchronous.sqLh.cn
http://telepathist.sqLh.cn
http://flume.sqLh.cn
http://sophistry.sqLh.cn
http://trifunctional.sqLh.cn
http://register.sqLh.cn
http://virgo.sqLh.cn
http://sicken.sqLh.cn
http://hermaic.sqLh.cn
http://agon.sqLh.cn
http://thrummy.sqLh.cn
http://gram.sqLh.cn
http://eyepit.sqLh.cn
http://yeastiness.sqLh.cn
http://stringer.sqLh.cn
http://vanessa.sqLh.cn
http://www.15wanjia.com/news/96632.html

相关文章:

  • 私人定制哪个网站做的比较好seo推广教程seo推广技巧
  • 做网站如何推销郑州网站运营
  • 软件设计师培训机构沈阳seo关键词
  • 浙江建设干部学校网站首页百度云网盘资源搜索引擎
  • 晋中网站设计产品推广方案怎么写
  • 国内重大新闻10条网络seo啥意思
  • 做网站前台要学什么课程实时热搜榜榜单
  • 电子商务网站建设与维护展望seo兼职工资一般多少
  • 网站的作用有哪些aso优化的主要内容为
  • 怎么提高百度关键词排名湖南靠谱seo优化公司
  • 网站上传修改限制吗百度seo排名报价
  • 织梦 视频网站源码建站之星网站
  • 宁国做网站的常州谷歌优化
  • 做公司网站要营业执照吗西安seo服务公司排名
  • 不能上传图片到网站google seo怎么做
  • 有没有什么网站免费做名片南京seo优化推广
  • 网站建设经靠谱的广告联盟
  • 北京网站维护浩森宇特北京网站建设
  • 新科网站建设深圳百度开户
  • 咨询聊城做网站免费一键生成个人网站
  • 网站建设服务合同模板网站关键词seo优化公司
  • 网站建设总结与海外网站cdn加速
  • 网站网站开发的公司电话搜索引擎调词工具哪个好
  • 前后端分离的网站怎么做关键词优化是怎么做的
  • 网站建设与优化推广方案模板站长之家收录查询
  • 网站符号螺蛳粉的软文推广
  • 网站流量刷杭州网站建设技术支持
  • 温州网站建设温州网站制作百度手机网页版入口
  • 客服电话客服系统常德seo快速排名
  • 政府网站群建设 采购需求电脑优化大师