Parcourir la source

properties优化

properties优化
shimingxy il y a 5 ans
Parent
commit
38164a50b4
20 fichiers modifiés avec 87 ajouts et 43 suppressions
  1. 8 4
      maxkey-core/src/main/java/org/maxkey/autoconfigure/ApplicationAutoConfiguration.java
  2. 3 2
      maxkey-core/src/main/java/org/maxkey/autoconfigure/JwtAuthnAutoConfiguration.java
  3. 3 1
      maxkey-core/src/main/java/org/maxkey/autoconfigure/KaptchaAutoConfiguration.java
  4. 4 2
      maxkey-core/src/main/java/org/maxkey/autoconfigure/MvcAutoConfiguration.java
  5. 2 1
      maxkey-core/src/main/java/org/maxkey/autoconfigure/RedisAutoConfiguration.java
  6. 13 1
      maxkey-core/src/main/java/org/maxkey/config/ApplicationConfig.java
  7. 3 1
      maxkey-core/src/main/java/org/maxkey/config/CharacterEncodingConfig.java
  8. 2 1
      maxkey-core/src/main/java/org/maxkey/config/EmailConfig.java
  9. 2 1
      maxkey-core/src/main/java/org/maxkey/config/LoginConfig.java
  10. 24 0
      maxkey-core/src/main/java/org/maxkey/constants/ConstantsProperties.java
  11. 3 1
      maxkey-web-manage/src/main/java/org/maxkey/MaxKeyMgtApplication.java
  12. 3 11
      maxkey-web-manage/src/main/java/org/maxkey/MaxKeyMgtConfig.java
  13. 0 0
      maxkey-web-manage/src/main/resources/maxkey.properties
  14. 2 1
      maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyApplication.java
  15. 5 10
      maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyConfig.java
  16. 2 1
      maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyMvcConfig.java
  17. 2 1
      maxkey-web-maxkey/src/main/java/org/maxkey/autoconfigure/CasAutoConfiguration.java
  18. 3 2
      maxkey-web-maxkey/src/main/java/org/maxkey/autoconfigure/Oauth20AutoConfiguration.java
  19. 3 2
      maxkey-web-maxkey/src/main/java/org/maxkey/autoconfigure/Saml20AutoConfiguration.java
  20. 0 0
      maxkey-web-maxkey/src/main/resources/maxkey.properties

+ 8 - 4
maxkey-core/src/main/java/org/maxkey/autoconfigure/ApplicationAutoConfiguration.java

@@ -9,6 +9,7 @@ import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
 import org.maxkey.authn.support.rememberme.InMemoryRemeberMeService;
 import org.maxkey.authn.support.rememberme.JdbcRemeberMeService;
 import org.maxkey.authn.support.rememberme.RedisRemeberMeService;
+import org.maxkey.constants.ConstantsProperties;
 import org.maxkey.crypto.keystore.KeyStoreLoader;
 import org.maxkey.crypto.password.PasswordReciprocal;
 import org.maxkey.persistence.redis.RedisConnectionFactory;
@@ -31,8 +32,8 @@ import org.springframework.security.crypto.password.PasswordEncoder;
 
 
 @Configuration
-@PropertySource("classpath:/application.properties")
-@PropertySource("classpath:/config/applicationConfig.properties")
+@PropertySource(ConstantsProperties.applicationPropertySource)
+@PropertySource(ConstantsProperties.maxKeyPropertySource)
 public class ApplicationAutoConfiguration  implements InitializingBean {
     private static final  Logger _logger = 
             LoggerFactory.getLogger(ApplicationAutoConfiguration.class);
@@ -53,8 +54,11 @@ public class ApplicationAutoConfiguration  implements InitializingBean {
     public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer()
             throws IOException {
         ClassPathResource classPathResource1 = 
-                new ClassPathResource("/config/applicationConfig.properties");
-        ClassPathResource classPathResource2 = new ClassPathResource("/application.properties");
+                new ClassPathResource(ConstantsProperties.classPathResource(
+                        ConstantsProperties.applicationPropertySource));
+        ClassPathResource classPathResource2 = 
+                new ClassPathResource(ConstantsProperties.classPathResource(
+                        ConstantsProperties.maxKeyPropertySource));
 
         PropertySourcesPlaceholderConfigurer configurer = 
                 new PropertySourcesPlaceholderConfigurer();

+ 3 - 2
maxkey-core/src/main/java/org/maxkey/autoconfigure/JwtAuthnAutoConfiguration.java

@@ -7,6 +7,7 @@ import java.security.NoSuchAlgorithmException;
 import java.security.spec.InvalidKeySpecException;
 import org.maxkey.authn.support.jwt.JwtLoginService;
 import org.maxkey.config.oidc.OIDCProviderMetadataDetails;
+import org.maxkey.constants.ConstantsProperties;
 import org.maxkey.crypto.jose.keystore.JWKSetKeyStore;
 import org.maxkey.crypto.jwt.encryption.service.impl.DefaultJwtEncryptionAndDecryptionService;
 import org.maxkey.crypto.jwt.signer.service.impl.DefaultJwtSigningAndValidationService;
@@ -21,8 +22,8 @@ import org.springframework.core.io.ClassPathResource;
 
 
 @Configuration
-@PropertySource("classpath:/application.properties")
-@PropertySource("classpath:/config/applicationConfig.properties")
+@PropertySource(ConstantsProperties.applicationPropertySource)
+@PropertySource(ConstantsProperties.maxKeyPropertySource)
 public class JwtAuthnAutoConfiguration implements InitializingBean {
     private static final  Logger _logger = LoggerFactory.getLogger(JwtAuthnAutoConfiguration.class);
     

+ 3 - 1
maxkey-core/src/main/java/org/maxkey/autoconfigure/KaptchaAutoConfiguration.java

@@ -5,6 +5,7 @@ import com.google.code.kaptcha.impl.DefaultKaptcha;
 import com.google.code.kaptcha.util.Config;
 import java.io.IOException;
 import java.util.Properties;
+import org.maxkey.constants.ConstantsProperties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.InitializingBean;
@@ -25,7 +26,8 @@ public class KaptchaAutoConfiguration  implements InitializingBean {
      */
     @Bean (name = "captchaProducer")
     public Producer captchaProducer() throws IOException {
-        Resource resource = new ClassPathResource("/kaptcha.properties");
+        Resource resource = new ClassPathResource(
+                ConstantsProperties.classPathResource(ConstantsProperties.kaptchaPropertySource));
         _logger.debug("Kaptcha config file " + resource.getURL());
         DefaultKaptcha  kaptcha = new DefaultKaptcha();
         Properties properties = new Properties();

+ 4 - 2
maxkey-core/src/main/java/org/maxkey/autoconfigure/MvcAutoConfiguration.java

@@ -2,6 +2,8 @@ package org.maxkey.autoconfigure;
 
 import java.util.ArrayList;
 import java.util.List;
+
+import org.maxkey.constants.ConstantsProperties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.InitializingBean;
@@ -28,8 +30,8 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
 
 
 @Configuration
-@PropertySource("classpath:/application.properties")
-@PropertySource("classpath:/config/applicationConfig.properties")
+@PropertySource(ConstantsProperties.applicationPropertySource)
+@PropertySource(ConstantsProperties.maxKeyPropertySource)
 public class MvcAutoConfiguration implements InitializingBean {
     private static final  Logger _logger = LoggerFactory.getLogger(MvcAutoConfiguration.class);
    

+ 2 - 1
maxkey-core/src/main/java/org/maxkey/autoconfigure/RedisAutoConfiguration.java

@@ -1,5 +1,6 @@
 package org.maxkey.autoconfigure;
 
+import org.maxkey.constants.ConstantsProperties;
 import org.maxkey.persistence.redis.RedisConnectionFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -11,7 +12,7 @@ import org.springframework.context.annotation.PropertySource;
 import redis.clients.jedis.JedisPoolConfig;
 
 @Configuration
-@PropertySource("classpath:/application.properties")
+@PropertySource(ConstantsProperties.applicationPropertySource)
 public class RedisAutoConfiguration implements InitializingBean {
     private static final  Logger _logger = LoggerFactory.getLogger(RedisAutoConfiguration.class);
     

+ 13 - 1
maxkey-core/src/main/java/org/maxkey/config/ApplicationConfig.java

@@ -1,5 +1,6 @@
 package org.maxkey.config;
 
+import org.maxkey.constants.ConstantsProperties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -18,7 +19,8 @@ import org.springframework.stereotype.Component;
  * 
  */
 @Component
-@PropertySource("classpath:/config/applicationConfig.properties")
+@PropertySource(ConstantsProperties.maxKeyPropertySource)
+@PropertySource(ConstantsProperties.applicationPropertySource)
 public class ApplicationConfig {
     private static final Logger _logger = LoggerFactory.getLogger(ApplicationConfig.class);
 
@@ -47,6 +49,16 @@ public class ApplicationConfig {
     @Value("${config.server.management.uri}")
     String managementUri;
 
+    @Value("${server.port:8080}")
+    private int port;
+
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
     /*
      * //is enable whiteList for ipAddress filter boolean whiteList;
      * 

+ 3 - 1
maxkey-core/src/main/java/org/maxkey/config/CharacterEncodingConfig.java

@@ -1,6 +1,8 @@
 package org.maxkey.config;
 
 import java.io.UnsupportedEncodingException;
+
+import org.maxkey.constants.ConstantsProperties;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.PropertySource;
@@ -12,7 +14,7 @@ import org.springframework.context.annotation.PropertySource;
  *
  */
 @Configuration
-@PropertySource("classpath:/application.properties")
+@PropertySource(ConstantsProperties.applicationPropertySource)
 public class CharacterEncodingConfig {
 
     /**

+ 2 - 1
maxkey-core/src/main/java/org/maxkey/config/EmailConfig.java

@@ -1,11 +1,12 @@
 package org.maxkey.config;
 
+import org.maxkey.constants.ConstantsProperties;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.PropertySource;
 
 @Configuration
-@PropertySource("classpath:/application.properties")
+@PropertySource(ConstantsProperties.applicationPropertySource)
 public class EmailConfig {
 
     @Value("${spring.mail.username}")

+ 2 - 1
maxkey-core/src/main/java/org/maxkey/config/LoginConfig.java

@@ -1,11 +1,12 @@
 package org.maxkey.config;
 
+import org.maxkey.constants.ConstantsProperties;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.PropertySource;
 
 @Configuration
-@PropertySource("classpath:/config/applicationConfig.properties")
+@PropertySource(ConstantsProperties.maxKeyPropertySource)
 public class LoginConfig {
     @Value("${config.login.captcha}")
     boolean captcha;

+ 24 - 0
maxkey-core/src/main/java/org/maxkey/constants/ConstantsProperties.java

@@ -0,0 +1,24 @@
+package org.maxkey.constants;
+
+import org.junit.Test;
+
+public class ConstantsProperties {
+
+    public static final String applicationPropertySource = 
+            "classpath:/application.properties";
+    
+    public static final String maxKeyPropertySource      = 
+            "classpath:/maxkey.properties";
+    
+    public static final String kaptchaPropertySource      = 
+            "classpath:/kaptcha.properties";
+    
+    public static String classPathResource(String propertySource) {
+        return propertySource.replaceAll("classpath:","");
+    }
+    
+    @Test
+    public void classPathResourceTest() {
+        System.out.println(classPathResource(maxKeyPropertySource));
+    }
+}

+ 3 - 1
maxkey-web-manage/src/main/java/org/maxkey/MaxKeyMgtApplication.java

@@ -2,6 +2,8 @@ package org.maxkey;
 
 import java.util.Date;
 import javax.servlet.ServletException;
+
+import org.maxkey.config.ApplicationConfig;
 import org.maxkey.web.InitializeContext;
 import org.mybatis.spring.annotation.MapperScan;
 import org.slf4j.Logger;
@@ -50,7 +52,7 @@ public class MaxKeyMgtApplication extends SpringBootServletInitializer {
 			_logger.error("",e);
 		}
 		_logger.info("MaxKeyMgt at "+new Date(applicationContext.getStartupDate()));
-		_logger.info("MaxKeyMgt Server Port "+applicationContext.getBean(MaxKeyMgtConfig.class).getPort());
+		_logger.info("MaxKeyMgt Server Port "+applicationContext.getBean(ApplicationConfig.class).getPort());
 		_logger.info("MaxKeyMgt started.");
 		
 	}

+ 3 - 11
maxkey-web-manage/src/main/java/org/maxkey/MaxKeyMgtConfig.java

@@ -2,6 +2,7 @@ package org.maxkey;
 
 import javax.sql.DataSource;
 import org.maxkey.authz.oauth2.provider.client.JdbcClientDetailsService;
+import org.maxkey.constants.ConstantsProperties;
 import org.maxkey.crypto.password.opt.impl.TimeBasedOtpAuthn;
 import org.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
 import org.slf4j.Logger;
@@ -15,20 +16,11 @@ import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.security.crypto.password.PasswordEncoder;
 
 @Configuration
-@PropertySource("classpath:/application.properties")
+@PropertySource(ConstantsProperties.applicationPropertySource)
 public class MaxKeyMgtConfig  implements InitializingBean {
     private static final  Logger _logger = LoggerFactory.getLogger(MaxKeyMgtConfig.class);
     
-	@Value("${server.port:8080}")
-    private int port;
-
-	public int getPort() {
-		return port;
-	}
-
-	public void setPort(int port) {
-		this.port = port;
-	}
+	
 	
 	@Bean(name = "oauth20JdbcClientDetailsService")
     public JdbcClientDetailsService JdbcClientDetailsService(

+ 0 - 0
maxkey-web-manage/src/main/resources/config/applicationConfig.properties → maxkey-web-manage/src/main/resources/maxkey.properties


+ 2 - 1
maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyApplication.java

@@ -4,6 +4,7 @@ import java.util.Date;
 import javax.servlet.ServletException;
 import org.apache.ibatis.io.VFS;
 import org.apache.mybatis.jpa.SpringBootVFS;
+import org.maxkey.config.ApplicationConfig;
 import org.maxkey.web.InitializeContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -35,7 +36,7 @@ public class MaxKeyApplication extends SpringBootServletInitializer {
         }
         _logger.info("MaxKey at " + new Date(applicationContext.getStartupDate()));
         _logger.info("MaxKey Server Port "
-                +   applicationContext.getBean(MaxKeyConfig.class).getPort());
+                +   applicationContext.getBean(ApplicationConfig.class).getPort());
         _logger.info("MaxKey started.");
     }
 

+ 5 - 10
maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyConfig.java

@@ -21,6 +21,7 @@ import org.maxkey.authn.support.socialsignon.service.JdbcSocialsAssociateService
 import org.maxkey.authn.support.socialsignon.service.SocialSignOnProvider;
 import org.maxkey.authn.support.socialsignon.service.SocialSignOnProviderService;
 import org.maxkey.authz.oauth2.provider.endpoint.TokenEndpointAuthenticationFilter;
+import org.maxkey.constants.ConstantsProperties;
 import org.maxkey.crypto.password.opt.algorithm.KeyUriFormat;
 import org.maxkey.crypto.password.opt.impl.MailOtpAuthn;
 import org.maxkey.crypto.password.opt.impl.SmsOtpAuthn;
@@ -50,8 +51,8 @@ import org.springframework.jdbc.core.JdbcTemplate;
 
 @Configuration
 //@ImportResource(locations = { "classpath:spring/maxkey.xml" })
-@PropertySource("classpath:/application.properties")
-@PropertySource("classpath:/config/applicationConfig.properties")
+@PropertySource(ConstantsProperties.applicationPropertySource)
+@PropertySource(ConstantsProperties.maxKeyPropertySource)
 @MapperScan("org.maxkey.dao.persistence,")
 @ComponentScan(basePackages = {
         "org.maxkey.config",
@@ -74,13 +75,6 @@ import org.springframework.jdbc.core.JdbcTemplate;
 public class MaxKeyConfig  implements InitializingBean {
     private static final  Logger _logger = LoggerFactory.getLogger(MaxKeyConfig.class);
     
-    @Value("${server.port:8080}")
-    private int port;
-
-    public int getPort() {
-        return port;
-    }
-
     @Bean
     public FilterRegistrationBean<TokenEndpointAuthenticationFilter> TokenEndpointAuthenticationFilter() {
         _logger.debug("TokenEndpointAuthenticationFilter init ");
@@ -250,7 +244,8 @@ public class MaxKeyConfig  implements InitializingBean {
     public SocialSignOnProviderService socialSignOnProviderService() throws IOException {
         SocialSignOnProviderService socialSignOnProviderService = new SocialSignOnProviderService();
         
-        Resource resource = new ClassPathResource("/config/applicationConfig.properties");
+        Resource resource = new ClassPathResource(
+                ConstantsProperties.classPathResource(ConstantsProperties.classPathResource(ConstantsProperties.maxKeyPropertySource)));
         Properties properties = new Properties();
         properties.load(resource.getInputStream());
         String [] providerList =properties.get("config.login.socialsignon.providers").toString().split(",");

+ 2 - 1
maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyMvcConfig.java

@@ -2,6 +2,7 @@ package org.maxkey;
 
 import org.maxkey.authn.support.basic.BasicEntryPoint;
 import org.maxkey.authn.support.httpheader.HttpHeaderEntryPoint;
+import org.maxkey.constants.ConstantsProperties;
 import org.maxkey.web.interceptor.HistoryLoginAppAdapter;
 import org.maxkey.web.interceptor.HistoryLogsAdapter;
 import org.maxkey.web.interceptor.PermissionAdapter;
@@ -20,7 +21,7 @@ import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
 
 @Configuration
 @EnableWebMvc
-@PropertySource("classpath:/config/applicationConfig.properties")
+@PropertySource(ConstantsProperties.maxKeyPropertySource)
 public class MaxKeyMvcConfig implements WebMvcConfigurer {
     private static final  Logger _logger = LoggerFactory.getLogger(MaxKeyMvcConfig.class);
     @Autowired

+ 2 - 1
maxkey-web-maxkey/src/main/java/org/maxkey/autoconfigure/CasAutoConfiguration.java

@@ -4,6 +4,7 @@ import org.maxkey.authz.cas.endpoint.ticket.service.InMemoryTicketServices;
 import org.maxkey.authz.cas.endpoint.ticket.service.JdbcTicketServices;
 import org.maxkey.authz.cas.endpoint.ticket.service.RedisTicketServices;
 import org.maxkey.authz.cas.endpoint.ticket.service.TicketServices;
+import org.maxkey.constants.ConstantsProperties;
 import org.maxkey.persistence.redis.RedisConnectionFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -19,7 +20,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
 @ComponentScan(basePackages = {
         "org.maxkey.authz.cas.endpoint"
 })
-@PropertySource("classpath:/application.properties")
+@PropertySource(ConstantsProperties.maxKeyPropertySource)
 public class CasAutoConfiguration implements InitializingBean {
     private static final  Logger _logger = LoggerFactory.getLogger(CasAutoConfiguration.class);
     

+ 3 - 2
maxkey-web-maxkey/src/main/java/org/maxkey/autoconfigure/Oauth20AutoConfiguration.java

@@ -25,6 +25,7 @@ import org.maxkey.authz.oauth2.provider.token.store.JwtAccessTokenConverter;
 import org.maxkey.authz.oauth2.provider.token.store.RedisTokenStore;
 import org.maxkey.authz.oidc.idtoken.OIDCIdTokenEnhancer;
 import org.maxkey.config.oidc.OIDCProviderMetadataDetails;
+import org.maxkey.constants.ConstantsProperties;
 import org.maxkey.crypto.jose.keystore.JWKSetKeyStore;
 import org.maxkey.crypto.jwt.encryption.service.impl.DefaultJwtEncryptionAndDecryptionService;
 import org.maxkey.crypto.jwt.signer.service.impl.DefaultJwtSigningAndValidationService;
@@ -53,8 +54,8 @@ import com.nimbusds.jose.JWEAlgorithm;
         "org.maxkey.authz.oauth2.provider.userinfo.endpoint",
         "org.maxkey.authz.oauth2.provider.approval.controller"
 })
-@PropertySource("classpath:/application.properties")
-@PropertySource("classpath:/config/applicationConfig.properties")
+@PropertySource(ConstantsProperties.applicationPropertySource)
+@PropertySource(ConstantsProperties.maxKeyPropertySource)
 public class Oauth20AutoConfiguration implements InitializingBean {
     private static final  Logger _logger = LoggerFactory.getLogger(Oauth20AutoConfiguration.class);
     

+ 3 - 2
maxkey-web-maxkey/src/main/java/org/maxkey/autoconfigure/Saml20AutoConfiguration.java

@@ -17,6 +17,7 @@ import org.maxkey.authz.saml20.binding.impl.PostBindingAdapter;
 import org.maxkey.authz.saml20.binding.impl.PostSimpleSignBindingAdapter;
 import org.maxkey.authz.saml20.provider.xml.AuthnResponseGenerator;
 import org.maxkey.authz.saml20.xml.SAML2ValidatorSuite;
+import org.maxkey.constants.ConstantsProperties;
 import org.maxkey.crypto.keystore.KeyStoreLoader;
 import org.maxkey.domain.Saml20Metadata;
 import org.opensaml.common.binding.security.IssueInstantRule;
@@ -40,8 +41,8 @@ import org.springframework.ui.velocity.VelocityEngineFactoryBean;
         "org.maxkey.authz.saml20.provider.endpoint",
         "org.maxkey.authz.saml20.metadata.endpoint",
 })
-@PropertySource("classpath:/application.properties")
-@PropertySource("classpath:/config/applicationConfig.properties")
+@PropertySource(ConstantsProperties.applicationPropertySource)
+@PropertySource(ConstantsProperties.maxKeyPropertySource)
 public class Saml20AutoConfiguration implements InitializingBean {
     private static final  Logger _logger = LoggerFactory.getLogger(Saml20AutoConfiguration.class);
     

+ 0 - 0
maxkey-web-maxkey/src/main/resources/config/applicationConfig.properties → maxkey-web-maxkey/src/main/resources/maxkey.properties