Skip to content

Commit 5acb534

Browse files
新增客户端模块及代码优化调整
1 parent b3de4ce commit 5acb534

28 files changed

+1115
-54
lines changed

misc/ymp-conf.properties

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,32 @@ ymp.configs.module.oauth.error_adapter_class=
3333
ymp.params.module.oauth.need_authorization_processor_class=
3434

3535
# OAuth\u5F02\u5E38\u9519\u8BEF\u5904\u7406\u5668\uFF0C\u53EF\u9009\u53C2\u6570
36-
ymp.configs.webmvc.error_processor_class=net.ymate.module.oauth.web.WebErrorProcessor
36+
ymp.configs.webmvc.error_processor_class=net.ymate.module.oauth.web.WebErrorProcessor
37+
38+
#-------------------------------------
39+
# module.oauth.client \u6A21\u5757\u521D\u59CB\u5316\u53C2\u6570
40+
#-------------------------------------
41+
42+
# OAuth\u5BA2\u6237\u7AEF\u5E10\u53F7\u4FE1\u606F\u63D0\u4F9B\u8005\u63A5\u53E3\u5B9E\u73B0\u7C7B, \u9ED8\u8BA4\u503C: net.ymate.module.oauth.client.impl.DefaultOAuthClientAccountProvider
43+
ymp.configs.module.oauth.client.account_provider_class=
44+
45+
# OAuth\u5BA2\u6237\u7AEF\u4EE4\u724C\u4FE1\u606F\u5B58\u50A8\u9002\u914D\u5668\u63A5\u53E3\u5B9E\u73B0\u7C7B, \u9ED8\u8BA4\u503C: net.ymate.module.oauth.client.impl.DefaultOAuthClientTokenStorageAdapter
46+
ymp.configs.module.oauth.client.token_storage_adapter_class=
47+
48+
# OAuth\u5BA2\u6237\u7AEF\u5E10\u53F7\u540D\u79F0\u5217\u8868\uFF0C\u591A\u4E2A\u540D\u79F0\u95F4\u7528'|'\u5206\u9694\uFF0C\u9ED8\u8BA4\u503C: default
49+
ymp.configs.module.oauth.client.account_name_list=
50+
51+
# OAuth\u5BA2\u6237\u7AEF\u5E10\u53F7\u5206\u914D\u7684client_id\u53C2\u6570\u503C, \u5FC5\u987B
52+
ymp.configs.module.oauth.client.default.client_id=
53+
54+
# OAuth\u5BA2\u6237\u7AEF\u5E10\u53F7\u5206\u914D\u7684client_secret\u53C2\u6570\u503C, \u5FC5\u987B
55+
ymp.configs.module.oauth.client.default.client_secret=
56+
57+
# OAuth\u5BA2\u6237\u7AEF\u4EE4\u724C\u8BF7\u6C42\u670D\u52A1URL\u5730\u5740, \u5FC5\u987B
58+
ymp.configs.module.oauth.client.default.service_url=
59+
60+
# OAuth\u5BA2\u6237\u7AEF\u5E10\u53F7\u914D\u7F6E\u7684\u91CD\u5B9A\u5411\u5730\u5740(\u4EE5https://\u6216http://\u5F00\u5934), \u53EF\u9009
61+
ymp.configs.module.oauth.client.default.redirect_uri=
62+
63+
# OAuth\u5BA2\u6237\u7AEF\u5E10\u53F7\u81EA\u5B9A\u4E49\u53C2\u6570, \u53EF\u9009
64+
ymp.configs.module.oauth.client.default.params.xxx=yyy

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515

1616
<modules>
1717
<module>ymate-module-oauth</module>
18+
<module>ymate-module-oauth-client</module>
1819
<module>ymate-module-oauth-impl</module>
1920
<module>ymate-module-oauth-model</module>
2021
</modules>
2122

2223
<properties>
2324
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24-
<ymate.platform.version>2.0.5</ymate.platform.version>
25-
<ymate.framework.version>2.0.5</ymate.framework.version>
25+
<ymate.platform.version>2.0.6</ymate.platform.version>
26+
<ymate.framework.version>2.0.6</ymate.framework.version>
2627
</properties>
2728

2829
<developers>
@@ -169,6 +170,11 @@
169170
<artifactId>ymate-platform-webmvc</artifactId>
170171
<version>${ymate.platform.version}</version>
171172
</dependency>
173+
<dependency>
174+
<groupId>net.ymate.framework</groupId>
175+
<artifactId>ymate-framework-commons</artifactId>
176+
<version>${ymate.framework.version}</version>
177+
</dependency>
172178
<dependency>
173179
<groupId>net.ymate.framework</groupId>
174180
<artifactId>ymate-framework-core</artifactId>

ymate-module-oauth-client/pom.xml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<artifactId>ymate-oauth-parent</artifactId>
9+
<groupId>net.ymate.module</groupId>
10+
<version>1</version>
11+
</parent>
12+
13+
<artifactId>ymate-module-oauth-client</artifactId>
14+
<version>1.0.0</version>
15+
<packaging>jar</packaging>
16+
17+
<name>ymate-module-oauth-client</name>
18+
<url>http://www.ymate.net/</url>
19+
<description>YMP OAuth Client Archetype</description>
20+
21+
<build>
22+
<resources>
23+
<resource>
24+
<directory>src/main/resources</directory>
25+
<excludes>
26+
<exclude>**/ymp-*.properties</exclude>
27+
</excludes>
28+
</resource>
29+
</resources>
30+
<pluginManagement>
31+
<plugins>
32+
<plugin>
33+
<groupId>org.apache.maven.plugins</groupId>
34+
<artifactId>maven-jar-plugin</artifactId>
35+
<configuration>
36+
<archive>
37+
<manifestSections>
38+
<manifestSection>
39+
<name>net/ymate/module/oauth/client/</name>
40+
</manifestSection>
41+
</manifestSections>
42+
<manifestEntries>
43+
<Specification-Version>${project.version}</Specification-Version>
44+
<Implementation-Title>${project.name}</Implementation-Title>
45+
<Implementation-Version>${maven.build.timestamp}</Implementation-Version>
46+
<Implementation-Vendor>www.ymate.net</Implementation-Vendor>
47+
</manifestEntries>
48+
</archive>
49+
</configuration>
50+
</plugin>
51+
</plugins>
52+
</pluginManagement>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-compiler-plugin</artifactId>
57+
<version>2.5.1</version>
58+
<configuration>
59+
<source>1.6</source>
60+
<target>1.6</target>
61+
</configuration>
62+
</plugin>
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-surefire-plugin</artifactId>
66+
<version>2.17</version>
67+
<configuration>
68+
<skipTests>true</skipTests>
69+
</configuration>
70+
</plugin>
71+
</plugins>
72+
</build>
73+
74+
<dependencies>
75+
<dependency>
76+
<groupId>junit</groupId>
77+
<artifactId>junit</artifactId>
78+
<scope>test</scope>
79+
</dependency>
80+
<dependency>
81+
<groupId>javax.servlet</groupId>
82+
<artifactId>servlet-api</artifactId>
83+
<scope>provided</scope>
84+
</dependency>
85+
<dependency>
86+
<groupId>net.ymate.platform</groupId>
87+
<artifactId>ymate-platform-core</artifactId>
88+
</dependency>
89+
<dependency>
90+
<groupId>net.ymate.framework</groupId>
91+
<artifactId>ymate-framework-commons</artifactId>
92+
</dependency>
93+
</dependencies>
94+
</project>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2007-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package net.ymate.module.oauth.client;
17+
18+
import net.ymate.module.oauth.client.base.OAuthAccount;
19+
20+
/**
21+
* OAuth客户端帐号信息提供者接口
22+
*
23+
* @author 刘镇 (suninformation@163.com) on 2018/10/6 下午3:50
24+
* @version 1.0
25+
*/
26+
public interface IOAuthClientAccountProvider {
27+
28+
/**
29+
* 默认客户端帐号主键名称
30+
*/
31+
String DEFAULT_ACCOUNT = "default";
32+
33+
String ACCOUNT_NAME_LIST = "account_name_list";
34+
35+
String SERVICE_URL = "service_url";
36+
37+
String CLIENT_ID = "client_id";
38+
39+
String CLIENT_SECRET = "client_secret";
40+
41+
String REDIRECT_URI = "redirect_uri";
42+
43+
String PARAMS_PREFIX = "params.";
44+
45+
/**
46+
* 初始化
47+
*
48+
* @param owner 所属模块对象
49+
* @throws Exception 可能产生的任何异常
50+
*/
51+
void init(IOAuthClients owner) throws Exception;
52+
53+
/**
54+
* 销毁
55+
*
56+
* @throws Exception 可能产生的任何异常
57+
*/
58+
void destroy() throws Exception;
59+
60+
/**
61+
* 判断是否包含指定id的客户端帐号配置
62+
*
63+
* @param accountId 客户端帐号主键名称
64+
* @return 若存在则返回true,否则返回false
65+
*/
66+
boolean hasAccount(String accountId);
67+
68+
/**
69+
* 获取指定id的客户端帐号信息
70+
*
71+
* @param accountId 客户端帐号主键名称
72+
* @return 返回OAuth客户端帐号元数据对象,若不存在则返回null
73+
*/
74+
OAuthAccount getAccount(String accountId);
75+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2007-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package net.ymate.module.oauth.client;
17+
18+
/**
19+
* @author 刘镇 (suninformation@163.com) on 2018/10/06 下午 15:26
20+
* @version 1.0
21+
*/
22+
public interface IOAuthClientModuleCfg {
23+
24+
String ACCOUNT_PROVIDER_CLASS = "account_provider_class";
25+
26+
String TOKEN_STORAGE_ADAPTER_CLASS = "token_storage_adapter_class";
27+
28+
/**
29+
* @return OAuth客户端帐号信息提供者接口实现类, 默认值: net.ymate.module.oauth.client.impl.DefaultOAuthClientAccountProvider
30+
*/
31+
IOAuthClientAccountProvider getAccountProvider();
32+
33+
/**
34+
* @return OAuth客户端令牌信息存储适配器接口实现类, 默认值: net.ymate.module.oauth.client.impl.DefaultOAuthClientTokenStorageAdapter
35+
*/
36+
IOAuthClientTokenStorageAdapter getTokenStorageAdapter();
37+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2007-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package net.ymate.module.oauth.client;
17+
18+
import net.ymate.module.oauth.client.base.OAuthAccessToken;
19+
import net.ymate.module.oauth.client.base.OAuthAccount;
20+
21+
/**
22+
* OAuth客户端令牌信息存储适配器接口
23+
*
24+
* @author 刘镇 (suninformation@163.com) on 2018/10/6 下午3:48
25+
* @version 1.0
26+
*/
27+
public interface IOAuthClientTokenStorageAdapter {
28+
29+
/**
30+
* 初始化
31+
*
32+
* @param owner 所属模块对象
33+
* @throws Exception 可能产生的任何异常
34+
*/
35+
void init(IOAuthClients owner) throws Exception;
36+
37+
/**
38+
* 销毁
39+
*
40+
* @throws Exception 可能产生的任何异常
41+
*/
42+
void destroy() throws Exception;
43+
44+
/**
45+
* 加载指定客户端帐号主键名称的访问令牌信息
46+
*
47+
* @param account 客户端帐号信息对象
48+
* @return 返回客户端访问令牌对象, 若不存在则返回null
49+
*/
50+
OAuthAccessToken loadAccessToken(OAuthAccount account);
51+
52+
/**
53+
* 储存或更新客户端访问令牌信息
54+
*
55+
* @param account 客户端帐号信息对象
56+
* @param accessToken 客户端访问令牌信息对象
57+
*/
58+
void saveOrUpdateAccessToken(OAuthAccount account, OAuthAccessToken.Result accessToken);
59+
}

0 commit comments

Comments
 (0)