Przeglądaj źródła

修改参数获取权限方式

zhouhao 8 lat temu
rodzic
commit
6135cf32ad

+ 2 - 3
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/HswebAutoConfiguration.java

@@ -81,9 +81,8 @@ public class HswebAutoConfiguration {
     }
 
     @Bean
-    @ConditionalOnBean(AuthenticationSupplier.class)
-    public AuthorizationArgumentResolver authorizationArgumentResolver(AuthenticationSupplier authenticationSupplier) {
-        return new AuthorizationArgumentResolver(authenticationSupplier);
+    public AuthorizationArgumentResolver authorizationArgumentResolver() {
+        return new AuthorizationArgumentResolver();
     }
 
     @Bean

+ 2 - 7
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/resolver/AuthorizationArgumentResolver.java

@@ -17,6 +17,7 @@
 
 package org.hswebframework.web.starter.resolver;
 
+import org.hswebframework.web.AuthorizeException;
 import org.hswebframework.web.authorization.Authentication;
 import org.hswebframework.web.authorization.AuthenticationSupplier;
 import org.springframework.core.MethodParameter;
@@ -42,12 +43,6 @@ import org.springframework.web.method.support.ModelAndViewContainer;
  */
 public class AuthorizationArgumentResolver implements HandlerMethodArgumentResolver {
 
-    AuthenticationSupplier authenticationSupplier;
-
-    public AuthorizationArgumentResolver(AuthenticationSupplier authenticationSupplier) {
-        Assert.notNull(authenticationSupplier);
-        this.authenticationSupplier = authenticationSupplier;
-    }
 
     @Override
     public boolean supportsParameter(MethodParameter parameter) {
@@ -56,6 +51,6 @@ public class AuthorizationArgumentResolver implements HandlerMethodArgumentResol
 
     @Override
     public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
-        return authenticationSupplier.get();
+        return Authentication.current().orElseThrow(AuthorizeException::new);
     }
 }