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);
}
};
}
}