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

灰蓝 网站模板做网站是怎么赚钱吗

灰蓝 网站模板,做网站是怎么赚钱吗,魏县住房和城乡建设局网站,常用博客建站程序基本认证概述 基本认证#xff08;Basic Auth#xff09;是保护REST API最简单的方式之一。它通过在HTTP请求头中携带Base64编码过的用户名和密码来进行身份验证。由于基本认证不使用cookie#xff0c;因此没有会话或用户登出的概念#xff0c;这意味着每次请求都必须包含…基本认证概述 基本认证Basic Auth是保护REST API最简单的方式之一。它通过在HTTP请求头中携带Base64编码过的用户名和密码来进行身份验证。由于基本认证不使用cookie因此没有会话或用户登出的概念这意味着每次请求都必须包含身份验证信息。 Maven依赖 要在Spring Boot项目中使用Spring Security需要添加以下Maven依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-security/artifactId /dependencySpring Security配置 接下来我们将配置Spring Security以使用内存中的基本认证。创建一个名为SpringSecurityConfig的类并加入如下代码 import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.security.web.SecurityFilterChain;Configuration EnableWebSecurity public class SpringSecurityConfig {Beanpublic static PasswordEncoder passwordEncoder() {return new BCryptPasswordEncoder();}Beanpublic SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {http.csrf().disable().authorizeHttpRequests(authorize - authorize.anyRequest().authenticated()).httpBasic(Customizer.withDefaults());return http.build();}Beanpublic UserDetailsService userDetailsService() {UserDetails ramesh User.builder().username(ramesh).password(passwordEncoder().encode(password)).roles(USER).build();UserDetails admin User.builder().username(admin).password(passwordEncoder().encode(admin)).roles(ADMIN).build();return new InMemoryUserDetailsManager(ramesh, admin);} }默认情况下Spring Security同时启用了基于表单的身份验证和HTTP基本认证。上述配置中我们通过调用httpBasic()方法仅启用了基本认证。此外我们还定义了一个UserDetailsService实现用于内存中的用户管理。 创建REST API 为了测试上面的Spring Security配置创建一个简单的REST API并使用Spring Security加以保护。当向Spring Boot项目添加Spring Security依赖后默认所有应用URL都会受到保护。 import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;RestController public class WelComeController {GetMapping(/greeting)public String greeting(Authentication authentication) {return Spring Security In-memory Authentication Example - Welcome authentication.getName();} }使用Postman测试REST API 要测试REST API需要在请求头中传递Base64编码过的用户名和密码即基本认证。 如果未提供这些凭证将收到401状态码这表明Spring Security正在正确地保护API。 总结 通过本教程您应该了解了如何配置Spring Security的内置HTTP基本认证来保护REST API。 基本认证虽然简单但在某些场景下仍是非常实用的选择。
http://www.hkea.cn/news/14360753/

相关文章:

  • wordpress建立网站企业网站手机端模板下载
  • 江苏住房城乡建设网站swiper做的全屏网站
  • 怎样找公司做单的网站网址域名注册信息查询
  • 哪个网站做贷款推广初中学历怎么提升大专学历
  • 注册网站刀具与钢材范围经典软文文案
  • 重庆孝爱之家网站建设wordpress 瀑布流分页
  • 保健品网站源代码群晖WordPress无端口号
  • 大连专业手机自适应网站制作公司建网站怎么做
  • 网站建设条款最佳磁力搜索引擎
  • 织梦绿色企业网站模板做网站就业要会什么
  • 企业网站开发研究现状企业年金怎么领取最划算
  • 宿迁网站建设公司排名如何看网站的流量
  • 做自己的博客网站湘潭seo优化
  • 中山 网站建设一条龙服务专题型定制网站建设
  • 佛山大良网站建设海南seo外包
  • linux wordpress建站教程赤壁网站建设公司
  • 温州最大的外贸公司网站优化技术
  • 虾皮这种网站根本不值得做机房网站建设方案
  • 网站建设朝阳网站建设 海南
  • 微网站摇一摇免费推广预期效果怎么写
  • 做网站宣传费用记什么科目常用的网站类型有哪些类型有哪些类型有哪些
  • 网站建设用模板域名批量注册查询
  • 大石桥城乡规划建设局网站网站优化 英文
  • 宁波网站制作相信荣胜网络分分钟制作一个h5页面
  • 微信平台与微网站开发便宜网站开发培训
  • 招聘类网站建设北京哪家公司做网站
  • asp网站安全如何做品牌营销推广方案怎么做
  • 南昌做网站公司南通网站建设公司哪个好
  • 越秀金融大厦北塔昆明seo关键词
  • 西南城乡建设部网站首页黄石规划建设局网站