Sfoglia il codice sorgente

v 1.5.0 RC2

v 1.5.0 RC2
shimingxy 5 anni fa
parent
commit
f4318a784d

+ 42 - 13
maxkey-core/src/main/java/org/maxkey/config/MvcAutoConfiguration.java

@@ -1,14 +1,18 @@
 package org.maxkey.config;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
 import org.springframework.context.support.ReloadableResourceBundleMessageSource;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.http.MediaType;
 import org.springframework.http.converter.HttpMessageConverter;
 import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
@@ -25,22 +29,39 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
 @Configuration
 @PropertySource("classpath:/application.properties")
 @PropertySource("classpath:/config/applicationConfig.properties")
-public class MvcAutoConfiguration {
+public class MvcAutoConfiguration implements InitializingBean {
     private static final  Logger _logger = LoggerFactory.getLogger(MvcAutoConfiguration.class);
-    
-    @Value("${config.server.domain.sub}")
-    String subDomainName;
-    @Value("${spring.servlet.multipart.max-file-size:4194304}")
-    int maxUploadSize;
-    @Value("${spring.messages.basename:classpath:messages/message}")
-    String messagesBasename;
+   
+    /**
+     * propertySourcesPlaceholderConfigurer .
+     * @return propertySourcesPlaceholderConfigurer
+     * @throws IOException  null
+     */
+    @Bean (name = "propertySourcesPlaceholderConfigurer")
+    public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer()
+            throws IOException {
+        ClassPathResource classPathResource1 = 
+                new ClassPathResource("/config/applicationConfig.properties");
+        ClassPathResource classPathResource2 = new ClassPathResource("/application.properties");
+
+        PropertySourcesPlaceholderConfigurer configurer = 
+                new PropertySourcesPlaceholderConfigurer();
+        configurer.setLocations(
+                classPathResource1,
+                classPathResource2
+        );
+        configurer.setIgnoreUnresolvablePlaceholders(true);
  
+        return configurer;
+    }
+    
     /**
      * cookieLocaleResolver .
      * @return cookieLocaleResolver
      */
     @Bean (name = "localeResolver")
-    public CookieLocaleResolver cookieLocaleResolver() {
+    public CookieLocaleResolver cookieLocaleResolver(
+            @Value("${config.server.domain.sub:maxkey.top}")String subDomainName) {
         _logger.debug("subDomainName " + subDomainName);
         CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
         cookieLocaleResolver.setCookieName("maxkey_lang");
@@ -55,8 +76,11 @@ public class MvcAutoConfiguration {
      * @return messageSource
      */
     @Bean (name = "messageSource")
-    public ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource()  {
+    public ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource(
+            @Value("${spring.messages.basename:classpath:messages/message}")
+            String messagesBasename)  {
         _logger.debug("Basename " + messagesBasename);
+        
         ReloadableResourceBundleMessageSource messageSource = 
                 new ReloadableResourceBundleMessageSource();
         messageSource.setBasename(messagesBasename);
@@ -82,7 +106,8 @@ public class MvcAutoConfiguration {
      * @return multipartResolver
      */
     @Bean (name = "multipartResolver")
-    public CommonsMultipartResolver commonsMultipartResolver()  {
+    public CommonsMultipartResolver commonsMultipartResolver(
+            @Value("${spring.servlet.multipart.max-file-size:0}") int maxUploadSize)  {
         _logger.debug("maxUploadSize " + maxUploadSize);
         CommonsMultipartResolver multipartResolver = 
                 new CommonsMultipartResolver();
@@ -180,8 +205,12 @@ public class MvcAutoConfiguration {
         restTemplate.setMessageConverters(httpMessageConverterList);
         return restTemplate;
     }
-    
-    
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        // TODO Auto-generated method stub
+        
+    }
     
     
 }

+ 7 - 0
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/algorithm/KeyUriFormat.java

@@ -202,4 +202,11 @@ public class KeyUriFormat {
         return uri.toString();
     }
 
+    @Override
+    public String toString() {
+        return "KeyUriFormat [crypto=" + crypto + ", type=" + type + ", secret=" + secret + ", issuer=" + issuer
+                + ", domain=" + domain + ", digits=" + digits + ", counter=" + counter + ", period=" + period
+                + ", account=" + account + "]";
+    }
+
 }

+ 2 - 0
maxkey-web-manage/src/main/resources/application.properties

@@ -47,5 +47,7 @@ spring.freemarker.suffix=.ftl
 
 #static resources
 spring.mvc.static-path-pattern=/static/**
+spring.messages.basename=classpath:messages/message
+spring.messages.encoding=UTF-8
 
 spring.main.allow-bean-definition-overriding=true

+ 1 - 12
maxkey-web-manage/src/main/resources/spring/maxkey-mgt.xml

@@ -21,18 +21,7 @@
     <context:annotation-config />
     <!-- language select must remove -->
 	<mvc:annotation-driven />
-    	
-    <!-- Application properties configs  -->
-	<bean  id="propertySourcesPlaceholderConfigurer"  class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
-	  <property name="locations">
-	    <list>
-	   	  <value>classpath:config/applicationConfig.properties</value>	
-	   	   <value>classpath:application.properties</value>   	  
-	    </list>
-	  </property>
-	  <property name="ignoreUnresolvablePlaceholders" value="true"/>
-	</bean>
-	
+
 	<context:component-scan base-package="org.maxkey.config" />
 	<!-- Scans the classpath for annotated components that will be auto-registered as Spring beans.
      @Controller and @Service. Make sure to set the correct base-package-->

+ 12 - 17
maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyConfig.java

@@ -120,24 +120,19 @@ public class MaxKeyConfig {
         return new SavedRequestAwareAuthenticationSuccessHandler();
     }
     
-    
-    @Value("${config.otp.keyuri.format.type:totp}")
-    String keyuriFormatType;
-    
-    @Value("${config.otp.keyuri.format.domain:MaxKey.top}")
-    String keyuriFormatDomain;
-    
-    @Value("${config.otp.keyuri.format.issuer:MaxKey}")
-    String keyuriFormatIssuer;
-    
-    @Value("${config.otp.keyuri.format.digits:6}")
-    int keyuriFormatDigits;
-    
-    @Value("${config.otp.keyuri.format.period:30}")
-    int keyuriFormatPeriod;
-    
     @Bean(name = "keyUriFormat")
-    public KeyUriFormat keyUriFormat() {
+    public KeyUriFormat keyUriFormat(
+            @Value("${config.otp.keyuri.format.type:totp}")
+            String keyuriFormatType,
+            @Value("${config.otp.keyuri.format.domain:MaxKey.top}")
+            String keyuriFormatDomain,
+            @Value("${config.otp.keyuri.format.issuer:MaxKey}")
+            String keyuriFormatIssuer,
+            @Value("${config.otp.keyuri.format.digits:6}")
+            int keyuriFormatDigits,
+            @Value("${config.otp.keyuri.format.period:30}")
+            int keyuriFormatPeriod) {
+        
         KeyUriFormat keyUriFormat=new KeyUriFormat();
         keyUriFormat.setType(keyuriFormatType);
         keyUriFormat.setDomain(keyuriFormatDomain);

+ 0 - 11
maxkey-web-maxkey/src/main/resources/spring/maxkey.xml

@@ -17,17 +17,6 @@
 	        http://www.springframework.org/schema/util/spring-util.xsd
 	        http://www.springframework.org/schema/mvc 
 	        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
-    
-    <!-- Application properties configs  -->
-	<bean id="propertySourcesPlaceholderConfigurer" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
-	  <property name="locations">
-	    <list>
-	   	  <value>classpath:config/applicationConfig.properties</value>
-	   	  <value>classpath:application.properties</value>
-	    </list>
-	  </property>
-	  <property name="ignoreUnresolvablePlaceholders" value="true"/>
-	</bean>
 	
 	<!-- Scans the classpath for annotated components that will be auto-registered as Spring beans.
  	 @Controller and @Service. Make sure to set the correct base-package-->