springcloud的资源管理(二)-oauth2的授权+密码

本文介绍了OAuth2的授权码和密码模式在实际生产中的应用,详细讲解了这两种模式的配置过程,包括认证服务器配置、Spring Security配置和客户端配置。并提供了测试步骤,包括授权码和密码模式的测试方法,帮助读者理解如何在SpringCloud环境中实现资源管理与安全授权。
摘要由CSDN通过智能技术生成

目录

一:密码和授权码

二:配置

三:测试

三:总结


一:密码和授权码

  在上一节中,我们讨论了oauth2的四种认证方式。在实际生产中授权和密码模式使用的最多,因此,我们主要讨论这2中方式。

至于在这个认证流程请参考上篇。

 

二:配置

1.认证服务器的配置:

      认证服务器的配置主要就是3个部分:(1)客户端配置:配置客户端id,密码等信息。(2)令牌端点安全约束:配置token获取

  验证策略。(3)token产出和存储:存储token

      代码:

package springcloud.oauth2.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;


@Configuration
public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
  
  @Autowired
  private AuthenticationManager authen
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值