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

帮别人做网站赚钱吗中山快速建站合作

帮别人做网站赚钱吗,中山快速建站合作,深圳做电商网站,南昌网站建设渠道本篇为SpringSecurity的第一篇#xff0c;主要来介绍下什么是SpringSecurity#xff0c;以及在springboot中如何使用它I. 基本知识点官方文档: https://docs.spring.io/spring-security/site/docs/5.2.2.BUILD-SNAPSHOT/reference/htmlsingle/#community-help下面是官方介绍S…本篇为SpringSecurity的第一篇主要来介绍下什么是SpringSecurity以及在springboot中如何使用它I. 基本知识点官方文档: https://docs.spring.io/spring-security/site/docs/5.2.2.BUILD-SNAPSHOT/reference/htmlsingle/#community-help下面是官方介绍Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications.Spring Security is a framework that focuses on providing both authentication and authorization to Java applications. Like all Spring projects, the real power of Spring Security is found in how easily it can be extended to meet custom requirements用国语简单抽象的说一下它的定义很的认证和访问权限校验框架那么具体能干嘛用户登录认证用户名密码登录确定用户身份用户访问鉴权(常见的ACL访问控制列表RBAC角色访问控制)判定是否有权限访问某个资源安全保护(CSRF跨站点攻击,Session Fixation会话固定攻击...)II. 初体验接下来我们看一下再springboot中如何使用springsecurity1. 配置首先得是spring boot项目然后添加上security的依赖即可相对完整的pom配置如下(注意我们使用的springboot版本为2.2.1.RELEASE)org.springframework.boot spring-boot-starter-parent 2.2.1.RELEASEUTF-8UTF-81.8org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-maven-plugin spring-snapshotsSpring Snapshotshttps://repo.spring.io/libs-snapshot-localtruespring-milestonesSpring Milestoneshttps://repo.spring.io/libs-milestone-localfalsespring-releasesSpring Releaseshttps://repo.spring.io/libs-release-localfalse2. 实例demo上面配置完之后啥都不需要干项目已经接入了spring security项目中的服务都需要登录之后才能访问// 程序启动类SpringBootApplicationpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}// rest 服务RestControllerpublic class IndexRest { GetMapping(path {/, /index}) public String index() { return hello this is index!; } GetMapping(path hello) public String hello(String name) { return welcome name; }}当我们需要访问首页时会发现直接302重定向到登录页面了如下图spring security默认给我们生成了一个用户名为user密码为控制台中输出的一行日志如Using generated security password: aa410186-5c04-4282-b217-507ffb1f61eb登录之后会重定向回我们之前访问的url通过抓包可以看到登录成功之后会设置请求方的cookie后续的请求携带cookie来表明用户身份3. 基本配置上面虽然演示了一个hello world的初体验项目但是这个默认的用户名/密码有点鬼畜默认的配置主要来自于org.springframework.boot.autoconfigure.security.SecurityProperties.User下面是截图(所以前面的用户名为user)接下来我们需要配置为对人类友好的方式在项目的配置文件application.yml中指定登录的用户名/密码spring: security: user: name: yihuihui password: 123456重启测试项目使用新的用户名/密码(yihuihui/123456)就可以登录成功了;4. 用户身份获取上面虽然是一个简单的case但还有一点不得不提一下在我的接口中虽然知道你登录了但怎么知道你是谁呢我们可以直接通过HttpServletRequest#getRemoteUser()的方法来获取登录用户 或者通过SecurityContextHolder.getContext().getAuthentication().getPrincipal()来获取授权信息我们来写一个通用方法public String getUser() { return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getRemoteUser();}// orpublic Object getUser() { SecurityContextHolder.getContext().getAuthentication().getPrincipal();}然后稍微改一下我们的服务接口GetMapping(path {/, /index})public String index() { return hello this is index! welcome getUser();}再次访问之后结果如下5. 小结本文主要是spring security系列的起源篇第一节介绍了下什么是SpringSecurity有什么特点spring security是一个很的认证(可以简单理解为登录验证)和鉴权(可简单理解为访问控制)框架三大特点登录 鉴权 安全防护第二节介绍了一个简单入门的HelloWorld实例springboot项目添加依赖 spring-boot-starter-security 所有的http接口访问都需要登录默认提供一个用户名为user密码为控制台输出的UUID字符串通过spring.security.user.name和spring.security.user.password来指定用户名密码通过HttpServletRequest#getRemoteUser()获取登录用户那么问题来了什么系统可能只有一个用户呢要多用户怎么办不同的用户不同的权限怎么办某些接口所有人都可以访问又怎么办II. 其他0. 项目工程https://github.com/liuyueyi/spring-boot-demo代码: https://github.com/liuyueyi/spring-boot-demo/tree/master/spring-security/000-basic-demo1. 一灰灰Blog尽信书则不如以上内容纯属一家之言因个人能力有限难免有疏漏和错误之处如发现bug或者有更好的建议欢迎批评指正不吝感激下面一灰灰的个人博客记录所有学习和工作中的博文欢迎大家前去逛逛一灰灰Blog个人博客 https://blog.hhui.top一灰灰Blog-Spring专题博客 http://spring.hhui.top
http://www.zqtcl.cn/news/249126/

相关文章:

  • 网站后台设计教程网站建设判断题
  • 珠海网站建设 金蝶天元建设集团有限公司李华
  • 海安市建设局网站成都官网seo技术
  • 网站建设策划书结束语wordpress付费版
  • 进口网站建设做网站用什么格式的图片
  • 青海省住房和城乡建设部网站进入网站空间
  • 做公司简介的开源网站企业seo多少费用
  • 学校网站建设工作方案昆明做网站词排名优化
  • 镇江企业做网站针对人群不同,网站做细分
  • 个人单页网站建设台州网站建设惠店
  • 专做婚礼logo的网站做搜狗pc网站快速排
  • 北京网站建设公司分享网站改版注意事项做网站需要多大空间
  • 主机网站建设制作天津西青区天气预报
  • 网站没有内容可以备案吗横向网站源码
  • 做的网站浏览器提示不安全站优化
  • dede移动端网站源码电子商务网站建设开题报告
  • 做网站价格多少优质做网站哪家好
  • 网站建设及推广服务的合同范本留言网站建设的报告
  • 工程师招聘网站做网站需要公司资质吗
  • 苏州模板网站建站开网店如何运营和推广
  • 换空间网站备案北京网页设计平台
  • 德德模板网站建设步骤可信的品牌网站建设
  • 网站权重0免费好用的ip代理
  • 赣州建设网站公司敬请期待英文怎么写
  • 可以做多边形背景的网站深圳网站建设 套餐
  • 建设工程的招标网站有哪些长江证券官方网站下载
  • 鹤壁网站建设智能网站建设步骤
  • 建设工程规划许可证在哪个网站查询手机免费推广软件
  • 微信上的网站怎么做的吗网页设计结果分析怎么写
  • 网站电子备案哪个网站做网销更好