v 1.5.0 RC2

v 1.5.0 RC2
This commit is contained in:
shimingxy
2020-05-16 11:54:58 +08:00
parent 7c180f33be
commit e33c6dfd0b
37 changed files with 931 additions and 1209 deletions

View File

@@ -1,34 +1,17 @@
package org.maxkey;
import java.io.IOException;
import java.util.Date;
import java.util.Properties;
import javax.servlet.ServletException;
import org.maxkey.authn.SavedRequestAwareAuthenticationSuccessHandler;
import org.maxkey.crypto.password.PasswordReciprocal;
import org.maxkey.web.InitializeContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
@SpringBootApplication
@ImportResource(locations={"classpath:spring/maxkey-mgt.xml"})
@@ -63,57 +46,5 @@ public class MaxKeyMgtApplication extends SpringBootServletInitializer {
return application.sources(MaxKeyMgtApplication.class);
}
@Bean
MaxKeyMgtConfig MaxKeyMgtConfig() {
return new MaxKeyMgtConfig();
}
/**
* 配置默认错误页面仅用于内嵌tomcat启动时
* 使用这种方式在打包为war后不起作用
*
* @return
*/
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
@Override
public void customize(ConfigurableWebServerFactory factory) {
ErrorPage errorPage400 = new ErrorPage(HttpStatus.BAD_REQUEST,"/exception/error/400");
ErrorPage errorPage404 = new ErrorPage(HttpStatus.NOT_FOUND,"/exception/error/404");
ErrorPage errorPage500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,"/exception/error/500");
factory.addErrorPages(errorPage400, errorPage404,errorPage500);
}
};
}
@Bean(name = "passwordReciprocal")
public PasswordReciprocal passwordReciprocal() {
return new PasswordReciprocal();
}
@Bean(name = "savedRequestSuccessHandler")
public SavedRequestAwareAuthenticationSuccessHandler SavedRequestAwareAuthenticationSuccessHandler() {
return new SavedRequestAwareAuthenticationSuccessHandler();
}
/**
* Captcha Producer Config .
* @return Producer
* @throws IOException
*/
@Bean(name = "captchaProducer")
public Producer captchaProducer() throws IOException{
Resource resource = new ClassPathResource("config/kaptcha.properties");
_logger.debug("Kaptcha config file " + resource.getURL());
DefaultKaptcha kaptcha=new DefaultKaptcha();
Properties properties = new Properties();
properties.load(resource.getInputStream());
Config config = new Config(properties);
kaptcha.setConfig(config);
return kaptcha;
}
}

View File

@@ -1,15 +1,42 @@
package org.maxkey;
import javax.sql.DataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.maxkey.authn.SavedRequestAwareAuthenticationSuccessHandler;
import org.maxkey.crypto.password.PasswordReciprocal;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpStatus;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
@Configuration
@PropertySource("classpath:/application.properties")
@MapperScan("org.maxkey.dao.persistence,")
public class MaxKeyMgtConfig {
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyMgtConfig.class);
@Autowired
@Qualifier("dataSource")
DataSource dataSource;
@Autowired
@Qualifier("sqlSessionFactory")
SqlSessionFactory sqlSessionFactory;
@Value("${server.port:8080}")
private int port;
@@ -21,5 +48,58 @@ public class MaxKeyMgtConfig {
this.port = port;
}
@Bean
@Primary
@ConfigurationProperties("spring.datasource")
public DataSource dataSource() {
return DruidDataSourceBuilder.create().build();
}
@Bean(name = "passwordReciprocal")
public PasswordReciprocal passwordReciprocal() {
return new PasswordReciprocal();
}
@Bean(name = "savedRequestSuccessHandler")
public SavedRequestAwareAuthenticationSuccessHandler SavedRequestAwareAuthenticationSuccessHandler() {
return new SavedRequestAwareAuthenticationSuccessHandler();
}
@Bean(name = "jdbcTemplate")
public JdbcTemplate jdbcTemplate() {
return new JdbcTemplate(dataSource);
}
/*
@Bean(name = "sqlSession")
public SqlSessionTemplate sqlSession() throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}*/
@Bean(name = "transactionManager")
DataSourceTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource);
}
/**
* 配置默认错误页面仅用于内嵌tomcat启动时
* 使用这种方式在打包为war后不起作用
*
* @return
*/
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
@Override
public void customize(ConfigurableWebServerFactory factory) {
_logger.debug("WebServerFactoryCustomizer ... ");
ErrorPage errorPage400 = new ErrorPage(HttpStatus.BAD_REQUEST,"/exception/error/400");
ErrorPage errorPage404 = new ErrorPage(HttpStatus.NOT_FOUND,"/exception/error/404");
ErrorPage errorPage500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,"/exception/error/500");
factory.addErrorPages(errorPage400, errorPage404,errorPage500);
}
};
}
}

View File

@@ -0,0 +1,5 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.maxkey.MaxKeyMgtConfig,\
org.maxkey.config.KaptchaAutoConfiguration,\
org.maxkey.config.MvcAutoConfiguration

View File

@@ -1,14 +1,39 @@
#server config
#spring.profiles.active=dev
#application
application.title=MaxKey
application.name=MaxKey-Mgt
application.formatted-version=v1.5.0 GA
#server config
#server port
server.port=9521
#web app context path
server.servlet.context-path=/maxkey-mgt
application.name=MaxKey-Mgt
application.formatted-version=v1.5.0 GA
#for freemarker
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=4194304
#server.servlet.encoding.charset.from=
#server.servlet.encoding.charset=
#server.servlet.encoding.enabled=
#server.servlet.encoding.force=
#datasource
spring.datasource.username=root
spring.datasource.password=maxkey
spring.datasource.url=jdbc:mysql://localhost/maxkey?autoReconnect=true&characterEncoding=UTF-8
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#mybatis
mybatis.type-aliases-package=org.maxkey.domain,org.maxkey.domain.apps,
mybatis.mapper-locations=classpath*:/org/maxkey/dao/persistence/xml/mysql/*.xml
#mail
spring.mail.default-encoding=utf-8
spring.mail.host=smtp.163.com
spring.mail.port=465
spring.mail.username=maxkey@163.com
spring.mail.password=password
spring.mail.protocol=smtp
spring.mail.properties.ssl=true
spring.mail.properties.sender=maxkey@163.com
#freemarker
spring.freemarker.template-loader-path=classpath:/templates/views
spring.freemarker.cache=false
spring.freemarker.charset=UTF-8

View File

@@ -10,75 +10,21 @@ config.server.prefix.uri=${config.server.name}:9521/maxkey-mgt
config.server.default.uri=${config.server.prefix.uri}/main
config.maxkey.uri=${config.server.name}/maxkey
############################################################################
# Application Configuration
############################################################################
# DataBase configuration
# JDBC Driver
# for MySql com.mysql.jdbc.Driver
# for oracle oracle.jdbc.driver.OracleDriver
# for DB2 com.ibm.db2.jdbc.app.DB2Driver
# for SqlServer com.microsoft.jdbc.sqlserver.SQLServerDriver
# for SyBase com.sybase.jdbc.SybDriver
# for PostgreSQL org.postgresql.Driver
# for Derby org.apache.derby.jdbc.ClientDriver
config.datasource.driverclass=com.mysql.jdbc.Driver
# JDBC URL
# you need database hostname,port,databasename
# for MySql jdbc:mysql://hostname:port/secdb
# for oracle jdbc:oracle:thin:@hostname:port:secdb
# for DB2 jdbc:db2://hostname:port/secdb
# for SqlServer jdbc:microsoft:sqlserver://hostname:port;DatabaseName=secdb
# for SyBase jdbc:sybase:Tds:hostname:port/secdb
# for Derby jdbc:derby://localhost:1527/secdb
#
config.datasource.url=jdbc:mysql://localhost/maxkey?autoReconnect=true&characterEncoding=UTF-8
config.datasource.username=root
#root/maxkey
config.datasource.password=maxkey
#db2,derby,mysql,oracle,postgresql,sqlserver at Dialect
config.datasource.database=mysql
config.datasource.password.encrypt=false
# End DataBase configuration
############################################################################
# CharacterEncoding
#CharacterEncoding true/false
config.characterencoding.encoding=true
config.characterencoding.fromcharset=iso8859-1
config.characterencoding.tocharset=UTF-8
# End CharacterEncoding
############################################################################
############################################################################
# Login
config.login.captcha=false
#text or arithmetic
config.login.captcha.type=text
config.login.socialAuth=true
config.login.msad.kerberos=false
# End Login
############################################################################
# EMAIL configuration
config.email.username=test@maxkey.org
config.email.password=3&8Ujbnm5hkjhFD
config.email.smtpHost=smtp.exmail.qq.com
config.email.port=25
config.email.senderMail=test@maxkey.org
config.email.ssl=false
############################################################################
# Login configuration
#enable captcha
config.login.captcha=true
#text or arithmetic
config.login.captcha.type=text
#enable two factor,use one time password
config.login.onetimepwd=true
config.login.onetimepwd=false
#enable social sign on
config.login.socialsignon=true
config.login.socialsignon=false
#Enable kerberos/SPNEGO
config.login.kerberos=true
config.login.kerberos=false
#wsFederation
config.login.wsfederation=false
#remeberme
config.login.remeberme=true
config.login.remeberme=false
#validity
config.login.remeberme.validity=
#default.uri

View File

@@ -1,90 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- dataSource define begin -->
<!-- dataSource configuration -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close" >
<!-- <property name="driverClass" value="#{dataSoruceConfig.driverClass}"/> -->
<property name="url" value="#{dataSoruceConfig.url}"/>
<property name="username" value="#{dataSoruceConfig.username}"/>
<property name="password" value="#{dataSoruceConfig.password}"/>
</bean>
<!-- JNDI data source configuration -->
<!-- jndiName is jndi name -->
<!-- if you don,t want use prefix 'java:comp/env/' set resourceRef to true,default is false -->
<!--
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jndi_maxkey_db" />
<property name="resourceRef" value="true" />
</bean> -->
<!-- dataSource define end -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- Declare a transaction manager -->
<!-- transaction manager, use JtaTransactionManager for global tx-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- Enable annotation style of managing transactions
<tx:annotation-driven transaction-manager="transactionManager" />-->
<!-- enable component scanning (beware that this does not enable mapper scanning!) -->
<context:component-scan base-package="org.maxkey.dao.service" />
<!-- enable autowire -->
<context:annotation-config />
<!-- enable transaction demarcation with annotations
<tx:annotation-driven />-->
<!--<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">-->
<bean id="sqlSessionFactory" class="org.apache.mybatis.jpa.MyBatisSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="dialect" value="mysql" />
<property name="timeout" value="30" />
<property name="transactionFactory">
<bean class="org.apache.ibatis.transaction.managed.ManagedTransactionFactory" />
</property>
<property name="typeAliasesPackage"
value="
org.maxkey.domain,
org.maxkey.domain.apps,
" />
<property name="mapperLocations" value="classpath*:org/maxkey/dao/persistence/xml/#{dataSoruceConfig.database}/*.xml" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage"
value="
org.maxkey.dao.persistence,
" />
</bean>
</beans>

View File

@@ -1,131 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- enable autowire -->
<context:annotation-config />
<!-- language select must remove -->
<mvc:annotation-driven />
<!-- 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-->
<!-- domain bean -->
<context:component-scan base-package="org.maxkey.domain" />
<context:component-scan base-package="org.maxkey.domain.apps" />
<context:component-scan base-package="org.maxkey.domain.userinfo" />
<!-- Business Contorller -->
<context:component-scan base-package="org.maxkey.web.endpoint" />
<context:component-scan base-package="org.maxkey.web.contorller" />
<context:component-scan base-package="org.maxkey.web.apps.contorller" />
<context:component-scan base-package="org.maxkey.web.endpoint" />
<context:component-scan base-package="org.maxkey.authn" />
<context:component-scan base-package="org.maxkey.dao" />
<context:component-scan base-package="org.maxkey.web" />
<context:component-scan base-package="org.maxkey.web.tag" />
<!-- LocaleResolver -->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="cookieDomain" value="#{applicationConfig.subDomainName}"/>
<property name="cookieName" value="single_sign_on_lang"/>
<property name="cookieMaxAge" value="604800" />
<!-- auto select language by brower remove -->
<!--<property name="defaultLocale" value="en" /> -->
</bean>
<!-- 消息处理可以直接使用properties的key值返回的是对应的value值 -->
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:messages/message</value>
</list>
</property>
<!-- 必须设置成false否则hibernate原有的校验信息无法返回value值-->
<property name="useCodeAsDefaultMessage" value="false"/>
</bean>
<!-- Locale Change Interceptor and Resolver definition -->
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language" />
</bean>
<!-- XML bean Marshaller define -->
<bean id="Jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>org.maxkey.domain.xml.UserInfoXML</value>
</list>
</property>
</bean>
<!-- MarshallingHttpMessageConverter -->
<bean id="marshallingHttpMessageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="Jaxb2Marshaller" />
<property name="unmarshaller" ref="Jaxb2Marshaller" />
<property name="supportedMediaTypes">
<list>
<value>application/xml;charset=UTF-8</value>
</list>
</property>
</bean>
<!--MappingJacksonHttpMessageConverter -->
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- REST Client -->
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<ref bean="marshallingHttpMessageConverter" />
<ref bean="mappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
<!-- AnnotationMethodHandlerAdapter -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<util:list id="beanList">
<ref bean="marshallingHttpMessageConverter" />
<ref bean="mappingJacksonHttpMessageConverter" />
</util:list>
</property>
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor" />
</list>
</property>
</bean>
<!-- upload file support -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="4194304" />
</bean>
</beans>

View File

@@ -34,6 +34,25 @@
</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-->
<!-- domain bean -->
<context:component-scan base-package="org.maxkey.domain" />
<context:component-scan base-package="org.maxkey.domain.apps" />
<context:component-scan base-package="org.maxkey.domain.userinfo" />
<!-- Business Contorller -->
<context:component-scan base-package="org.maxkey.web.endpoint" />
<context:component-scan base-package="org.maxkey.web.contorller" />
<context:component-scan base-package="org.maxkey.web.apps.contorller" />
<context:component-scan base-package="org.maxkey.web.endpoint" />
<context:component-scan base-package="org.maxkey.authn" />
<context:component-scan base-package="org.maxkey.dao" />
<context:component-scan base-package="org.maxkey.web" />
<context:component-scan base-package="org.maxkey.web.tag" />
<bean id="keyStoreLoader" class="org.maxkey.crypto.keystore.KeyStoreLoader">
<property name="entityName" value="${config.saml.v20.idp.issuing.entity.id}" />
@@ -61,10 +80,6 @@
<property name="passwordEncoder" ref="passwordReciprocal"></property>
</bean>
<import resource="maxkey-mgt-persistence.xml"/>
<import resource="maxkey-mgt-web.xml"/>
<import resource="maxkey-mgt-security.xml"/>
<import resource="maxkey-mgt-task.xml"/>