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,18 +1,23 @@
package org.maxkey;
import java.io.IOException;
import java.util.Properties;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import javax.sql.DataSource;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.maxkey.authz.oauth2.provider.endpoint.TokenEndpointAuthenticationFilter;
import org.maxkey.authn.RealmAuthenticationProvider;
import org.maxkey.authn.SavedRequestAwareAuthenticationSuccessHandler;
import org.maxkey.crypto.password.PasswordReciprocal;
import org.maxkey.crypto.password.opt.algorithm.KeyUriFormat;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
@@ -21,20 +26,20 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
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;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
@Configuration
@ImportResource(locations = { "classpath:spring/maxkey.xml" })
@PropertySource("classpath:/application.properties")
@PropertySource("classpath:/config/applicationConfig.properties")
@MapperScan("org.maxkey.dao.persistence,")
public class MaxKeyConfig {
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyConfig.class);
@Value("${server.port:8080}")
private int port;
@@ -42,10 +47,13 @@ public class MaxKeyConfig {
return port;
}
public void setPort(int port) {
this.port = port;
@Bean
@Primary
@ConfigurationProperties("spring.datasource")
public DataSource dataSource() {
return DruidDataSourceBuilder.create().build();
}
@Bean
public FilterRegistrationBean<TokenEndpointAuthenticationFilter> TokenEndpointAuthenticationFilter() {
FilterRegistrationBean<TokenEndpointAuthenticationFilter> registration = new FilterRegistrationBean<TokenEndpointAuthenticationFilter>();
@@ -66,6 +74,7 @@ public class MaxKeyConfig {
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");
@@ -111,21 +120,52 @@ public class MaxKeyConfig {
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;
@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() {
KeyUriFormat keyUriFormat=new KeyUriFormat();
keyUriFormat.setType(keyuriFormatType);
keyUriFormat.setDomain(keyuriFormatDomain);
keyUriFormat.setIssuer(keyuriFormatIssuer);
keyUriFormat.setDigits(keyuriFormatDigits);
keyUriFormat.setPeriod(keyuriFormatPeriod);
_logger.debug("KeyUri Format " + keyUriFormat);
return keyUriFormat;
}
@Bean(name = "authenticationProvider")
public RealmAuthenticationProvider authenticationProvider() {
return new RealmAuthenticationProvider();
}
@Bean(name = "jdbcTemplate")
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
@Bean(name = "sqlSession")
public SqlSessionTemplate sqlSession(SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
@Bean(name = "transactionManager")
DataSourceTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
}

View File

@@ -0,0 +1,50 @@
package org.maxkey;
import org.maxkey.persistence.redis.RedisConnectionFactory;
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 redis.clients.jedis.JedisPoolConfig;
@Configuration
@PropertySource("classpath:/application.properties")
public class RedisAutoConfiguration {
@Value("${spring.redis.host}")
private String host;
@Value("${spring.redis.port}")
private int port;
@Value("${spring.redis.timeout}")
private int timeout;
@Value("${spring.redis.password}")
private String password;
@Value("${spring.redis.lettuce.pool.max-active}")
private int maxActive;
@Value("${spring.redis.jedis.pool.max-wait}")
private int maxWait;
@Value("${spring.redis.jedis.pool.max-idle}")
private int maxIdle;
@Value("${spring.redis.lettuce.pool.min-idle}")
private int minIdle;
@Bean
public RedisConnectionFactory redisConnectionFactory() {
RedisConnectionFactory factory = new RedisConnectionFactory();
factory.setHostName(host);
factory.setPort(port);
factory.setTimeOut(timeout);
factory.setPassword(password);
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxIdle(maxIdle);
poolConfig.setMinIdle(minIdle);
poolConfig.setMaxTotal(maxActive);
poolConfig.setMaxWaitMillis(maxWait);
factory.setPoolConfig(poolConfig);
return factory;
}
}

View File

@@ -10,8 +10,8 @@ import org.maxkey.crypto.password.opt.algorithm.OtpSecret;
import org.maxkey.dao.service.UserInfoService;
import org.maxkey.domain.UserInfo;
import org.maxkey.util.RQCodeUtils;
import org.maxkey.web.ImageEndpoint;
import org.maxkey.web.WebContext;
import org.maxkey.web.image.ImageEndpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -80,7 +80,7 @@ public class RegistrationController {
email.setAuthenticator(new DefaultAuthenticator(applicationConfig.getEmailConfig().getUsername(), applicationConfig.getEmailConfig().getPassword()));
email.addTo(registration.getWorkEmail(), registration.getLastName()+registration.getFirstName());
email.setFrom(applicationConfig.getEmailConfig().getSenderMail(), "ConnSec");
email.setFrom(applicationConfig.getEmailConfig().getSender(), "ConnSec");
email.setSubject("ConnSec Cloud Identity & Access Registration activate Email .");
String activateUrl=WebContext.getHttpContextPath()+"/registration/forward/activate/"+registration.getId();