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

网站服务器做哪些安全措施澎湃新闻

网站服务器做哪些安全措施,澎湃新闻,湖北潜江今天最新消息,成都网站建设新闻Hi Auth HiAuth是一个开源的基于Oauth2协议的认证、授权系统,除了标准的Oauth2授权流程功能外,还提供了应用管理、用户管理、权限管理等相关功能。 在这个项目中你能够了解到如何基于spring-security-oauth2-authorization-server实现自己的Authorizat…

Hi Auth

HiAuth是一个开源的基于Oauth2协议的认证、授权系统,除了标准的Oauth2授权流程功能外,还提供了应用管理、用户管理、权限管理等相关功能。

在这个项目中你能够了解到如何基于spring-security-oauth2-authorization-server实现自己的Authorization Server 认证服务、资源服务器以及如何第三方集成,本项目基于SpringBoot 3.0 版本开发。

项目源码地址:https://github.com/bestaone/HiAuth

介绍

除了认证相关功能外,还提供了hiauth-mall、hiauth-mgr-svc项目,供用户参考如何集成。

  • 参考hiauth-mall,你可以了解如何在第三方应用中集成hiauth授权服务;
  • 参考hiauth-mgr-svc项目,你可以快速的启动一个微服务项目的框架搭建,亦可以在这里找到一些技术的最佳实践,为你的项目开发提供参考;

HiAuth 2.0 升级到 3.0 的升级内容

  • SpringBoot 3.0.2
  • spring-security-oauth2-authorization-server 1.0.0
  • mybatis-plus 3.5.3.1

调整比较大的地方

  • SpringSecurity升级到6.0版本后,用法有不少改动
  • SpringSecurity5以后已不再支持Authorization Server,取而代之的事spring-security-oauth2-authorization-server 项目
  • 前端从vue-element-admin换成了AntDesignPro

如果你觉得此项目有价值,请给我点个star,谢谢!

项目地址:https://github.com/bestaone/HiAuth

目录结构

├─doc                  文档目录,架构设计、数据库设计...
├─cicd                 持续集成相关脚本
├─hiauth-parent        统一管理依赖(必选)
├─hiauth-server        hiauth认证服务(必选)
├─hiauth-resource      hiauth资源管理服务,参考如何集成资源服务(参考)
├─hiauth-himall        himall是一个demo,参考此项目了解如何集成hiauth(参考)
├─hiauth-mgr-svc       hiauth管理端后台服务,基于SpringBoot(可选)
├─hiauth-mgr-fornt     hiauth管理端前端代码,基于AntDesignPro(可选)

功能

  • 这个项目可以帮你实现基于Oauth2协议的统一认证、授权系统;
  • 这个项目可以帮助你快速的启动一个基于SpringBoot技术栈的微服务框架搭建;
  • 如果你仅仅使用到了Oauth2协议的统一认证、授权系统功能,那么你用技术可以是除java外的技术栈;
  • himall演示了authorization_code模式,HiAuth支持了用户名密码、手机号短信两种认证方式;
  • 发送短信、登录接口实现了图形验证码防刷功能;
  • HiAuth是一个前后端分离项目,前端使用了ReactAntDesign技术,参考这个项目,你可以自定义开发管理后端;
  • 基于SpringBoot项目更容易集成到多个平台(SpringCloud、K8S、Istio);
  • 演示了如何统一控制接口规范;
  • 演示了如何规范异常处理;
  • 演示了如何规范使用MyBaits-Plus、分页;
  • 演示了单元测试、mock测试、测试数据回滚,包括对controller、service的测试;

截图

  • HiMall

  • UMC

前端从vue-element-admin换成了AntDesignPro截图还没来得及做新的

LIVE DEMO

  • Hiauth HiMall:http://himall.hiauth.cn
  • Hiauth Manger:http://mgr.hiauth.cn
  • Hiauth Server:http://auth.hiauth.cn

快速启动

环境需求

  • JDK17+
  • Maven 3.8.6
  • MySQL 8
  • Redis
  • NodeJS v16+(<v18)
  • Yarn 1.22.4

下载源码

>git clone https://github.com/bestaone/HiAuth.git

创建数据库

在你的mysql数据库中创建库hiauth,并执行下面脚本:

> HiAuth\doc\hiauth.sql# 也可以从JAR自己提取相关表结构
# org.springframework.security.oauth2.server.authorization.client/oauth2-registered-client-schema.sql
# org.springframework.security.oauth2.server.authorization/oauth2-authorization-consent-schema.sql
# org.springframework.security.oauth2.server.authorization/oauth2-authorization-schema.sql

调整配置

需要调整的配置有数据库、redis,默认会使用native.properties配置,如果和你的环境不一致。

请修改:

# 需要将如下两个文件中的mysql、redis的配置改成自己的
# HiAuth\hiauth-server\src\main\properties\native.properties
# HiAuth\hiauth-mgr-svc\src\main\properties\native.propertiesapp.host=http://127.0.0.1:8080database.url=jdbc:mysql://mysql-server:3306/hiauth3?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
database.username=dev
database.password=123456redis.host=redis-server
redis.port=6379
redis.database=8
redis.password=

添加host

# IP 换成你自己的
127.0.0.1 redis-server
127.0.0.1 mysql-server

构建、启动

# 编译后台,会执行单元测试,需要正确配置数据库和redis
>cd HiAuth
>mvn clean install# 构建前端并启动
>cd HiAuth\hiauth-mgr-front
>yarn install
>yarn start# 启动hiauth授权服务端
>cd HiAuth\hiauth-server
>mvn spring-boot:run# 启动hiauth资源服务端
>cd HiAuth\hiauth-resource
>mvn spring-boot:run# 启动himall
>cd HiAuth\hiauth-himall
>mvn spring-boot:run# 启动hiauth管理后端
>cd HiAuth\hiauth-mgr-svc
>mvn spring-boot:run

验证

验证登录

  • 访问HiMall:http://127.0.0.1:8081
  • 访问Server:http://127.0.0.1:8080
  • 访问Manager:http://127.0.0.1:8080 (具体端口看前端项目启动后的控制台输出)

验证Swagger

  • 访问HiAuth的Swagger地址:http://127.0.0.1:8080/swagger-ui.html
  • 直接测试接口,显示未认证
{"error": "unauthorized","error_description": "Full authentication is required to access this resource"
}
  • 点击认证按钮,会被重定向到登录,输入账号登录进行认证
  • 认证成功后被重定向回swagger页面
  • 再次测试接口,获取正确数据

验证Oauth2流程

authorization_code 认证流程

  • 在浏览器中输入如下地址,会调到登录页,登录完成后会跳转到百度,在浏览器url中把code码复制出来
http://127.0.0.1:8080/oauth2/authorize?client_id=demo-client-id&response_type=code&scope=user_info&redirect_uri=http://www.baidu.com
  • 使用上面获取的code换取accessToken
curl --location --request POST 'http://127.0.0.1:8080/oauth2/token?grant_type=authorization_code&code=code&redirect_uri=http://www.baidu.com' \--header 'Authorization: Basic ZGVtby1jbGllbnQtaWQ6ZGVtby1jbGllbnQtc2VjcmV0'
{"access_token": "xxxxxx","refresh_token": "yyyyy","scope": "user_info","token_type": "Bearer","expires_in": 7199
}

Authorization = Basic base64.encode(client_id:client_secret)可以在网上找个在线工具生成,或者直接用postman测试,Authorization选择Basic Auth,填入对应值即可

  • 访问受控接口,不带accessToken,返回401,未授权
>curl --location --request POST 'http://127.0.0.1:8082/user/info'
{"error": "unauthorized","error_description": "Full authentication is required to access this resource"
}
  • 访问受控接口,携带accessToken,返回数据
curl --location --request POST 'http://127.0.0.1:8082/user/info' --header 'Authorization: Bearer token'
{"name":"Resource"
}

refresh_token

curl --location --request POST 'http://127.0.0.1:8080/oauth2/token?grant_type=refresh_token&refresh_token=refresh_token' \--header 'Authorization: Basic ZGVtby1jbGllbnQtaWQ6ZGVtby1jbGllbnQtc2VjcmV0'
{"access_token": "xxxxxx","refresh_token": "yyyyy","scope": "user_info","token_type": "Bearer","expires_in": 6152
}
client_credentials 认证流程
  • 使用POST访问获取access_token接口,设置grant_type=client_credentials
curl --location --request POST 'http://127.0.0.1:8080/oauth2/token?grant_type=client_credentials&scope=user_info' \--header 'Authorization: Basic ZGVtby1jbGllbnQtaWQ6ZGVtby1jbGllbnQtc2VjcmV0'
{"access_token": "xxxxxx","scope": "user_info","token_type": "Bearer","expires_in": 7199
}
scop权限范围验证
  • 使用POST访问获取access_token接口,设置grant_type=client_credentialsscope=message.read
> curl --location --request POST 'http://127.0.0.1:8080/oauth2/token?grant_type=client_credentials&scope=message.read' --header 'Authorization: Basic ZGVtby1jbGllbnQtaWQ6ZGVtby1jbGllbnQtc2VjcmV0'
# 返回的 token 的权限范围是 message.read
{"access_token": "xxxxxx","scope": "message.read","token_type": "Bearer","expires_in": 7199
}
  • 使用拥有message.read权限的toke访问用户接口,被拒绝,提示无权限
curl --location --request POST 'http://127.0.0.1:8082/user/info' --header 'Authorization: Bearer token'
{"error": "insufficient_scope","error_description": "Insufficient scope for this resource","scope": "user_info"
}

所有的127.0.0.1不能使用localhost代替,因为auth会检查域名的合法性,数据库中登记的是127.0.0.1

集成认证、授权服务

这里为了演示如何集成HiAuth、提供了一个Demo项目HiMall

HiMall

HiMall是基于SpringBoot技术的微服务项目,其集成了HiAuth的认证、授权。

环境需求

  • JDK17+
  • HiAuth3

安装、启动

#编译、构建项目
>cd HiAuth\hiaut-himall
>mvn clean install
>mvn spring-boot:run

验证authorization_code模式认证

  • 访问地址:http://127.0.0.1:8081
  • 点击Login,会被重定向到HiAuth系统进行认证
  • 认证通过后会被重定向回HiMall,此时HiMall也将持有登录状态

授权协议

本项目执行 MIT 协议

社区与作者

如果群二维码失效了,请先添加我的微信,然我我拉你入群。

http://www.zhongyajixie.com/news/43.html

相关文章:

  • 江西航达建设集团网站短视频培训学校
  • 网站模板切换seo职位具体做什么
  • 链接点开网页表白的网站怎么做的百度高级搜索入口
  • 做淘宝网站报告昆明seocn整站优化
  • 网站功能有哪些app推广代理平台
  • 广东省路桥建设有限公司网站专业北京网站建设公司
  • 网站建设 电子书百度指数的主要功能有
  • 做网站图片属性百度广告怎么投放多少钱
  • 上海定制网站建设费用深圳营销型网站建设
  • 游戏系统网站开发说明书市场营销八大营销模式
  • 泰安网页以下哪个单词表示搜索引擎优化
  • 创业做社交网站黄页网站推广app咋做广告
  • 网站注销申请影视网站怎么优化关键词排名
  • 湖南大型网站建设公司优化网站seo
  • 对红色网站建设的建议免费创建属于自己的网站
  • 济南营销网站建设宜兴百度推广公司
  • 电子商务网站开发的目的是什么招聘网站排名
  • 网站建设的总体目标是什么火星时代教育培训机构怎么样
  • 可以做配音兼职的网站b站推广网站2024
  • 网站域名到期后果品牌营销推广
  • 邵阳做网站搜索引擎优化的缺点包括
  • 用宝塔给远程网站做备份竞价账户托管公司哪家好
  • 佛山高端网站建设报价百度移动点击排名软件
  • 建立网站怎么做什么网站推广比较好
  • 做网站一定要学java吗什么是网络营销?
  • 网站建设评分细则搜索引擎优化案例分析
  • 阿里云可以做哪些网站网络推广途径
  • 泰安人力资源招聘广州企业网站seo
  • 网站建设服务价格表网站建设怎么弄
  • 关于php动态网站开发的书籍百度图片搜索网页版