This commit is contained in:
MaxKey
2021-08-08 15:15:39 +08:00
parent b3f9c8abf5
commit cecc22edfc
15 changed files with 310 additions and 105 deletions

View File

@@ -28,7 +28,9 @@
*(MAXKEY-210627) 找回密码时密码不匹配问题修复
*(MAXKEY-210628) SHELL脚本优化
*(MAXKEY-210629) 官方网站优化
*(MAXKEY-210630) 依赖jar引用、更新和升级
*(MAXKEY-210630) 标准构建优化
*(MAXKEY-210631) maxkey-web-mgt配置文件分离方便后续不同环境的切换
*(MAXKEY-210632) 依赖jar引用、更新和升级
spring 5.3.9
springBoot 2.5.3
springSession 2.5.1

View File

@@ -459,6 +459,7 @@ task copyMaxKeyLibs(type: Copy) {
from "$rootDir/build/maxkey-jars/maxkey-protocol-oauth-2.0-${project.version}.jar"
from "$rootDir/build/maxkey-jars/maxkey-protocol-saml-2.0-${project.version}.jar"
from "$rootDir/build/maxkey-jars/maxkey-protocol-tokenbased-${project.version}.jar"
from "$rootDir/build/maxkey-jars/maxkey-web-resources-${project.version}.jar"
into "$rootDir/build/MaxKey-v${project.version}GA/lib";
}

View File

@@ -29,6 +29,10 @@ public class ChangePassword extends JpaBaseEntity{
private String id;
private String uid;
private String username;
private String email;
private String mobile;
private String windowsAccount;
private String employeeNumber;
private String displayName;
private String oldPassword;
private String password;
@@ -155,6 +159,16 @@ public class ChangePassword extends JpaBaseEntity{
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getDisplayName() {
return displayName;
}
@@ -165,6 +179,36 @@ public class ChangePassword extends JpaBaseEntity{
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getWindowsAccount() {
return windowsAccount;
}
public void setWindowsAccount(String windowsAccount) {
this.windowsAccount = windowsAccount;
}
public String getEmployeeNumber() {
return employeeNumber;
}
public void setEmployeeNumber(String employeeNumber) {
this.employeeNumber = employeeNumber;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();

View File

@@ -32,6 +32,9 @@ public class HistoryConnector extends JpaBaseEntity implements Serializable{
@Column
String conType;
@Column
String conAction;
@Column
String sourceId;
@@ -178,36 +181,48 @@ public class HistoryConnector extends JpaBaseEntity implements Serializable{
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("HistoryConnector [id=");
builder.append(id);
builder.append(", conName=");
builder.append(conName);
builder.append(", conType=");
builder.append(conType);
builder.append(", sourceId=");
builder.append(sourceId);
builder.append(", sourceName=");
builder.append(sourceName);
builder.append(", objectId=");
builder.append(objectId);
builder.append(", objectName=");
builder.append(objectName);
builder.append(", description=");
builder.append(description);
builder.append(", syncTime=");
builder.append(syncTime);
builder.append(", result=");
builder.append(result);
builder.append(", startDate=");
builder.append(startDate);
builder.append(", endDate=");
builder.append(endDate);
builder.append("]");
return builder.toString();
}
public String getConAction() {
return conAction;
}
public void setConAction(String conAction) {
this.conAction = conAction;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("HistoryConnector [id=");
builder.append(id);
builder.append(", conName=");
builder.append(conName);
builder.append(", conType=");
builder.append(conType);
builder.append(", conAction=");
builder.append(conAction);
builder.append(", sourceId=");
builder.append(sourceId);
builder.append(", sourceName=");
builder.append(sourceName);
builder.append(", objectId=");
builder.append(objectId);
builder.append(", objectName=");
builder.append(objectName);
builder.append(", description=");
builder.append(description);
builder.append(", syncTime=");
builder.append(syncTime);
builder.append(", result=");
builder.append(result);
builder.append(", startDate=");
builder.append(startDate);
builder.append(", endDate=");
builder.append(endDate);
builder.append("]");
return builder.toString();
}
}

View File

@@ -65,42 +65,41 @@ public class ActiveDirectoryUtils extends LdapUtils {
this.ctx = dirContext;
}
// connect to ActiveDirectory server
@Override
public DirContext openConnection() {
_logger.info("PROVIDER_URL:" + providerUrl);
_logger.info("SECURITY_PRINCIPAL:" + principal);
_logger.info("SECURITY_CREDENTIALS:" + credentials);
// LDAP
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.setProperty(Context.URL_PKG_PREFIXES, "com.sun.jndi.url");
props.setProperty(Context.REFERRAL, referral);
props.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
props.setProperty(Context.PROVIDER_URL, providerUrl);
if (activeDirectoryDomain == null && domain.indexOf(".") > -1) {
activeDirectoryDomain = domain.substring(0, domain.indexOf("."));
}else {
activeDirectoryDomain = domain;
}
_logger.info("PROVIDER_DOMAIN:" + activeDirectoryDomain + " for " + domain);
String activeDirectoryPrincipal = activeDirectoryDomain + "\\" + principal;
_logger.debug("Active Directory SECURITY_PRINCIPAL : " + activeDirectoryPrincipal);
props.setProperty(Context.SECURITY_PRINCIPAL, activeDirectoryPrincipal);
props.setProperty(Context.SECURITY_CREDENTIALS, credentials);
if (ssl && providerUrl.toLowerCase().startsWith("ldaps")) {
_logger.info("ldaps security protocol.");
System.setProperty("javax.net.ssl.trustStore", trustStore);
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
props.put(Context.SECURITY_PROTOCOL, "ssl");
}
props.put(Context.REFERRAL, "follow");
return InitialDirContext(props);
protected void initEnvironment() {
if(props == null) {
_logger.info("PROVIDER_URL:" + providerUrl);
_logger.info("SECURITY_PRINCIPAL:" + principal);
_logger.info("SECURITY_CREDENTIALS:" + credentials);
// LDAP
props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.setProperty(Context.URL_PKG_PREFIXES, "com.sun.jndi.url");
props.setProperty(Context.REFERRAL, referral);
props.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
props.setProperty(Context.PROVIDER_URL, providerUrl);
if (domain.indexOf(".") > -1) {
activeDirectoryDomain = domain.substring(0, domain.indexOf("."));
}else {
activeDirectoryDomain = domain;
}
_logger.info("PROVIDER_DOMAIN:" + activeDirectoryDomain + " for " + domain);
String activeDirectoryPrincipal = activeDirectoryDomain + "\\" + principal;
_logger.debug("Active Directory SECURITY_PRINCIPAL : " + activeDirectoryPrincipal);
props.setProperty(Context.SECURITY_PRINCIPAL, activeDirectoryPrincipal);
props.setProperty(Context.SECURITY_CREDENTIALS, credentials);
if (ssl && providerUrl.toLowerCase().startsWith("ldaps")) {
_logger.info("ldaps security protocol.");
System.setProperty("javax.net.ssl.trustStore", trustStore);
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
props.put(Context.SECURITY_PROTOCOL, "ssl");
}
props.put(Context.REFERRAL, "follow");
}
}
public String getDomain() {

View File

@@ -53,6 +53,7 @@ public class LdapUtils {
protected String trustStorePassword;
protected boolean ssl;
protected int searchScope;
protected Properties props;
/**
*
@@ -90,42 +91,60 @@ public class LdapUtils {
}
protected DirContext InitialDirContext(Properties properties) {
if(ctx == null) {
ctx =createDirContext(properties);
}
return ctx;
}
protected DirContext createDirContext(Properties properties) {
DirContext ctx = null;
try {
ctx = new InitialDirContext(properties);
ctx = new InitialDirContext(properties);
_logger.info("connect to ldap " + providerUrl + " seccessful.");
} catch (NamingException e) {
_logger.error("connect to ldap " + providerUrl + " fail.");
e.printStackTrace();
_logger.error(e.getMessage());
}
return ctx;
}
protected void initEnvironment() {
// LDAP
if(props == null) {
_logger.debug("PROVIDER_URL:" + providerUrl);
_logger.debug("SECURITY_PRINCIPAL:" + principal);
_logger.trace("SECURITY_CREDENTIALS:" + credentials);
props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.setProperty(Context.URL_PKG_PREFIXES, "com.sun.jndi.url");
props.setProperty(Context.REFERRAL, referral);
props.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
props.setProperty(Context.PROVIDER_URL, providerUrl);
props.setProperty(Context.SECURITY_PRINCIPAL, principal);
props.setProperty(Context.SECURITY_CREDENTIALS, credentials);
if (ssl && providerUrl.toLowerCase().startsWith("ldaps")) {
System.setProperty("javax.net.ssl.trustStore", trustStore);
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
props.put(Context.SECURITY_PROTOCOL, "ssl");
props.put(Context.REFERRAL, "follow");
}
}
}
// connect to ldap server
public DirContext openConnection() {
_logger.debug("PROVIDER_URL:" + providerUrl);
_logger.debug("SECURITY_PRINCIPAL:" + principal);
_logger.trace("SECURITY_CREDENTIALS:" + credentials);
// LDAP
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.setProperty(Context.URL_PKG_PREFIXES, "com.sun.jndi.url");
props.setProperty(Context.REFERRAL, referral);
props.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
props.setProperty(Context.PROVIDER_URL, providerUrl);
props.setProperty(Context.SECURITY_PRINCIPAL, principal);
props.setProperty(Context.SECURITY_CREDENTIALS, credentials);
if (ssl && providerUrl.toLowerCase().startsWith("ldaps")) {
System.setProperty("javax.net.ssl.trustStore", trustStore);
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
props.put(Context.SECURITY_PROTOCOL, "ssl");
props.put(Context.REFERRAL, "follow");
}
initEnvironment();
return InitialDirContext(props);
}
// connect to ldap server
public DirContext createConnection() {
initEnvironment();
return createDirContext(props);
}
public boolean authenticate() {
openConnection();

View File

@@ -17,6 +17,8 @@
package org.maxkey.synchronizer;
import org.apache.mybatis.jpa.util.WebContext;
import org.maxkey.entity.Synchronizers;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
@@ -44,10 +46,13 @@ public class SynchronizerJob implements Job {
_logger.debug("SynchronizerJob is running ... " );
jobStatus = JOBSTATUS.RUNNING;
try {
ISynchronizerService service =
(ISynchronizerService)context.getMergedJobDataMap().get("synchronizerService");
Synchronizers synchronizer = (Synchronizers)context.getMergedJobDataMap().get("synchronizer");
_logger.debug("synchronizer : " + synchronizer.getName()+"("+synchronizer.getId()+"_"+synchronizer.getSourceType()+")");
_logger.debug("synchronizer service : " + synchronizer.getService());
_logger.debug("synchronizer Scheduler : " + synchronizer.getScheduler());
ISynchronizerService service = (ISynchronizerService)WebContext.getBean(synchronizer.getService());
service.setSynchronizer(synchronizer);
service.sync();
Thread.sleep(10 *1000);
_logger.debug("SynchronizerJob is success " );
}catch(Exception e) {

View File

@@ -0,0 +1,118 @@
package org.maxkey.synchronizer.autoconfigure;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.maxkey.constants.ConstantsProperties;
import org.maxkey.entity.Synchronizers;
import org.maxkey.synchronizer.SynchronizerJob;
import org.quartz.CronExpression;
import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.TriggerBuilder;
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.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
@Configuration
@PropertySource(ConstantsProperties.applicationPropertySource)
public class SynchronizerAutoConfiguration implements InitializingBean {
private static final Logger _logger =
LoggerFactory.getLogger(SynchronizerAutoConfiguration.class);
public static final String SYNCHRONIZERS_SELECT_STATEMENT = "select * from mxk_synchronizers where status ='1'";
@Bean(name = "schedulerSynchronizerJobs")
public Scheduler schedulerSynchronizerJobs(
JdbcTemplate jdbcTemplate,
SchedulerFactoryBean schedulerFactoryBean,
@Value("${maxkey.job.cron.enable}") boolean jobCronEnable
) throws SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
if(jobCronEnable) {
List<Synchronizers> synchronizerList = querySynchronizers(jdbcTemplate);
for(Synchronizers synchronizer : synchronizerList) {
if(synchronizer.getScheduler()!=null
&& !synchronizer.getScheduler().equals("")
&& CronExpression.isValidExpression(synchronizer.getScheduler())) {
_logger.debug("synchronizer details : " + synchronizer);
buildJob(scheduler,synchronizer);
}
}
}
return scheduler;
}
private void buildJob(Scheduler scheduler ,
Synchronizers synchronizer) throws SchedulerException {
JobDetail jobDetail =
JobBuilder.newJob(SynchronizerJob.class)
.withIdentity(synchronizer.getService()+"Job", "SynchronizerGroups")
.build();
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("synchronizer", synchronizer);
_logger.debug("synchronizer : " + synchronizer.getName()+"("+synchronizer.getId()+"_"+synchronizer.getSourceType()+")");
_logger.debug("synchronizer service : " + synchronizer.getService());
_logger.debug("synchronizer Scheduler : " + synchronizer.getScheduler());
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(synchronizer.getScheduler());
CronTrigger cronTrigger =
TriggerBuilder.newTrigger()
.withIdentity("trigger"+synchronizer.getService(), "SynchronizerGroups")
.usingJobData(jobDataMap)
.withSchedule(scheduleBuilder)
.build();
scheduler.scheduleJob(jobDetail,cronTrigger);
}
public List<Synchronizers> querySynchronizers(JdbcTemplate jdbcTemplate) {
List<Synchronizers> synchronizerList = jdbcTemplate.query(SYNCHRONIZERS_SELECT_STATEMENT, new RowMapper<Synchronizers>() {
public Synchronizers mapRow(ResultSet rs, int rowNum) throws SQLException {
Synchronizers synchronizer = new Synchronizers();
synchronizer.setId( rs.getString("id"));
synchronizer.setName( rs.getString("name"));
synchronizer.setScheduler( rs.getString("scheduler"));
synchronizer.setSourceType( rs.getString("sourcetype"));
synchronizer.setProviderUrl(rs.getString("providerurl"));
synchronizer.setDriverClass(rs.getString("driverclass"));
synchronizer.setPrincipal( rs.getString("principal"));
synchronizer.setCredentials(rs.getString("credentials"));
synchronizer.setResumeTime( rs.getString("resumetime"));
synchronizer.setSuspendTime(rs.getString("suspendtime"));
synchronizer.setFilters( rs.getString("filters"));
synchronizer.setBasedn( rs.getString("basedn"));
synchronizer.setMsadDomain( rs.getString("msaddomain"));
synchronizer.setSslSwitch( rs.getString("sslswitch"));
synchronizer.setTrustStore( rs.getString("truststore"));
synchronizer.setStatus( rs.getString("status"));
synchronizer.setDescription(rs.getString("description"));
synchronizer.setSyncStartTime(rs.getInt("syncstarttime"));
synchronizer.setService(rs.getString("service"));
return synchronizer;
}
});
return synchronizerList;
}
@Override
public void afterPropertiesSet() throws Exception {
// TODO Auto-generated method stub
}
}

View File

@@ -19,7 +19,7 @@
and uid = #{uid}
</if>
<if test="username != null and username != ''">
and username = #{username}
and username = #{username}
</if>
<if test="displayName != null and displayName != ''">
and displayname like concat('%',#{displayName},'%')

View File

@@ -22,8 +22,9 @@
select
count(*) reportcount
from mxk_userinfo
where
lastlogintime -lastlogofftime
where online = 1
and now() - lastlogintime between 1 and 10000
and lastlogintime > lastlogofftime
</select>
<!-- 30天活跃用户统计 -->
<select id="analysisActiveUsers" parameterType="String" resultType="Integer">

View File

@@ -96,11 +96,11 @@
<update id="changePassword" parameterType="UserInfo" >
update mxk_userinfo set
<if test="password != null">
password = #{password},
decipherable = #{decipherable},
passwordsettype = #{passwordSetType},
password = #{password},
decipherable = #{decipherable},
passwordsettype =#{passwordSetType},
</if>
passwordlastsettime = current_timestamp
passwordlastsettime = current_timestamp
where
id = #{id}
</update>

View File

@@ -6,5 +6,6 @@ org.maxkey.autoconfigure.MvcAutoConfiguration,\
org.maxkey.autoconfigure.JwtAuthnAutoConfiguration,\
org.maxkey.autoconfigure.RedisAutoConfiguration,\
org.maxkey.autoconfigure.AuthenticationAutoConfiguration,\
org.maxkey.synchronizer.autoconfigure.SynchronizerAutoConfiguration,\
org.maxkey.MaxKeyMgtConfig,\
org.maxkey.MaxKeyMgtMvcConfig

View File

@@ -1,5 +1,5 @@
global.title=Genvict\u8eab\u4efd\u5b89\u5168\u7ba1\u7406\u7cfb\u7edf
global.application=Genvict\u8eab\u4efd\u5b89\u5168\u7ba1\u7406\u7cfb\u7edf
global.title=MaxKey\u8eab\u4efd\u5b89\u5168\u7ba1\u7406\u7cfb\u7edf
global.application=Max<span style="color: #FFD700;">Key</span>\u8eab\u4efd\u5b89\u5168\u7ba1\u7406\u7cfb\u7edf
global.change.language=\u8bed\u8a00\u9009\u62e9
global.change.language.en=English
global.change.language.zh=\u4e2d\u6587

View File

@@ -1,5 +1,5 @@
global.title=Genvict Secure Management
global.application=Secure Management
global.title=MaxKey Secure Management
global.application=Max<span style="color: #FFD700;">Key</span> Secure Management
global.change.language=Language
global.change.language.en=English
global.change.language.zh=\u4e2d\u6587

View File

@@ -1,5 +1,5 @@
global.title=Genvict\u8eab\u4efd\u5b89\u5168\u7ba1\u7406\u7cfb\u7edf
global.application=\u8eab\u4efd\u5b89\u5168\u7ba1\u7406\u7cfb\u7edf
global.title=MaxKey\u8eab\u4efd\u5b89\u5168\u7ba1\u7406\u7cfb\u7edf
global.application=Max<span style="color: #FFD700;">Key</span>\u8eab\u4efd\u5b89\u5168\u7ba1\u7406\u7cfb\u7edf
global.change.language=\u8bed\u8a00\u9009\u62e9
global.change.language.en=English
global.change.language.zh=\u4e2d\u6587