zhou-hao 7 vuotta sitten
vanhempi
commit
81d4228128
13 muutettua tiedostoa jossa 134 lisäystä ja 25 poistoa
  1. 0 5
      hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/handler/MethodProceedCallback.java
  2. 5 5
      hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/java/org/hswebframework/web/authorization/oauth2/server/support/code/DefaultAuthorizationCodeGranter.java
  3. 4 2
      hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/java/org/hswebframework/web/authorization/oauth2/server/support/refresh/DefaultRefreshTokenGranter.java
  4. 2 1
      hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/SimpleOAuth2RequestService.java
  5. 2 0
      hsweb-boost/hsweb-boost-aop/src/main/java/org/hswebframework/web/boost/aop/context/MethodInterceptorContext.java
  6. 11 2
      hsweb-boost/hsweb-boost-aop/src/main/java/org/hswebframework/web/boost/aop/context/MethodInterceptorHolder.java
  7. 11 0
      hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/QueryController.java
  8. 26 0
      hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/pom.xml
  9. 36 0
      hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2QueryService.java
  10. 25 0
      hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2ServiceSupport.java
  11. 1 0
      hsweb-commons/hsweb-commons-service/pom.xml
  12. 7 2
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthorizationSettingService.java
  13. 4 8
      hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-service/hsweb-system-oauth2-client-service-simple/src/main/java/org/hswebframework/web/service/oauth2/client/simple/SimpleOAuth2UserTokenService.java

+ 0 - 5
hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/handler/MethodProceedCallback.java

@@ -1,5 +0,0 @@
-package org.hswebframework.web.authorization.basic.handler;
-
-public interface MethodProceedCallback {
-    void  call(Object result);
-}

+ 5 - 5
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/java/org/hswebframework/web/authorization/oauth2/server/support/code/DefaultAuthorizationCodeGranter.java

@@ -28,14 +28,14 @@ import org.hswebframework.web.oauth2.core.GrantType;
 import static org.hswebframework.web.oauth2.core.ErrorType.*;
 
 /**
- * TODO 完成注释
- *
  * @author zhouhao
+ * @see AuthorizationCodeGranter
+ * @since 3.0
  */
 public class DefaultAuthorizationCodeGranter extends AbstractAuthorizationService implements AuthorizationCodeGranter {
 
     //默认有效时间为10分钟
-    private long codeTimeOut = 10 * 60 * 1000;
+    private long codeTimeOut = 10 * 60 * 1000L;
 
     private AuthorizationCodeService authorizationCodeService;
 
@@ -71,9 +71,9 @@ public class DefaultAuthorizationCodeGranter extends AbstractAuthorizationServic
         }
         // TODO: 17-5-3  验证redirect_uri
         //验证redirect_uri
-        if (!redirectUri.equals(authorizationCode.getRedirectUri())) {
+        //if (!redirectUri.equals(authorizationCode.getRedirectUri())) {
             //   throw new GrantTokenException(ILLEGAL_REDIRECT_URI);
-        }
+       // }
 
         OAuth2AccessToken accessToken = accessTokenService.createToken();
         accessToken.setGrantType(GrantType.authorization_code);

+ 4 - 2
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/java/org/hswebframework/web/authorization/oauth2/server/support/refresh/DefaultRefreshTokenGranter.java

@@ -35,11 +35,13 @@ import static org.hswebframework.web.oauth2.core.ErrorType.*;
 
 /**
  * @author zhouhao
+ * @see RefreshTokenGranter
+ * @since 3.0
  */
 public class DefaultRefreshTokenGranter extends AbstractAuthorizationService implements RefreshTokenGranter {
 
     //默认有效时间为1年
-    private long refreshTokenTimeOut = 1 * 365 * 24 * 60 * 60 * 1000;
+    private long refreshTokenTimeOut = 365 * 24 * 60 * 60 * 1000L;
 
     public void setRefreshTokenTimeOut(long refreshTokenTimeOut) {
         this.refreshTokenTimeOut = refreshTokenTimeOut;
@@ -65,7 +67,7 @@ public class DefaultRefreshTokenGranter extends AbstractAuthorizationService imp
             throw new GrantTokenException(EXPIRED_REFRESH_TOKEN);
         }
         //更新间隔小于10秒 返回原始token
-        if(System.currentTimeMillis()-accessToken.getUpdateTime()<10000){
+        if (System.currentTimeMillis() - accessToken.getUpdateTime() < 10000) {
             return accessToken;
         }
         Set<String> newRange = request.getScope() != null ? request.getScope() : accessToken.getScope();

+ 2 - 1
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/SimpleOAuth2RequestService.java

@@ -26,6 +26,7 @@ import org.hswebframework.web.authorization.oauth2.client.OAuth2ServerConfig;
 import org.hswebframework.web.authorization.oauth2.client.OAuth2SessionBuilder;
 import org.hswebframework.web.authorization.oauth2.client.listener.OAuth2Event;
 import org.hswebframework.web.authorization.oauth2.client.listener.OAuth2Listener;
+import org.hswebframework.web.commons.entity.DataStatus;
 import org.hswebframework.web.concurrent.lock.LockManager;
 
 import java.util.*;
@@ -63,7 +64,7 @@ public class SimpleOAuth2RequestService implements OAuth2RequestService {
     @Override
     public OAuth2SessionBuilder create(String serverId) {
         OAuth2ServerConfig configEntity = oAuth2ServerConfigService.findById(serverId);
-        if (null == configEntity || !Byte.valueOf((byte) 1).equals(configEntity.getStatus())) {
+        if (null == configEntity || !DataStatus.STATUS_ENABLED.equals(configEntity.getStatus())) {
             throw new NotFoundException("server not found!");
         }
         return new SimpleOAuth2SessionBuilder(oAuth2UserTokenService, configEntity, oAuth2RequestBuilderFactory,

+ 2 - 0
hsweb-boost/hsweb-boost-aop/src/main/java/org/hswebframework/web/boost/aop/context/MethodInterceptorContext.java

@@ -73,4 +73,6 @@ public interface MethodInterceptorContext extends Serializable {
      * @see this#getParameter(String)
      */
     Map<String, Object> getParams();
+
+    Object getInvokeResult();
 }

+ 11 - 2
hsweb-boost/hsweb-boost-aop/src/main/java/org/hswebframework/web/boost/aop/context/MethodInterceptorHolder.java

@@ -118,9 +118,13 @@ public class MethodInterceptorHolder {
     public <T extends Annotation> T findAnnotation(Class<T> annClass) {
         return AopUtils.findAnnotation(target.getClass(), method, annClass);
     }
-
-    public MethodInterceptorContext createParamContext() {
+    public MethodInterceptorContext createParamContext(){
+        return createParamContext(null);
+    }
+    public MethodInterceptorContext createParamContext(Object invokeResult) {
         return new MethodInterceptorContext() {
+            private static final long serialVersionUID = -4102787561601219273L;
+
             @Override
             public Object getTarget() {
                 return target;
@@ -148,6 +152,11 @@ public class MethodInterceptorHolder {
             public Map<String, Object> getParams() {
                 return getArgs();
             }
+
+            @Override
+            public Object getInvokeResult() {
+                return invokeResult;
+            }
         };
     }
 }

+ 11 - 0
hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/QueryController.java

@@ -32,6 +32,9 @@ import org.hswebframework.web.service.QueryByEntityService;
 import org.hswebframework.web.service.QueryService;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.List;
 
 import static org.hswebframework.web.controller.message.ResponseMessage.ok;
 
@@ -90,6 +93,14 @@ public interface QueryController<E, PK, Q extends Entity> {
         return ok(assertNotNull(getService().selectByPk(id)));
     }
 
+    @Authorize(action = Permission.ACTION_GET)
+    @GetMapping(path = "/ids")
+    @AccessLogger("{get_by_id}")
+    @ApiOperation("根据主键查询多个数据")
+    default ResponseMessage<List<E>> getByPrimaryKey(@RequestParam List<PK> ids) {
+        return ok(assertNotNull(getService().selectByPk(ids)));
+    }
+
     static <T> T assertNotNull(T obj) {
         if (null == obj) {
             throw new NotFoundException("{data_not_exist}");

+ 26 - 0
hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/pom.xml

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>hsweb-commons-service</artifactId>
+        <groupId>org.hswebframework.web</groupId>
+        <version>3.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>hsweb-commons-service-oauth2</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.hswebframework.web</groupId>
+            <artifactId>hsweb-commons-service-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.hswebframework.web</groupId>
+            <artifactId>hsweb-authorization-oauth2-client</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+</project>

+ 36 - 0
hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2QueryService.java

@@ -0,0 +1,36 @@
+package org.hswebframework.web.service.oauth2;
+
+import org.hswebframework.web.service.QueryService;
+
+import java.util.List;
+
+public interface OAuth2QueryService<E, PK> extends OAuth2ServiceSupport, QueryService<E, PK> {
+
+    @Override
+    default E selectByPk(PK id) {
+        return createRequest("/" + id).get().as(getEntityType());
+    }
+
+    @Override
+    default List<E> select() {
+        return createRequest("/all").get().asList(getEntityType());
+    }
+
+    @Override
+    default List<E> selectByPk(List<PK> id) {
+        return createRequest("/ids")
+                .param("ids", id.stream()
+                        .map(String::valueOf)
+                        .reduce((id1, id2) -> String.join(",", id1, id2))
+                        .orElse(""))
+                .get()
+                .asList(getEntityType());
+    }
+
+    @Override
+    default int count() {
+        return createRequest("/count")
+                .get()
+                .as(Integer.class);
+    }
+}

+ 25 - 0
hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2ServiceSupport.java

@@ -0,0 +1,25 @@
+package org.hswebframework.web.service.oauth2;
+
+
+import org.hswebframework.web.authorization.oauth2.client.OAuth2RequestService;
+import org.hswebframework.web.authorization.oauth2.client.request.OAuth2Request;
+import org.hswebframework.web.authorization.oauth2.client.request.OAuth2Session;
+
+public interface OAuth2ServiceSupport {
+
+    OAuth2RequestService getRequestService();
+
+    String getServiceId();
+
+    String getUriPrefix();
+
+   <E> Class<E> getEntityType();
+
+    default OAuth2Session createSession() {
+        return getRequestService().create(getServiceId()).byClientCredentials();
+    }
+
+    default OAuth2Request createRequest(String uri) {
+        return createSession().request(getUriPrefix()+uri);
+    }
+}

+ 1 - 0
hsweb-commons/hsweb-commons-service/pom.xml

@@ -32,6 +32,7 @@
     <modules>
         <module>hsweb-commons-service-simple</module>
         <module>hsweb-commons-service-api</module>
+        <module>hsweb-commons-service-oauth2</module>
     </modules>
 
     <dependencies>

+ 7 - 2
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthorizationSettingService.java

@@ -209,7 +209,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
             return null;
         }
         List<AuthorizationSettingEntity> entities = getUserSetting(userId);
-        if(entities.isEmpty()){
+        if (entities.isEmpty()) {
             return Collections.emptyList();
         }
         //用户持有的权限设置id集合
@@ -281,7 +281,12 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
         }
         SimpleAuthentication authentication = new SimpleAuthentication();
         // 用户信息
-        authentication.setUser(new SimpleUser(userId, userEntity.getUsername(), userEntity.getName()));
+        authentication.setUser(SimpleUser.builder()
+                .id(userId)
+                .username(userEntity.getUsername())
+                .name(userEntity.getName())
+                .type("default")
+                .build());
         //角色
         authentication.setRoles(userService.getUserRole(userId)
                 .stream()

+ 4 - 8
hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-service/hsweb-system-oauth2-client-service-simple/src/main/java/org/hswebframework/web/service/oauth2/client/simple/SimpleOAuth2UserTokenService.java

@@ -104,10 +104,8 @@ public class SimpleOAuth2UserTokenService extends GenericEntityService<OAuth2Use
 
     @Override
     @Caching(
-            put = {
-                    @CachePut(cacheNames = "oauth2-user-token", key = "'a-t:'+#tokenInfo.accessToken"),
-            },
-            evict = @CacheEvict(cacheNames = "oauth2-user-token-list", allEntries = true)
+            put = @CachePut(cacheNames = "oauth2-user-token", key = "'a-t:'+#tokenInfo.accessToken"),
+            evict = @CacheEvict(cacheNames = "oauth2-user-token-list", key = "'s-g-t:'+#result.serverId+':'+#result.grantType")
     )
     @Transactional(propagation = Propagation.NOT_SUPPORTED)
     public AccessTokenInfo update(String id, AccessTokenInfo tokenInfo) {
@@ -119,10 +117,8 @@ public class SimpleOAuth2UserTokenService extends GenericEntityService<OAuth2Use
 
     @Override
     @Caching(
-            put = {
-                    @CachePut(cacheNames = "oauth2-user-token", key = "'a-t:'+#tokenInfo.accessToken"),
-            },
-            evict = @CacheEvict(cacheNames = "oauth2-user-token-list", allEntries = true)
+            put = @CachePut(cacheNames = "oauth2-user-token", key = "'a-t:'+#tokenInfo.accessToken"),
+            evict = @CacheEvict(cacheNames = "oauth2-user-token-list", key = "'s-g-t:'+#result.serverId+':'+#result.grantType")
     )
     @Transactional(propagation = Propagation.NOT_SUPPORTED)
     public AccessTokenInfo insert(AccessTokenInfo tokenInfo) {