CREATE TABLE oauth2_authorization
(
id varchar(100) NOT NULL,
registered_client_id varchar(100) NOT NULL,
principal_name varchar(200) NOT NULL,
authorization_grant_type varchar(100) NOT NULL,
attributes varchar(4000) NULL,
state varchar(500) NULL,
authorization_code_value blob NULL,
authorization_code_issued_at
timestamp NULL,
authorization_code_expires_at timestamp NULL,
authorization_code_metadata varchar(2000) NULL,
access_token_value blob NULL,
access_token_issued_at timestamp NULL,
access_token_expires_at timestamp NULL,
access_token_metadata varchar(2000) NULL,
access_token_type varchar(100) NULL,
access_token_scopes varchar(1000) NULL,
oidc_id_token_value blob NULL,
oidc_id_token_issued_at timestamp NULL,
oidc_id_token_expires_at timestamp NULL,
oidc_id_token_metadata varchar(2000) NULL,
refresh_token_value blob NULL,
refresh_token_issued_at timestamp NULL,
refresh_token_expires_at timestamp NULL,
refresh_token_metadata varchar(2000) NULL,
PRIMARY KEY (id)
);
❝
这里的机制目前还没有研究,先挖个坑。
同样它也需要一个持久化服务接口OAuth2AuthorizationService
并注入Spring IoC:
/**
* 管理OAuth2授权信息服务
* @param jdbcTemplate the jdbc template
* @param registeredClientRepository the registered client repository
* @return the o auth 2 authorization service
*/
@Bean
public OAuth2AuthorizationService authorizationService(JdbcTemplate jdbcTemplate,
RegisteredClientRepository registeredClientRepository) {
return new JdbcOAuth2AuthorizationService(jdbcTemplate,
registeredClientRepository);
}
持久化到数据库的OAuth2Authorization
用JSON表示为:
{
“id”: “aa2f6e7d-d9b9-4360-91ef-118cbb6d4b09”,
“registered_client_id”: “658cd010-4d8c-4824-a8c7-a86b642299af”,
“principal_name”: “felord”,
“authorization_grant_type”: “authorization_code”,
“attributes”: “{”@class":“java.util.CollectionsKaTeX parse error: Expected group as argument to '\"' at position 317: …rization_code\"}̲,\"responseType…UnmodifiableSet”,[“message.read”,“message.write”]],“state”:“9gTcVNXgV8Pn_Ron3bkFb6M92AYCodeWKoEd6xxaiUg=”,“additionalParameters”:{“@class”:“java.util.CollectionsKaTeX parse error: Expected group as argument to '\"' at position 18: …modifiableMap\"}̲,\"authorizatio…UnmodifiableMap”}},“java.security.Principal”:{“@class”:“org.springframework.security.authentication.UsernamePasswordAuthenticationToken”,“authorities”:[“java.util.CollectionsKaTeX parse error: Expected group as argument to '\"' at position 143: …":\"ROLE_USER\"}̲]],\"details\":…UnmodifiableSet”,[{“@class”:“org.springframework.security.core.authority.SimpleGrantedAuthority”,“authority”:“ROLE_USER”}]],“accountNonExpired”:true,“accountNonLocked”:true,“credentialsNonExpired”:true,“enabled”:true},“credentials”:null},“org.springframework.security.oauth2.server.authorization.OAuth2Authorization.AUTHORIZED_SCOPE”:[“java.util.Collections$UnmodifiableSet”,[“message.read”,“message.write”]]}",
“state”: null,
“authorization_code_value”: “EZFxDcsKoaGtyqRTS0oNMg85EcVcyLdVssuD3SV-o0FvNXsSTRjTmCdu0ZPZnVIQ7K4TTSzrvLwBqoRXOigo_dWVNeqE44LjHHL_KtujM_Mxz8hLZgGhtfipvTdpWWR1”,
“authorization_code_issued_at”: “2021-11-11 18:44:45”,
“authorization_code_expires_at”: “2021-11-11 18:49:45”,
“authorization_code_metadata”: “{”@class":“java.util.Collections$UnmodifiableMap”,“metadata.token.invalidated”:true}",
“access_token_value”: “eyJ4NXQjUzI1NiI6IlZGR1F4Q21nSEloX2dhRi13UGIxeEM5b0tBMXc1bGEwRUZtcXFQTXJxbXciLCJraWQiOiJmZWxvcmRjbiIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiJmZWxvcmQiLCJhdWQiOiJmZWxvcmQtY2xpZW50IiwibmJmIjoxNjM2NjI3NDg0LCJzY29wZSI6WyJtZXNzYWdlLnJlYWQiLCJtZXNzYWdlLndyaXRlIl0sImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo5MDAwIiwiZXhwIjoxNjM2NjI3Nzg0LCJpYXQiOjE2MzY2Mjc0ODR9.CFzye9oIh8-ZMpyp9XoIXIQLnj2Sn17yZ9bgn7NYAbrp2hRq-Io_Se2SJpSEMa_Ce44aOGmcLTmIOILYUxlU08QCtHgr4UfCZttzroQhEn3Qui7fixBMprPYqxmu2KL5G_l3q5EWyh4G0ilHpByCBDeBGAl7FpaxSDlelnBfNGs9q6nJCs7aC40U_YPBRLoCBLVK1Y8t8kQvNu8NqCkS5D5DZAogpmlVg7jSIPz1UXVIh7iDTTQ1wJl6rZ1E87E0UroX4eSuYfMQ351y65IUlB14hvKhu03yDLTiVKtujOo3m0DAkJTbk3ZkFZEmDf4N3Yn-ktU7cyswQWa1bKf3og”,
“access_token_issued_at”: “2021-11-11 18:44:45”,
“access_token_expires_at”: “2021-11-11 18:49:45”,
“access_token_metadata”: “{”@class":“java.util.CollectionsKaTeX parse error: Expected '}', got 'EOF' at end of input: …til.CollectionsUnmodifiableMap”,“sub”:“felord”,“aud”:[“java.util.Collections S i n g l e t o n L i s t , ¨ [ f ¨ e l o r d − c l i e n t ] ¨ ] , n ¨ b f : ¨ [ j ¨ a v a . t i m e . I n s t a n t , ¨ 1636627484.674000000 ] , s ¨ c o p e : ¨ [ j ¨ a v a . u t i l . C o l l e c t i o n s SingletonList\",[\"felord-client\"]],\"nbf\":[\"java.time.Instant\",1636627484.674000000],\"scope\":[\"java.util.Collections SingletonList,¨[f¨elord−client]¨],n¨bf:¨[j¨ava.time.Instant,¨1636627484.674000000],s¨cope:¨[j¨ava.util.CollectionsUnmodifiableSet”,[“message.read”,“message.write”]],“iss”:[“java.net.URL”,“http://localhost:9000”],“exp”:[“java.time.Instant”,1636627784.674000000],“iat”:[“java.time.Instant”,1636627484.674000000]},“metadata.token.invalidated”:false}",
“access_token_type”: “Bearer”,
“access_token_scopes”: “message.read,message.write”,
“oidc_id_token_value”: null,
“oidc_id_token_issued_at”: null,
“oidc_id_token_expires_at”: null,
“oidc_id_token_metadata”: null,
“refresh_token_value”: “hbD9dVMpu855FhDDOYapwsQSx8zO9iPX5LUZKeXWzUcbE2rgYRV-sgXl5vGwyByLNljcqVyK9Pgquzbcoe6dkt0_yPQPJfxLY8ezEQ-QREBjxNYqecd6OI9SHMQkBObG”,
“refresh_token_issued_at”: “2021-11-11 18:44:45”,
“refresh_token_expires_at”: “2021-11-11 19:44:45”,
“refresh_token_metadata”: “{”@class":“java.util.Collections$UnmodifiableMap”,“metadata.token.invalidated”:false}"
}
❝
存储的东西还是比较全的,甚至把Java类都序列化了。
确认授权持久化
资源拥有者(Resource Owner)对授权的确认信息OAuth2AuthorizationConsent
的持久化,这个比较简单。下面是定义脚本:
CREATE TABLE oauth2_authorization_consent
(
registered_client_id varchar(100) NOT NULL,
principal_name varchar(200) NOT NULL,
authorities varchar(1000) NOT NULL,
PRIMARY KEY (registered_client_id, principal_name)
);
对应的持久化服务接口为OAuth2AuthorizationConsentService
,也要注入Spring IoC:
@Bean
public OAuth2AuthorizationConsentService authorizationConsentService(JdbcTemplate jdbcTemplate,
RegisteredClientRepository registeredClientRepository) {
return new JdbcOAuth2AuthorizationConsentService(jdbcTemplate, registeredClientRepository);
}
持久化到数据库的OAuth2AuthorizationConsent
用JSON表示为:
{
“registered_client_id”: “658cd010-4d8c-4824-a8c7-a86b642299af”,
“principal_name”: “felord”,
“authorities”: “SCOPE_message.read,SCOPE_message.write”
}
JWK
JWK全称JSON Web Key,是一个将加密的密钥用JSON对象描述的规范,和JWT一样是JOSE规范的重要组成部分。规范的详细定义可参考JWK文档。JWK参考示例:
{
“keys”: [
{
“kty”: “RSA”,
“x5t#S256”: “VFGQxCmgHIh_gaF-wPb1xC9oKA1w5la0EFmqqPMrqmw”,
“e”: “AQAB”,
“kid”: “felordcn”,
“x5c”: [
“MIIDczCCAlugAwIBAgIEURwmYzANBgkqhkiG9w0BAQsFADBqMQ0wCwYDVQQGEwQoY24pMQ0wCwYDVQQIEwQoaG4pMQ0wCwYDVQQHEwQoenopMRMwEQYDVQQKEwooZmVsb3JkY24pMRMwEQYDVQQLEwooZmVsb3JkY24pMREwDwYDVQQDEwgoRmVsb3JkKTAeFw0yMTEwMTgwNDUwMTRaFw0yMjEwMTgwNDUwMTRaMGo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p-il3JNiOpcnLCbAKZgzm4qaugeuOD02_M0YcMW2Jqg3SUWpC-9vu9yt5dVc1xpmpwEAamKzvynI3Zxl44ddlA8RRAS6kV0OUcKbEG63G3yZ4MHnhrFrZDuvlwfSSgn0wFOC_b6mJ-bUxByMAXKD0d4DS2B2mVl7RO5AzL4SFcqtZZE3Drtcli67bsENyOQeoTVaKO6gu5PEEFlQ7pHKw”
}
]
}
❝
JWK的意义在于生成JWT和提供JWK端点给OAuth2.0资源服务器解码校验JWT。
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注Java)
总结
虽然面试套路众多,但对于技术面试来说,主要还是考察一个人的技术能力和沟通能力。不同类型的面试官根据自身的理解问的问题也不尽相同,没有规律可循。
上面提到的关于这些JAVA基础、三大框架、项目经验、并发编程、JVM及调优、网络、设计模式、spring+mybatis源码解读、Mysql调优、分布式监控、消息队列、分布式存储等等面试题笔记及资料
有些面试官喜欢问自己擅长的问题,比如在实际编程中遇到的或者他自己一直在琢磨的这方面的问题,还有些面试官,尤其是大厂的比如 BAT 的面试官喜欢问面试者认为自己擅长的,然后通过提问的方式深挖细节,刨根到底。
一个人可以走的很快,但一群人才能走的更远。如果你从事以下工作或对以下感兴趣,欢迎戳这里加入程序员的圈子,让我们一起学习成长!
AI人工智能、Android移动开发、AIGC大模型、C C#、Go语言、Java、Linux运维、云计算、MySQL、PMP、网络安全、Python爬虫、UE5、UI设计、Unity3D、Web前端开发、产品经理、车载开发、大数据、鸿蒙、计算机网络、嵌入式物联网、软件测试、数据结构与算法、音视频开发、Flutter、IOS开发、PHP开发、.NET、安卓逆向、云计算
到底。
一个人可以走的很快,但一群人才能走的更远。如果你从事以下工作或对以下感兴趣,欢迎戳这里加入程序员的圈子,让我们一起学习成长!
AI人工智能、Android移动开发、AIGC大模型、C C#、Go语言、Java、Linux运维、云计算、MySQL、PMP、网络安全、Python爬虫、UE5、UI设计、Unity3D、Web前端开发、产品经理、车载开发、大数据、鸿蒙、计算机网络、嵌入式物联网、软件测试、数据结构与算法、音视频开发、Flutter、IOS开发、PHP开发、.NET、安卓逆向、云计算