参考一下两个案例:https://www.cnblogs.com/haoliyou/p/9606018.html

https://www.cnblogs.com/haoliyou/p/9606036.html

.authorizedGrantTypes("authorization_code", "password", "refresh_token")//授权码模式和password模式

package com.auth.server.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
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.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
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; /**
* 授权配置
* @author wb0024
*
*/
@Configuration
@EnableAuthorizationServer
public class ServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager; @Qualifier("myUserDetailsService")
@Autowired
private UserDetailsService userDetailsService; // @Autowired
// @Qualifier("dataSource")
// private DataSource dataSource; @Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
// 配置token获取和验证时的策略
security.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()");
} @Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("client")
// secret密码配置从 Spring Security 5.0开始必须以 {加密方式}+加密后的密码 这种格式填写 /* * 当前版本5新增支持加密方式:
* bcrypt - BCryptPasswordEncoder (Also used for encoding)
* ldap - LdapShaPasswordEncoder
* MD4 - Md4PasswordEncoder
* MD5 - new MessageDigestPasswordEncoder("MD5")
* noop - NoOpPasswordEncoder
* pbkdf2 - Pbkdf2PasswordEncoder
* scrypt - SCryptPasswordEncoder
* SHA-1 - new MessageDigestPasswordEncoder("SHA-1")
* SHA-256 - new MessageDigestPasswordEncoder("SHA-256")
* sha256 - StandardPasswordEncoder*/ .secret("{noop}secret")
.scopes("all")
.authorizedGrantTypes("authorization_code", "password", "refresh_token")//授权码模式和password模式
.autoApprove(true);
} @Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
// // 配置tokenStore,保存到redis缓存中
// endpoints.authenticationManager(authenticationManager)
// .tokenStore(new MyRedisTokenStore(redisConnectionFactory))
// // 不添加userDetailsService,刷新access_token时会报错
// .userDetailsService(userDetailsService); // 使用最基本的InMemoryTokenStore生成token
endpoints.authenticationManager(authenticationManager).tokenStore(memoryTokenStore()); } // 使用最基本的InMemoryTokenStore生成token
@Bean
public TokenStore memoryTokenStore() {
return new InMemoryTokenStore();
}
}

  

springboot oauth 鉴权之——password、authorization_code鉴权的更多相关文章

  1. 基于Springboot集成security、oauth2实现认证鉴权、资源管理

    1.Oauth2简介 OAuth(开放授权)是一个开放标准,允许用户授权第三方移动应用访问他们存储在另外的服务提供者上的信息,而不需要将用户名和密码提供给第三方移动应用或分享他们数据的所有内容,OAu ...

  2. HDU 1569 - 方格取数(2) - [最大点权独立集与最小点权覆盖集]

    嗯,这是关于最大点权独立集与最小点权覆盖集的姿势,很简单对吧,然后开始看题. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1569 Time Limi ...

  3. poj3565 Ants km算法求最小权完美匹配,浮点权值

    /** 题目:poj3565 Ants km算法求最小权完美匹配,浮点权值. 链接:http://poj.org/problem?id=3565 题意:给定n个白点的二维坐标,n个黑点的二维坐标. 求 ...

  4. springboot oauth 鉴权之——password鉴权相当于jwt鉴权模式

    近期一直在研究鉴权方面的各种案例,这几天有空,写一波总结及经验. 第一步:什么是 OAuth鉴权 OAuth2是工业标准的授权协议.OAuth2取代了在2006创建的原始OAuthTM协议所做的工作. ...

  5. springboot oauth 鉴权之——授权码authorization_code鉴权

    近期一直在研究鉴权方面的各种案例,这几天有空,写一波总结及经验. 第一步:什么是 OAuth鉴权 OAuth2是工业标准的授权协议.OAuth2取代了在2006创建的原始OAuthTM协议所做的工作. ...

  6. springboot+security整合(3)自定义鉴权

    说明 springboot 版本 2.0.3源码地址:点击跳转 系列 springboot+security 整合(1) springboot+security 整合(2) springboot+se ...

  7. 如何在SpringBoot中集成JWT(JSON Web Token)鉴权

    这篇博客主要是简单介绍了一下什么是JWT,以及如何在Spring Boot项目中使用JWT(JSON Web Token). 1.关于JWT 1.1 什么是JWT 老生常谈的开头,我们要用这样一种工具 ...

  8. Go+gRPC-Gateway(V2) 微服务实战,小程序登录鉴权服务(五):鉴权 gRPC-Interceptor 拦截器实战

    拦截器(gRPC-Interceptor)类似于 Gin 中间件(Middleware),让你在真正调用 RPC 服务前,进行身份认证.参数校验.限流等通用操作. 系列 云原生 API 网关,gRPC ...

  9. hdu1569 方格取数(2) 最大点权独立集=总权和-最小点权覆盖集 (最小点权覆盖集=最小割=最大流)

    /** 转自:http://blog.csdn.net/u011498819/article/details/20772147 题目:hdu1569 方格取数(2) 链接:https://vjudge ...

随机推荐

  1. PowerShell创建 Profile

    profile主要用于个性化常用的函数.别名等等.每次加载powershell的时候,都会执行profile中的内容. 查看是否有profile: $profile 如果结果是false说明没有.则创 ...

  2. MySQL--数据插入

    1.创建表的同时插入其他表的数据 CREATE TABLE table_name SELECT ... FROM    ... [...] 例: CREATE TABLE tabl_memory EN ...

  3. 2019收藏盘点(编程语言/AI/面试/实用工具)

    2020.1.5更新 我看过的后面会加上评价 编程学习 java开源项目汇总: https://github.com/Snailclimb/awesome-java 大数据学习入门: https:// ...

  4. 获取IP和IP地址

    <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>; <script type= ...

  5. tomcat设置远程监听端口(linux&windows)

    1.Linxu系统: apach/bin/startup.sh开始处中增加如下内容: declare -x CATALINA_OPTS="-server -Xdebug -Xnoagent ...

  6. List集合分组依据集合中对象的属性

    直接上代码 用到了Spring的BeanWrapper类 public static <T, K> Map<K, List<T>> groupByProperty( ...

  7. spark安装和使用

    local模式 概述 local模式就是在一台计算机上运行spark程序,通常用于在本机上练手和测试,它将线程映射为worker. 1)local: 所有计算都运行在一个线程当中,没有任何并行计算,通 ...

  8. mysql之DTS的那些事

    最近才考虑数据库迁移,想起了之前做DTS踩过的那些坑. 基于数据库迁移,比如从源A库迁移到源B库,包括但不限于数据库上云. 数据库迁移方案有两种场景: (1).停机迁移方案 这种方案是允许停服的场景, ...

  9. nfs存储(一)

    排错思路: .环境问题 SElinux firewalld 网络是否能通 .配置问题 所有的故障只会出现在你曾经修改过的文件中 /etc/rsyncd.conf /etc/rsyncd.passwor ...

  10. rsync实战(二)

    加两个需求:1.增加一个模块2.每个模块不同的用户名 步骤: .修改配置文件/etc/rsyncd.conf [backup] comment = commit path = /backup auth ...