diff --git a/README.md b/README.md index 416da02b0fab274fb8cff39dfc333dbc086a34fc..d86ed906b05b87c4fb6a30b51488287a56cb5929 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ 项目用Maven管理, 字符编码: UTF-8 +授权协议:GPL-2.0 使用的技术与版本号
- 如果在使用过程中遇到特殊的问题(如:如何将oauth_code存入数据库),请访问项目的 Wiki
- 与 附件.
+ 如果在使用过程中遇到特殊的问题(如:如何将oauth_code存入数据库),请访问项目的 Wiki
+ 与 附件.
我会把大家反馈的问题解决办法添加在这里.
@@ -105,7 +110,7 @@
- 如果在使用项目的过程中发现任何的BUG或者更好的提议, 建议将其提交到项目的 Issues 中, + 如果在使用项目的过程中发现任何的BUG或者更好的提议, 建议将其提交到项目的 Issues 中, 我会一直关注并不断改进项目.
oauth_code存入数据库的配置
, 请下载文件 oauth_code存入数据库的配置.jpg
+ oauth_code存入数据库的配置
, 请下载文件 oauth_code存入数据库的配置.jpg
改变token过期的时间的配置
, 请下载文件改变token过期的时间的配置.jpg
+ 改变token过期的时间的配置
, 请下载文件改变token过期的时间的配置.jpg
自定义 grant_type
, 默认情况支持的grant_type包括 [password,authorization_code,refresh_token,implicit], 若不需要其中的某些grant_type,
@@ -152,14 +157,40 @@
从 0.3版本开始将项目的所有计划的开发内容列出来, 方便大家跟进, 也欢迎你加入.
-项目的开发管理使用开源项目 andaily-developer.
+项目的开发管理使用开源项目 andaily-developer.
- Version: 1.0 [pending]
+ Version: 2.0.1 [pending]
+
+ Date: 2018-05-01 / ---
+
增加 /oauth/check_token 可使用 #IJO9H
Fix issue #IJO9R /oauth/rest_token 接口 client_secret字段没有校验
升级spring-boot 版本为 2.0.2.RELEASE
2013-11-19 Initial project, start push code 2013-11-20 发布0.1版本 2013-11-20 发布0.1版本 2015-05-06 发布0.2版本 2015-05-27 创建项目博客,访问地址 http://andaily.com/blog/?cat=19 2015-06-07 发布0.3版本 2015-06-07 发布0.3版本
2015-06-16 添加github访问: https://github.com/monkeyk/spring-oauth-server,
以后的更新将同步github与gitosc.
2015-11-09 开始开发 0.4-beta 版本 2015-11-18 发布 0.4-beta 版本 2016-01-02 发布 0.4 版本 2015-11-18 发布 0.4-beta 版本 2016-01-02 发布 0.4 版本 2016-02-19 Add 0.5 version development planning 2016-04-03 Add config branch 2016-04-14 Add mongodb branch 2016-06-02 发布 0.5 版本 2016-04-03 Add config branch 2016-04-14 Add mongodb branch 2016-06-02 发布 0.5 版本 2016-07-06 Add 0.6 version planning 2016-10-13 发布0.6版本 2018-04-21 发布2.0.0版本, spring-boot版本将项目用视频方式展现出来,更直观. spring-oauth-client
project use
+ #75 - Add user information API, for spring-oauth-client
project use
URL: /unity/user_info
Login: Yes (ROLE_UNITY)
@@ -266,23 +297,24 @@
http://andaily.com/blog/?dwqa-question_category=oauth
+ GitHub项目地址: https://github.com/monkeyk/spring-oauth-server.git +
南京索特科技 -- 200元 (2016-12-16)
周广文 -- 6.66元 (2017-02-17)
境随心转 -- 20元 (2017-06-09)
Xyz(秦) -- 50元 (2018-06-05)
+ *
+ * Cache 操作相关
+ *
+ * @author Shengzhao Li
+ * @since 1.0
+ */
+public class SOSCacheUtils implements CacheConstants {
+
+
+ private SOSCacheUtils() {
+ }
+
+
+ /**
+ * 用户 Cache
+ *
+ * @return Cache instance
+ */
+ public static Cache userCache() {
+ final CacheManager cacheManager = getCacheManager();
+ return cacheManager.getCache(USER_CACHE);
+ }
+
+ private static CacheManager getCacheManager() {
+ final CacheManager cacheManager = BeanProvider.getBean(CacheManager.class);
+ Assert.notNull(cacheManager, "cacheManager is null");
+ return cacheManager;
+ }
+
+
+}
diff --git a/src/main/java/com/monkeyk/sos/service/business/CurrentUserJsonDtoLoader.java b/src/main/java/com/monkeyk/sos/service/business/CurrentUserJsonDtoLoader.java
new file mode 100644
index 0000000000000000000000000000000000000000..d7c67063efd170ee1b21018fe7d119578745e501
--- /dev/null
+++ b/src/main/java/com/monkeyk/sos/service/business/CurrentUserJsonDtoLoader.java
@@ -0,0 +1,40 @@
+package com.monkeyk.sos.service.business;
+
+import com.monkeyk.sos.domain.dto.UserJsonDto;
+import com.monkeyk.sos.domain.shared.security.WdcyUserDetails;
+import com.monkeyk.sos.domain.user.UserRepository;
+import com.monkeyk.sos.web.context.BeanProvider;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.oauth2.provider.OAuth2Authentication;
+
+/**
+ * 2018/10/14
+ *
+ * @author Shengzhao Li
+ * @since 1.0
+ */
+public class CurrentUserJsonDtoLoader {
+
+
+ private transient UserRepository userRepository = BeanProvider.getBean(UserRepository.class);
+
+ public CurrentUserJsonDtoLoader() {
+ }
+
+ public UserJsonDto load() {
+
+ final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ final Object principal = authentication.getPrincipal();
+
+ if (authentication instanceof OAuth2Authentication &&
+ (principal instanceof String || principal instanceof org.springframework.security.core.userdetails.User)) {
+ OauthUserJsonDtoLoader jsonDtoLoader = new OauthUserJsonDtoLoader((OAuth2Authentication) authentication);
+ return jsonDtoLoader.load();
+ } else {
+ final WdcyUserDetails userDetails = (WdcyUserDetails) principal;
+ return new UserJsonDto(userRepository.findByGuid(userDetails.user().guid()));
+ }
+ }
+
+}
diff --git a/src/main/java/com/monkeyk/sos/service/business/OauthUserJsonDtoLoader.java b/src/main/java/com/monkeyk/sos/service/business/OauthUserJsonDtoLoader.java
new file mode 100644
index 0000000000000000000000000000000000000000..8acf1194aca0edd40c4196986ef54d31582538f9
--- /dev/null
+++ b/src/main/java/com/monkeyk/sos/service/business/OauthUserJsonDtoLoader.java
@@ -0,0 +1,35 @@
+package com.monkeyk.sos.service.business;
+
+import com.monkeyk.sos.domain.dto.UserJsonDto;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.oauth2.provider.OAuth2Authentication;
+
+import java.util.Collection;
+
+/**
+ * 2018/10/14
+ *
+ * @author Shengzhao Li
+ * @since 1.0
+ */
+public class OauthUserJsonDtoLoader {
+
+ private OAuth2Authentication oAuth2Authentication;
+
+ public OauthUserJsonDtoLoader(OAuth2Authentication oAuth2Authentication) {
+ this.oAuth2Authentication = oAuth2Authentication;
+ }
+
+ public UserJsonDto load() {
+
+ UserJsonDto userJsonDto = new UserJsonDto();
+ userJsonDto.setUsername(oAuth2Authentication.getName());
+
+ final Collection
+ * Spring bean容器, 启动时初始化
+ *
+ * @author Shengzhao Li
+ * @see SOSContextLoaderListener
+ * @since 1.0
+ */
+public abstract class BeanProvider {
+
+ private static ApplicationContext springApplicationContext;
+
+
+ //private
+ private BeanProvider() {
+ }
+
+ static void initialize(ApplicationContext applicationContext) {
+ BeanProvider.springApplicationContext = applicationContext;
+ }
+
+ public static
+ *
+ * 扩展 Spring Context, 方便获取 bean
+ *
+ * @author Shengzhao Li
+ * @since 1.0
+ */
+public class SOSContextLoaderListener extends ContextLoaderListener {
+
+
+ @Override
+ public void contextInitialized(ServletContextEvent event) {
+ super.contextInitialized(event);
+ //ext
+ WebApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext());
+ BeanProvider.initialize(applicationContext);
+ }
+}
diff --git a/src/main/java/com/monkeyk/sos/web/controller/OAuthRestController.java b/src/main/java/com/monkeyk/sos/web/controller/OAuthRestController.java
index 7c52f4af634e877de15bbe62eba05ab38d989a31..e893c9b1e2c479be48f4cd754ea093e4f155ba0d 100644
--- a/src/main/java/com/monkeyk/sos/web/controller/OAuthRestController.java
+++ b/src/main/java/com/monkeyk/sos/web/controller/OAuthRestController.java
@@ -137,6 +137,16 @@ public class OAuthRestController implements InitializingBean, ApplicationContext
String clientId = getClientId(parameters);
ClientDetails authenticatedClient = clientDetailsService.loadClientByClientId(clientId);
+ //validate client_secret
+ String clientSecret = getClientSecret(parameters);
+ if (clientSecret == null || clientSecret.equals("")) {
+ throw new InvalidClientException("Bad client credentials");
+ } else {
+ if (!clientSecret.equals(authenticatedClient.getClientSecret())) {
+ throw new InvalidClientException("Bad client credentials");
+ }
+ }
+
TokenRequest tokenRequest = oAuth2RequestFactory.createTokenRequest(parameters, authenticatedClient);
if (clientId != null && !"".equals(clientId)) {
@@ -149,9 +159,7 @@ public class OAuthRestController implements InitializingBean, ApplicationContext
}
}
- if (authenticatedClient != null) {
- oAuth2RequestValidator.validateScope(tokenRequest, authenticatedClient);
- }
+ oAuth2RequestValidator.validateScope(tokenRequest, authenticatedClient);
final String grantType = tokenRequest.getGrantType();
if (!StringUtils.hasText(grantType)) {
@@ -227,7 +235,7 @@ public class OAuthRestController implements InitializingBean, ApplicationContext
*
* @param e Exception
* @return ResponseEntity
- * @throws Exception
+ * @throws Exception Exception
* @see org.springframework.security.oauth2.provider.endpoint.CheckTokenEndpoint#handleException(Exception)
*/
@ExceptionHandler(InvalidTokenException.class)
@@ -238,18 +246,23 @@ public class OAuthRestController implements InitializingBean, ApplicationContext
private boolean isRefreshTokenRequest(Map
+ Logout
+