Skip to content

Commit 77ce6d8

Browse files
author
monkeyk7
committed
Upgrade 2.0.0. spring-boot
1 parent 39d6996 commit 77ce6d8

File tree

76 files changed

+3924
-617
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3924
-617
lines changed
2.19 MB
Binary file not shown.
49.8 KB
Binary file not shown.

others/database/initial_data.ddl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,39 @@ truncate user_privilege;
55
-- admin, password is admin ( All privileges)
66
insert into user_(id,guid,create_time,email,password,phone,username,default_user)
77
values
8-
(21,'29f6004fb1b0466f9572b02bf2ac1be8',now(),'[email protected]','21232f297a57a5a743894a0e4a801fc3','028-1234567','admin',true);
8+
(21,'29f6004fb1b0466f9572b02bf2ac1be8',now(),'[email protected]','$2a$10$XWN7zOvSLDiyxQnX01KMXuf5NTkkuAUtt23YxUMWaIPURcR7bdULi','028-1234567','admin',1);
9+
10+
insert into user_privilege(user_id,privilege) values (21,'ADMIN');
11+
insert into user_privilege(user_id,privilege) values (21,'UNITY');
12+
insert into user_privilege(user_id,privilege) values (21,'MOBILE');
913

1014
-- unity, password is unity ( ROLE_UNITY)
1115
insert into user_(id,guid,create_time,email,password,phone,username,default_user)
1216
values
13-
(22,'55b713df1c6f423e842ad68668523c49',now(),'unity@wdcy.cc','439b3a25b555b3bc8667a09a036ae70c','','unity',false);
17+
(22,'55b713df1c6f423e842ad68668523c49',now(),'unity@andaily.com','$2a$10$gq3eUch/h.eHt20LpboSXeeZinzSLBk49K5KD.Ms4/1tOAJIsrrfq','','unity',0);
1418

1519
insert into user_privilege(user_id,privilege) values (22,'UNITY');
1620

1721
-- mobile, password is mobile ( ROLE_MOBILE)
1822
insert into user_(id,guid,create_time,email,password,phone,username,default_user)
1923
values
20-
(23,'612025cb3f964a64a48bbdf77e53c2c1',now(),'mobile@wdcy.cc','532c28d5412dd75bf975fb951c740a30','','mobile',false);
24+
(23,'612025cb3f964a64a48bbdf77e53c2c1',now(),'mobile@andaily.com','$2a$10$BOmMzLDaoiIQ4Q1pCw6Z4u0gzL01B8bNL.0WUecJ2YxTtHVRIA8Zm','','mobile',0);
2125

2226
insert into user_privilege(user_id,privilege) values (23,'MOBILE');
2327

2428

2529
-- initial oauth client details test data
26-
-- 'unity-client' support browser, js(flash) visit
27-
-- 'mobile-client' only support mobile-device visit
30+
-- 'unity-client' support browser, js(flash) visit, secret: unity
31+
-- 'mobile-client' only support mobile-device visit, secret: mobile
2832
truncate oauth_client_details;
2933
insert into oauth_client_details
3034
(client_id, resource_ids, client_secret, scope, authorized_grant_types,
3135
web_server_redirect_uri,authorities, access_token_validity,
3236
refresh_token_validity, additional_information, create_time, archived, trusted)
3337
values
34-
('unity-client','unity-resource', 'unity', 'read,write','authorization_code,refresh_token,implicit',
35-
null,'ROLE_CLIENT',null,
38+
('unity-client','sos-resource', '$2a$10$QQTKDdNfj9sPjak6c8oWaumvTsa10MxOBOV6BW3DvLWU6VrjDfDam', 'read','authorization_code,refresh_token,implicit',
39+
'http://localhost:8080/spring-oauth-server/unity/dashboard','ROLE_CLIENT',null,
3640
null,null, now(), 0, 0),
37-
('mobile-client','mobile-resource', 'mobile', 'read,write','password,refresh_token',
41+
('mobile-client','sos-resource', '$2a$10$uLvpxfvm3CuUyjIvYq7a9OUmd9b3tHFKrUaMyU/jC01thrTdkBDVm', 'read','password,refresh_token',
3842
null,'ROLE_CLIENT',null,
3943
null,null, now(), 0, 0);

others/database/initial_db.ddl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-- ###############
22
-- create MySQL database , if need create, cancel the comment
33
-- ###############
4-
-- create database if not exists oauth2 default character set utf8;
5-
-- use oauth2 set default character = utf8;
4+
-- create database if not exists oauth2_boot default character set utf8;
5+
-- use oauth2_boot set default character = utf8;
66

77
-- ###############
88
-- grant privileges to oauth2/oauth2

others/how_to_use.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11

22

33
使用的主要技术与版本号
4-
*Spring (4.1.6.RELEASE)
5-
*Spring Security (4.0.4.RELEASE)
6-
*spring-security-oauth2 (2.0.14.RELEASE)
4+
*Spring-Boot (2.0.1.RELEASE)
5+
*spring-security-oauth2 (2.3.0.RELEASE)
76

87

98
如何使用?
10-
1.项目是Maven管理的, 需要本地安装maven(开发用的maven版本号为3.1.0), 还有MySql(开发用的mysql版本号为5.6)
9+
1.项目是Maven管理的, 需要本地安装maven(开发用的maven版本号为3.3.3), 还有MySql(开发用的mysql版本号为5.6)
1110

1211
2.下载(或clone)项目到本地
1312

14-
3.创建MySQL数据库(如数据库名oauth2), 并运行相应的SQL脚本(脚本文件位于others/database目录),
13+
3.创建MySQL数据库(数据库名oauth2_boot), 并运行相应的SQL脚本(脚本文件位于others/database目录),
1514
运行脚本的顺序: initial_db.ddl -> oauth.ddl -> initial_data.ddl
1615

17-
4.修改spring-oauth-server.properties(位于src/resources目录)中的数据库连接信息(包括username, password等)
16+
4.修改application.properties(位于src/resources目录)中的数据库连接信息(包括username, password等)
1817

1918
5.将本地项目导入到IDE(如Intellij IDEA)中,配置Tomcat(或类似的servlet运行服务器), 并启动Tomcat(默认端口为8080)
2019
另: 也可通过maven package命令将项目编译为war文件(spring-oauth-server.war),
21-
将war放在Tomcat中并启动(注意: 这种方式需要将spring-oauth-server.properties加入到classpath中并正确配置数据库连接信息).
20+
将war放在Tomcat中并启动(注意: 这种方式需要将application.properties加入到classpath中并正确配置数据库连接信息).
2221

2322
6.参考oauth_test.txt(位于others目录)的内容并测试之(也可在浏览器中访问相应的地址,如: http://localhost:8080/spring-oauth-server).
2423

24+
7. 运行单元测试时请先创建数据库 oauth2_boot_test, 并依次运行SQL脚本.
25+
运行脚本的顺序: initial_db.ddl -> oauth.ddl
26+
2527

others/oauth_test.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
说明:只能使用admin或unity 账号登录才能有权限访问,若使用mobile账号登录将返回Access is denied
44
http://localhost:8080/spring-oauth-server/oauth/authorize?client_id=unity-client&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2funity%2fdashboard&response_type=code&scope=read
55

6-
说明: 由于mobile-client只支持password,refresh_token, 所以不管用哪个账号登录后都将返回Illegal action
6+
说明: 由于mobile-client只支持password,refresh_token, 所以不管用哪个账号登录后都将返回 OAuth Error
77
http://localhost:8080/spring-oauth-server/oauth/authorize?client_id=mobile-client&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2fm%2fdashboard&response_type=code&scope=read
88

99

1010

1111

1212
响应的URL如:
13-
http://localhost:8080/spring-oauth-server/unity/dashboard.htm?code=zLl170
13+
http://localhost:8080/spring-oauth-server/unity/dashboard?code=hGQ8qx
1414

1515
通过code换取access_token [POST]
16-
http://localhost:8080/spring-oauth-server/oauth/token?client_id=unity-client&client_secret=unity&grant_type=authorization_code&code=zLl170&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2funity%2fdashboard
16+
http://localhost:8080/spring-oauth-server/oauth/token?client_id=unity-client&client_secret=unity&grant_type=authorization_code&code=hGQ8qx&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2funity%2fdashboard
1717

1818

1919
方式2:基于客户端 (注意参数中的username,password,对应用户的账号,密码) [POST]
20-
http://localhost:8080/spring-oauth-server/oauth/token?client_id=mobile-client&client_secret=mobile&grant_type=password&scope=read,write&username=mobile&password=mobile
20+
http://localhost:8080/spring-oauth-server/oauth/token?client_id=mobile-client&client_secret=mobile&grant_type=password&scope=read&username=mobile&password=mobile
2121

22-
说明:由于unity-client不支持password,所以若用unity-client通过password方式去授权,将返回invalid_grant
23-
http://localhost:8080/spring-oauth-server/oauth/token?client_id=unity-client&client_secret=unity&grant_type=password&scope=read,write&username=mobile&password=mobile
22+
说明:由于unity-client不支持password,所以若用unity-client通过password方式去授权,将返回 invalid_client
23+
http://localhost:8080/spring-oauth-server/oauth/token?client_id=unity-client&client_secret=unity&grant_type=password&scope=read&username=mobile&password=mobile
2424

2525

2626

@@ -29,7 +29,7 @@ http://localhost:8080/spring-oauth-server/oauth/token?client_id=unity-client&cli
2929

3030

3131
获取access_token后访问资源 [GET]
32-
http://localhost:8080/spring-oauth-server/unity/dashboard.htm?access_token=3420d0e0-ed77-45e1-8370-2b55af0a62e8
32+
http://localhost:8080/spring-oauth-server/unity/dashboard?access_token=89767569-5b78-4b26-ae2d-d361aa3e6bf9
3333

3434

3535

@@ -38,11 +38,12 @@ http://localhost:8080/spring-oauth-server/oauth/token?client_id=mobile-client&cl
3838

3939

4040
Restful OAuth2 Test [POST]
41-
URL: /oauth2/rest_token
41+
URL: /oauth/rest_token
4242
ContentType: application/json
4343

4444
DEMO URL: http://localhost:8080/spring-oauth-server/oauth2/rest_token
45-
Request Body: {"grant_type":"client_credentials","scope":"read","client_id":"credentials","client_secret":"credentials","username":"user","password":"123"}
45+
Request Body:
46+
{"grant_type":"client_credentials","scope":"read","client_id":"credentials","client_secret":"credentials","username":"user","password":"123"}
4647

4748
Response Body:
4849
{
@@ -56,7 +57,7 @@ Response Body:
5657

5758

5859
更多的测试请访问
59-
http://git.oschina.net/mkk/spring-oauth-client
60+
https://gitee.com/mkk/spring-oauth-client
6061

6162

6263
------------------------------------------------------------------------------------------------
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
3+
记录 spring-oauth-server 升级到 spring-boot 后的变化
4+
5+
1. client_secret 加密保存
6+
2. 密码加密方式由 MD5 变成 BCrypt
7+
3. resourceId 可为可选
8+
4.增加CSRF支持
9+
10+
11+

0 commit comments

Comments
 (0)