v 1.5.0 RC2

v 1.5.0 RC2
This commit is contained in:
shimingxy
2020-05-17 22:14:12 +08:00
parent d5e494810b
commit dcae09742f
14 changed files with 154 additions and 100 deletions

View File

@@ -15,29 +15,30 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
@SpringBootApplication
@ImportResource(locations={"classpath:spring/maxkey-mgt.xml"})
//@ImportResource(locations={"classpath:spring/maxkey-mgt.xml"})
@ComponentScan(basePackages = {
"org.maxkey.MaxKeyMgtConfig",
"org.maxkey.config",
"org.maxkey.domain",
"org.maxkey.domain.apps",
"org.maxkey.domain.userinfo",
"org.maxkey.web.endpoint",
"org.maxkey.web.contorller",
"org.maxkey.web.apps.contorller",
"org.maxkey.web.endpoint",
"org.maxkey.authn",
"org.maxkey.dao",
"org.maxkey.web",
"org.maxkey.web.tag"
}
)
"org.maxkey.MaxKeyMgtConfig",
"org.maxkey.MaxKeyMgtMvcConfig",
"org.maxkey.web.interceptor",
"org.maxkey.config",
"org.maxkey.domain",
"org.maxkey.domain.apps",
"org.maxkey.domain.userinfo",
"org.maxkey.web.endpoint",
"org.maxkey.web.contorller",
"org.maxkey.web.apps.contorller",
"org.maxkey.web.endpoint",
"org.maxkey.authn",
"org.maxkey.dao",
"org.maxkey.web",
"org.maxkey.web.tag"
})
@MapperScan("org.maxkey.dao.persistence,")
public class MaxKeyMgtApplication extends SpringBootServletInitializer {
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyMgtApplication.class);
public static void main(String[] args) {
System.out.println("MaxKeyMgtApplication");
_logger.info("Start MaxKeyMgtApplication ...");
ConfigurableApplicationContext applicationContext =SpringApplication.run(MaxKeyMgtApplication.class, args);
InitializeContext initWebContext=new InitializeContext(applicationContext);

View File

@@ -2,6 +2,8 @@ package org.maxkey;
import javax.sql.DataSource;
import org.maxkey.authz.oauth2.provider.client.JdbcClientDetailsService;
import org.maxkey.crypto.password.opt.impl.TimeBasedOtpAuthn;
import org.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
@@ -9,6 +11,7 @@ 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.jdbc.core.JdbcTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
@Configuration
@@ -32,9 +35,26 @@ public class MaxKeyMgtConfig implements InitializingBean {
DataSource dataSource,PasswordEncoder passwordReciprocal) {
JdbcClientDetailsService clientDetailsService = new JdbcClientDetailsService(dataSource);
clientDetailsService.setPasswordEncoder(passwordReciprocal);
_logger.debug("JdbcClientDetailsService inited.");
return clientDetailsService;
}
//以下内容可以注释掉后再xml中配置,xml引入在MaxKeyMgtApplication中
@Bean(name = "authenticationRealm")
public JdbcAuthenticationRealm JdbcAuthenticationRealm(
JdbcTemplate jdbcTemplate) {
JdbcAuthenticationRealm authenticationRealm = new JdbcAuthenticationRealm(jdbcTemplate);
_logger.debug("JdbcAuthenticationRealm inited.");
return authenticationRealm;
}
@Bean(name = "tfaOptAuthn")
public TimeBasedOtpAuthn tfaOptAuthn() {
TimeBasedOtpAuthn tfaOptAuthn = new TimeBasedOtpAuthn();
_logger.debug("TimeBasedOtpAuthn inited.");
return tfaOptAuthn;
}
@Override
public void afterPropertiesSet() throws Exception {
// TODO Auto-generated method stub

View File

@@ -0,0 +1,72 @@
package org.maxkey;
import org.maxkey.web.interceptor.HistoryLogsAdapter;
import org.maxkey.web.interceptor.PermissionAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
@Configuration
@EnableWebMvc
public class MaxKeyMgtMvcConfig implements WebMvcConfigurer {
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyMgtMvcConfig.class);
@Autowired
PermissionAdapter permissionAdapter;
@Autowired
HistoryLogsAdapter historyLogsAdapter;
@Autowired
LocaleChangeInterceptor localeChangeInterceptor;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
registry.addResourceHandler("/templates/**")
.addResourceLocations("classpath:/templates/");
_logger.debug("add addResourceHandler");
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
//addPathPatterns 用于添加拦截规则 先把所有路径都加入拦截, 再一个个排除
//excludePathPatterns 表示改路径不用拦截
registry.addInterceptor(permissionAdapter)
.addPathPatterns("/main/**")
.addPathPatterns("/orgs/**")
.addPathPatterns("/userinfo/**")
.addPathPatterns("/apps/**")
.addPathPatterns("/groups/**")
.addPathPatterns("/groupMember/**")
.addPathPatterns("/groupPrivileges/**")
.addPathPatterns("/config/**")
.addPathPatterns("/logs/**")
;
_logger.debug("add PermissionAdapter");
registry.addInterceptor(historyLogsAdapter)
.addPathPatterns("/users/*")
.addPathPatterns("/userinfo/**")
.addPathPatterns("/enterprises/**")
.addPathPatterns("/employees/**")
.addPathPatterns("/authInfo/**")
.addPathPatterns("/usercenter/**")
.addPathPatterns("/retrievePassword/**")
.addPathPatterns("/roles/**")
.addPathPatterns("/apps/**")
.addPathPatterns("/approles/**")
;
_logger.debug("add HistoryLogsAdapter");
registry.addInterceptor(localeChangeInterceptor);
_logger.debug("add LocaleChangeInterceptor");
}
}

View File

@@ -14,6 +14,8 @@ 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.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@@ -25,6 +27,7 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
* @author Crystal.Sea
*
*/
@Component
public class HistoryLogsAdapter extends HandlerInterceptorAdapter {
private static final Logger _logger = LoggerFactory.getLogger(HistoryLogsAdapter.class);

View File

@@ -12,6 +12,8 @@ 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.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
/**
* 权限Interceptor处理
@@ -20,7 +22,7 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
* @author Crystal.Sea
*
*/
@Component
public class PermissionAdapter extends HandlerInterceptorAdapter {
private static final Logger _logger = LoggerFactory.getLogger(PermissionAdapter.class);
//无需Interceptor url