MvcCurrentUserAutoConfiguration

This commit is contained in:
MaxKey 2023-12-15 17:05:07 +08:00
parent fc7c8fd2ef
commit 52bb2bed00
9 changed files with 43 additions and 50 deletions

View File

@ -0,0 +1,30 @@
package org.dromara.maxkey.autoconfigure;
import java.util.List;
import org.dromara.maxkey.authn.web.CurrentUserMethodArgumentResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@EnableWebMvc
@AutoConfiguration
public class MvcCurrentUserAutoConfiguration implements WebMvcConfigurer {
private static final Logger logger = LoggerFactory.getLogger(MvcCurrentUserAutoConfiguration.class);
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(currentUserMethodArgumentResolver());
logger.debug("add currentUserMethodArgumentResolver");
}
@Bean
public CurrentUserMethodArgumentResolver currentUserMethodArgumentResolver() {
return new CurrentUserMethodArgumentResolver();
}
}

View File

@ -9,8 +9,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@EnableWebMvc
@AutoConfiguration
public class ResourceMvcConfig implements WebMvcConfigurer {
private static final Logger logger = LoggerFactory.getLogger(ResourceMvcConfig.class);
public class MvcResourceAutoConfiguration implements WebMvcConfigurer {
private static final Logger logger = LoggerFactory.getLogger(MvcResourceAutoConfiguration.class);
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {

View File

@ -17,8 +17,8 @@ import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
@AutoConfiguration
public class SwaggerConfig {
static final Logger _logger = LoggerFactory.getLogger(SwaggerConfig.class);
public class SwaggerAutoConfiguration {
static final Logger _logger = LoggerFactory.getLogger(SwaggerAutoConfiguration.class);
@Value("${maxkey.swagger.title}")
String title;

View File

@ -187,14 +187,4 @@ public class MaxKeyMvcConfig implements WebMvcConfigurer {
}
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(currentUserMethodArgumentResolver());
}
@Bean
public CurrentUserMethodArgumentResolver currentUserMethodArgumentResolver() {
return new CurrentUserMethodArgumentResolver();
}
}

View File

@ -10,9 +10,10 @@ org.dromara.maxkey.autoconfigure.SessionAutoConfiguration
org.dromara.maxkey.autoconfigure.TokenAutoConfiguration
org.dromara.maxkey.autoconfigure.CasAutoConfiguration
org.dromara.maxkey.autoconfigure.Oauth20AutoConfiguration
org.dromara.maxkey.autoconfigure.ResourceMvcConfig
org.dromara.maxkey.autoconfigure.MvcCurrentUserAutoConfiguration
org.dromara.maxkey.autoconfigure.MvcResourceAutoConfiguration
org.dromara.maxkey.autoconfigure.Saml20AutoConfiguration
org.dromara.maxkey.autoconfigure.SocialSignOnAutoConfiguration
org.dromara.maxkey.autoconfigure.SwaggerConfig
org.dromara.maxkey.autoconfigure.SwaggerAutoConfiguration
org.dromara.maxkey.autoconfigure.MaxKeyMvcConfig
org.dromara.maxkey.autoconfigure.MaxKeyConfig

View File

@ -17,21 +17,16 @@
package org.dromara.maxkey.autoconfigure;
import java.util.List;
import org.dromara.maxkey.authn.provider.AbstractAuthenticationProvider;
import org.dromara.maxkey.authn.web.CurrentUserMethodArgumentResolver;
import org.dromara.maxkey.authn.web.interceptor.PermissionInterceptor;
import org.dromara.maxkey.configuration.ApplicationConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
@EnableWebMvc
@AutoConfiguration
@ -88,15 +83,5 @@ public class MaxKeyMgtMvcConfig implements WebMvcConfigurer {
logger.debug("add Permission Adapter");
}
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(currentUserMethodArgumentResolver());
}
@Bean
public CurrentUserMethodArgumentResolver currentUserMethodArgumentResolver() {
return new CurrentUserMethodArgumentResolver();
}
}

View File

@ -8,9 +8,10 @@ org.dromara.maxkey.autoconfigure.OneTimePasswordAutoConfiguration
org.dromara.maxkey.autoconfigure.SmsAutoConfiguration
org.dromara.maxkey.autoconfigure.SessionAutoConfiguration
org.dromara.maxkey.autoconfigure.TokenAutoConfiguration
org.dromara.maxkey.autoconfigure.ResourceMvcConfig
org.dromara.maxkey.autoconfigure.MvcCurrentUserAutoConfiguration
org.dromara.maxkey.autoconfigure.MvcResourceAutoConfiguration
org.dromara.maxkey.autoconfigure.SynchronizerAutoConfiguration
org.dromara.maxkey.autoconfigure.SwaggerConfig
org.dromara.maxkey.autoconfigure.SwaggerAutoConfiguration
org.dromara.maxkey.autoconfigure.Oauth20ClientAutoConfiguration
org.dromara.maxkey.autoconfigure.MaxKeyMgtConfig
org.dromara.maxkey.autoconfigure.MaxKeyMgtMvcConfig

View File

@ -17,10 +17,7 @@
package org.dromara.maxkey.autoconfigure;
import java.util.List;
import org.dromara.maxkey.authn.provider.AbstractAuthenticationProvider;
import org.dromara.maxkey.authn.web.CurrentUserMethodArgumentResolver;
import org.dromara.maxkey.authn.web.interceptor.PermissionInterceptor;
import org.dromara.maxkey.configuration.ApplicationConfig;
import org.dromara.maxkey.web.interceptor.RestApiPermissionAdapter;
@ -28,11 +25,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
@EnableWebMvc
@AutoConfiguration
@ -105,15 +100,5 @@ public class MaxKeyOpenApiMvcConfig implements WebMvcConfigurer {
logger.debug("add Rest Api Permission Adapter");
}
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(currentUserMethodArgumentResolver());
}
@Bean
public CurrentUserMethodArgumentResolver currentUserMethodArgumentResolver() {
return new CurrentUserMethodArgumentResolver();
}
}

View File

@ -5,11 +5,12 @@ org.dromara.maxkey.autoconfigure.JwtAuthnAutoConfiguration
org.dromara.maxkey.autoconfigure.RedisAutoConfiguration
org.dromara.maxkey.autoconfigure.AuthnProviderAutoConfiguration
org.dromara.maxkey.autoconfigure.OneTimePasswordAutoConfiguration
org.dromara.maxkey.autoconfigure.ResourceMvcConfig
org.dromara.maxkey.autoconfigure.MvcCurrentUserAutoConfiguration
org.dromara.maxkey.autoconfigure.MvcResourceAutoConfiguration
org.dromara.maxkey.autoconfigure.SmsAutoConfiguration
org.dromara.maxkey.autoconfigure.SessionAutoConfiguration
org.dromara.maxkey.autoconfigure.TokenAutoConfiguration
org.dromara.maxkey.autoconfigure.SwaggerConfig
org.dromara.maxkey.autoconfigure.SwaggerAutoConfiguration
org.dromara.maxkey.autoconfigure.Oauth20ClientAutoConfiguration
org.dromara.maxkey.autoconfigure.MaxKeyOpenApiConfig
org.dromara.maxkey.autoconfigure.MaxKeyOpenApiMvcConfig