mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-07 17:38:32 +08:00
SnowFlakeId Generator
This commit is contained in:
parent
c47e5f2009
commit
b96db810f8
69
maxkey-common/src/main/java/org/maxkey/util/IdGenerator.java
Normal file
69
maxkey-common/src/main/java/org/maxkey/util/IdGenerator.java
Normal file
@ -0,0 +1,69 @@
|
||||
package org.maxkey.util;
|
||||
|
||||
public class IdGenerator {
|
||||
|
||||
String strategy = "uuid";
|
||||
|
||||
int datacenterId;
|
||||
|
||||
int machineId;
|
||||
|
||||
SnowFlakeId snowFlakeId = new SnowFlakeId(0,0);
|
||||
|
||||
StringGenerator stringGenerator = new StringGenerator();
|
||||
|
||||
|
||||
public String generate(){
|
||||
if(strategy.equalsIgnoreCase("uuid")) {
|
||||
return stringGenerator.uuidGenerate();
|
||||
}else if(strategy.equalsIgnoreCase("SnowFlake")) {
|
||||
return snowFlakeId.nextId()+"";
|
||||
}else {
|
||||
return stringGenerator.randomGenerate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IdGenerator() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IdGenerator(String strategy) {
|
||||
super();
|
||||
this.strategy = strategy;
|
||||
}
|
||||
|
||||
|
||||
public int getDatacenterId() {
|
||||
return datacenterId;
|
||||
}
|
||||
|
||||
public void setDatacenterId(int datacenterId) {
|
||||
this.datacenterId = datacenterId;
|
||||
}
|
||||
|
||||
public int getMachineId() {
|
||||
return machineId;
|
||||
}
|
||||
|
||||
public void setMachineId(int machineId) {
|
||||
this.machineId = machineId;
|
||||
}
|
||||
|
||||
public SnowFlakeId getSnowFlakeId() {
|
||||
return snowFlakeId;
|
||||
}
|
||||
|
||||
public void setSnowFlakeId(SnowFlakeId snowFlakeId) {
|
||||
this.snowFlakeId = snowFlakeId;
|
||||
}
|
||||
|
||||
public StringGenerator getStringGenerator() {
|
||||
return stringGenerator;
|
||||
}
|
||||
|
||||
public void setStringGenerator(StringGenerator stringGenerator) {
|
||||
this.stringGenerator = stringGenerator;
|
||||
}
|
||||
|
||||
}
|
||||
191
maxkey-common/src/main/java/org/maxkey/util/SnowFlakeId.java
Normal file
191
maxkey-common/src/main/java/org/maxkey/util/SnowFlakeId.java
Normal file
@ -0,0 +1,191 @@
|
||||
package org.maxkey.util;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 描述: Twitter的分布式自增ID雪花算法snowflake (Java版)
|
||||
*
|
||||
* @author Crystal.Sea
|
||||
* @create 2021-04-17
|
||||
**/
|
||||
public class SnowFlakeId {
|
||||
|
||||
/**
|
||||
* 起始的时间戳
|
||||
*/
|
||||
private final static long START_STMP = 1480166465631L;
|
||||
|
||||
/**
|
||||
* 每一部分占用的位数
|
||||
*/
|
||||
private final static long SEQUENCE_BIT = 12; //序列号占用的位数
|
||||
private final static long MACHINE_BIT = 5; //机器标识占用的位数
|
||||
private final static long DATACENTER_BIT = 5;//数据中心占用的位数
|
||||
|
||||
/**
|
||||
* 每一部分的最大值
|
||||
*/
|
||||
private final static long MAX_DATACENTER_NUM = -1L ^ (-1L << DATACENTER_BIT);
|
||||
private final static long MAX_MACHINE_NUM = -1L ^ (-1L << MACHINE_BIT);
|
||||
private final static long MAX_SEQUENCE = -1L ^ (-1L << SEQUENCE_BIT);
|
||||
|
||||
/**
|
||||
* 每一部分向左的位移
|
||||
*/
|
||||
private final static long MACHINE_LEFT = SEQUENCE_BIT;
|
||||
private final static long DATACENTER_LEFT = SEQUENCE_BIT + MACHINE_BIT;
|
||||
private final static long TIMESTMP_LEFT = DATACENTER_LEFT + DATACENTER_BIT;
|
||||
|
||||
private long datacenterId; //数据中心
|
||||
private long machineId; //机器标识
|
||||
private long sequence = 0L; //序列号
|
||||
private long lastStmp = -1L;//上一次时间戳
|
||||
private String dateTime;
|
||||
|
||||
public SnowFlakeId(long datacenterId, long machineId) {
|
||||
if (datacenterId > MAX_DATACENTER_NUM || datacenterId < 0) {
|
||||
throw new IllegalArgumentException("datacenterId can't be greater than MAX_DATACENTER_NUM or less than 0");
|
||||
}
|
||||
if (machineId > MAX_MACHINE_NUM || machineId < 0) {
|
||||
throw new IllegalArgumentException("machineId can't be greater than MAX_MACHINE_NUM or less than 0");
|
||||
}
|
||||
this.datacenterId = datacenterId;
|
||||
this.machineId = machineId;
|
||||
}
|
||||
|
||||
public SnowFlakeId(long datacenterId, long machineId, long sequence, long lastStmp) {
|
||||
super();
|
||||
this.datacenterId = datacenterId;
|
||||
this.machineId = machineId;
|
||||
this.sequence = sequence;
|
||||
this.lastStmp = lastStmp;
|
||||
dateTime =DateUtils.toUtc( fromatTime(lastStmp));
|
||||
}
|
||||
|
||||
/**
|
||||
* 产生下一个ID
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public synchronized long nextId() {
|
||||
long currStmp = getNewstmp();
|
||||
if (currStmp < lastStmp) {
|
||||
throw new RuntimeException("Clock moved backwards. Refusing to generate id");
|
||||
}
|
||||
|
||||
if (currStmp == lastStmp) {
|
||||
//相同毫秒内,序列号自增
|
||||
sequence = (sequence + 1) & MAX_SEQUENCE;
|
||||
//同一毫秒的序列数已经达到最大
|
||||
if (sequence == 0L) {
|
||||
currStmp = getNextMill();
|
||||
}
|
||||
} else {
|
||||
//不同毫秒内,序列号置为0
|
||||
sequence = 0L;
|
||||
}
|
||||
|
||||
lastStmp = currStmp;
|
||||
|
||||
return (currStmp - START_STMP) << TIMESTMP_LEFT //时间戳部分
|
||||
| datacenterId << DATACENTER_LEFT //数据中心部分
|
||||
| machineId << MACHINE_LEFT //机器标识部分
|
||||
| sequence; //序列号部分
|
||||
}
|
||||
|
||||
private long getNextMill() {
|
||||
long mill = getNewstmp();
|
||||
while (mill <= lastStmp) {
|
||||
mill = getNewstmp();
|
||||
}
|
||||
return mill;
|
||||
}
|
||||
|
||||
private long getNewstmp() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public SnowFlakeId parse(long id) {
|
||||
String sonwFlakeId = Long.toBinaryString(id);
|
||||
System.out.println(sonwFlakeId);
|
||||
int len = sonwFlakeId.length();
|
||||
int sequenceStart = (int) (len < MACHINE_LEFT ? 0 : len - MACHINE_LEFT);
|
||||
int workerStart = (int) (len < DATACENTER_LEFT ? 0 : len - DATACENTER_LEFT);
|
||||
int timeStart = (int) (len < TIMESTMP_LEFT ? 0 : len - TIMESTMP_LEFT);
|
||||
String sequence = sonwFlakeId.substring(sequenceStart, len);
|
||||
String workerId = sequenceStart == 0 ? "0" : sonwFlakeId.substring(workerStart, sequenceStart);
|
||||
String dataCenterId = workerStart == 0 ? "0" : sonwFlakeId.substring(timeStart, workerStart);
|
||||
String time = timeStart == 0 ? "0" : sonwFlakeId.substring(0, timeStart);
|
||||
int sequenceInt = Integer.valueOf(sequence, 2);
|
||||
int workerIdInt = Integer.valueOf(workerId, 2);
|
||||
int dataCenterIdInt = Integer.valueOf(dataCenterId, 2);
|
||||
long diffTime = Long.parseLong(time, 2);
|
||||
long timeLong = diffTime + START_STMP;
|
||||
|
||||
SnowFlakeId snowFlakeIdParse =new SnowFlakeId(dataCenterIdInt,workerIdInt,sequenceInt,timeLong);
|
||||
|
||||
return snowFlakeIdParse;
|
||||
}
|
||||
|
||||
private static Date fromatTime(long date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(date);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public long getDatacenterId() {
|
||||
return datacenterId;
|
||||
}
|
||||
|
||||
public void setDatacenterId(long datacenterId) {
|
||||
this.datacenterId = datacenterId;
|
||||
}
|
||||
|
||||
public long getMachineId() {
|
||||
return machineId;
|
||||
}
|
||||
|
||||
public void setMachineId(long machineId) {
|
||||
this.machineId = machineId;
|
||||
}
|
||||
|
||||
public long getSequence() {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
public void setSequence(long sequence) {
|
||||
this.sequence = sequence;
|
||||
}
|
||||
|
||||
public long getLastStmp() {
|
||||
return lastStmp;
|
||||
}
|
||||
|
||||
public void setLastStmp(long lastStmp) {
|
||||
this.lastStmp = lastStmp;
|
||||
}
|
||||
|
||||
public String getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(String dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SnowFlakeId snowFlake = new SnowFlakeId(20, 30);
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
System.out.println(snowFlake.nextId());
|
||||
}
|
||||
|
||||
System.out.println(System.currentTimeMillis() - start);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.maxkey.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SonwFlakeIdTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void UidGenerator() {
|
||||
SnowFlakeId snowFlake = new SnowFlakeId(2, 3);
|
||||
long seq = snowFlake.nextId();
|
||||
System.out.println(seq);
|
||||
System.out.println(snowFlake.parse(seq));
|
||||
}
|
||||
}
|
||||
@ -56,4 +56,5 @@ public class UUIDGeneratorTest {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -32,6 +32,9 @@ import org.maxkey.crypto.password.MessageDigestPasswordEncoder;
|
||||
import org.maxkey.crypto.password.PasswordReciprocal;
|
||||
import org.maxkey.crypto.password.SM3PasswordEncoder;
|
||||
import org.maxkey.crypto.password.StandardPasswordEncoder;
|
||||
import org.maxkey.util.IdGenerator;
|
||||
import org.maxkey.util.SnowFlakeId;
|
||||
import org.maxkey.web.WebContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@ -183,6 +186,23 @@ public class ApplicationAutoConfiguration implements InitializingBean {
|
||||
@Value("${maxkey.saml.v20.sp.issuing.entity.id}") String spIssuingEntityName) {
|
||||
return spIssuingEntityName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* spKeyStoreLoader .
|
||||
* @return
|
||||
*/
|
||||
@Bean(name = "idGenerator")
|
||||
public IdGenerator idGenerator(
|
||||
@Value("${maxkey.id.strategy:SnowFlake}") String strategy,
|
||||
@Value("${maxkey.id.datacenterId:0}") int datacenterId,
|
||||
@Value("${maxkey.id.machineId:0}") int machineId) {
|
||||
IdGenerator idGenerator = new IdGenerator(strategy);
|
||||
SnowFlakeId SnowFlakeId = new SnowFlakeId(datacenterId,machineId);
|
||||
idGenerator.setSnowFlakeId(SnowFlakeId);
|
||||
WebContext.idGenerator = idGenerator;
|
||||
return idGenerator;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@ -42,7 +42,7 @@ public class Accounts extends JpaBaseDomain implements Serializable {
|
||||
private static final long serialVersionUID = 6829592256223630307L;
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "uuid")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeid")
|
||||
private String id;
|
||||
@Column
|
||||
private String uid;
|
||||
|
||||
@ -43,7 +43,7 @@ public class GroupMember extends UserInfo implements Serializable{
|
||||
private static final long serialVersionUID = -8059639972590554760L;
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy=GenerationType.AUTO,generator="uuid")
|
||||
@GeneratedValue(strategy=GenerationType.AUTO,generator="snowflakeid")
|
||||
String id;
|
||||
@Column
|
||||
private String groupId;
|
||||
|
||||
@ -45,7 +45,7 @@ public class GroupPrivileges extends Apps implements Serializable{
|
||||
private static final long serialVersionUID = 8634166407201007340L;
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy=GenerationType.AUTO,generator="uuid")
|
||||
@GeneratedValue(strategy=GenerationType.AUTO,generator="snowflakeid")
|
||||
String id;
|
||||
@Column
|
||||
private String groupId;
|
||||
|
||||
@ -33,7 +33,7 @@ public class Groups extends JpaBaseDomain implements Serializable {
|
||||
private static final long serialVersionUID = 4660258495864814777L;
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "uuid")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeid")
|
||||
String id;
|
||||
|
||||
@Length(max = 60)
|
||||
|
||||
@ -43,7 +43,7 @@ public class HistoryLogin extends JpaBaseDomain implements Serializable{
|
||||
private static final long serialVersionUID = -1321470643357719383L;
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy=GenerationType.AUTO,generator="uuid")
|
||||
@GeneratedValue(strategy=GenerationType.AUTO,generator="snowflakeid")
|
||||
String id;
|
||||
@Column
|
||||
String sessionId;
|
||||
|
||||
@ -37,7 +37,7 @@ public class HistoryLoginApps extends JpaBaseDomain {
|
||||
private static final long serialVersionUID = 5085201575292304749L;
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy=GenerationType.AUTO,generator="uuid")
|
||||
@GeneratedValue(strategy=GenerationType.AUTO,generator="snowflakeid")
|
||||
String id;
|
||||
@Column
|
||||
private String sessionId;
|
||||
|
||||
@ -37,7 +37,7 @@ public class HistoryLogs extends JpaBaseDomain implements Serializable {
|
||||
private static final long serialVersionUID = 6560201093784960493L;
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "uuid")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeid")
|
||||
String id;
|
||||
@Column
|
||||
String serviceName;
|
||||
|
||||
@ -22,7 +22,7 @@ public class Notices extends JpaBaseDomain implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "uuid")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeid")
|
||||
protected String id;
|
||||
/**
|
||||
*
|
||||
|
||||
@ -33,7 +33,7 @@ public class Organizations extends JpaBaseDomain implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "uuid")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeid")
|
||||
private String id;
|
||||
@Column
|
||||
private String code;
|
||||
|
||||
@ -32,7 +32,7 @@ public class Resources extends JpaBaseDomain implements Serializable {
|
||||
private static final long serialVersionUID = 2567171742999638608L;
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.AUTO,generator = "uuid")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO,generator = "snowflakeid")
|
||||
String id;
|
||||
@Column
|
||||
String name;
|
||||
|
||||
@ -37,7 +37,7 @@ public class RoleMember extends UserInfo implements Serializable {
|
||||
private static final long serialVersionUID = -8059639972590554760L;
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "uuid")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeid")
|
||||
String id;
|
||||
@Column
|
||||
private String roleId;
|
||||
|
||||
@ -26,6 +26,7 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import org.apache.mybatis.jpa.persistence.JpaBaseDomain;
|
||||
import org.maxkey.constants.ConstantsStatus;
|
||||
import org.maxkey.web.WebContext;
|
||||
|
||||
@Entity
|
||||
@Table(name = "MXK_ROLE_PERMISSIONS")
|
||||
@ -34,7 +35,7 @@ public class RolePermissions extends JpaBaseDomain implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "uuid")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeid")
|
||||
String id;
|
||||
@Column
|
||||
String appId;
|
||||
@ -60,7 +61,7 @@ public class RolePermissions extends JpaBaseDomain implements Serializable {
|
||||
* @param resourceId String
|
||||
*/
|
||||
public RolePermissions(String appId, String roleId, String resourceId) {
|
||||
this.id = this.generateId();
|
||||
this.id = WebContext.genId();
|
||||
this.appId = appId;
|
||||
this.roleId = roleId;
|
||||
this.resourceId = resourceId;
|
||||
|
||||
@ -33,7 +33,7 @@ public class Roles extends JpaBaseDomain implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.AUTO,generator = "uuid")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO,generator = "snowflakeid")
|
||||
private String id;
|
||||
@Column
|
||||
private String name;
|
||||
|
||||
@ -43,7 +43,7 @@ public class UserInfo extends JpaBaseDomain {
|
||||
//
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "uuid")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeid")
|
||||
String id;
|
||||
@Column
|
||||
protected String username;
|
||||
|
||||
@ -37,7 +37,7 @@ public class UserInfoAdjoint extends JpaBaseDomain {
|
||||
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "uuid")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeid")
|
||||
String id;
|
||||
|
||||
protected String displayName;
|
||||
|
||||
@ -28,9 +28,9 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
public class LoginHistoryService {
|
||||
private static Logger _logger = LoggerFactory.getLogger(LoginHistoryService.class);
|
||||
|
||||
private static final String HISTORY_LOGIN_INSERT_STATEMENT = "INSERT INTO MXK_HISTORY_LOGIN (ID , SESSIONID , UID , USERNAME , DISPLAYNAME , LOGINTYPE , MESSAGE , CODE , PROVIDER , SOURCEIP , BROWSER , PLATFORM , APPLICATION , LOGINURL )VALUES( ? , ? , ? , ? , ?, ? , ? , ?, ? , ? , ?, ? , ? , ?)";
|
||||
private static final String HISTORY_LOGIN_INSERT_STATEMENT = "insert into mxk_history_login (id , sessionid , uid , username , displayname , logintype , message , code , provider , sourceip , browser , platform , application , loginurl )values( ? , ? , ? , ? , ?, ? , ? , ?, ? , ? , ?, ? , ? , ?)";
|
||||
|
||||
private static final String HISTORY_LOGOUT_UPDATE_STATEMENT = "UPDATE MXK_HISTORY_LOGIN SET LOGOUTTIME = ? WHERE SESSIONID = ?";
|
||||
private static final String HISTORY_LOGOUT_UPDATE_STATEMENT = "update mxk_history_login set logouttime = ? where sessionid = ?";
|
||||
|
||||
protected JdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
@ -38,29 +38,29 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
public class LoginService {
|
||||
private static Logger _logger = LoggerFactory.getLogger(LoginService.class);
|
||||
|
||||
private static final String LOCK_USER_UPDATE_STATEMENT = "UPDATE MXK_USERINFO SET ISLOCKED = ? , UNLOCKTIME = ? WHERE ID = ?";
|
||||
private static final String LOCK_USER_UPDATE_STATEMENT = "update mxk_userinfo set islocked = ? , unlocktime = ? where id = ?";
|
||||
|
||||
private static final String UNLOCK_USER_UPDATE_STATEMENT = "UPDATE MXK_USERINFO SET ISLOCKED = ? , UNLOCKTIME = ? WHERE ID = ?";
|
||||
private static final String UNLOCK_USER_UPDATE_STATEMENT = "update mxk_userinfo set islocked = ? , unlocktime = ? where id = ?";
|
||||
|
||||
private static final String BADPASSWORDCOUNT_UPDATE_STATEMENT = "UPDATE MXK_USERINFO SET BADPASSWORDCOUNT = ? , BADPASSWORDTIME = ? WHERE ID = ?";
|
||||
private static final String BADPASSWORDCOUNT_UPDATE_STATEMENT = "update mxk_userinfo set badpasswordcount = ? , badpasswordtime = ? where id = ?";
|
||||
|
||||
private static final String BADPASSWORDCOUNT_RESET_UPDATE_STATEMENT = "UPDATE MXK_USERINFO SET BADPASSWORDCOUNT = ? , ISLOCKED = ? ,UNLOCKTIME = ? WHERE ID = ?";
|
||||
private static final String BADPASSWORDCOUNT_RESET_UPDATE_STATEMENT = "update mxk_userinfo set badpasswordcount = ? , islocked = ? ,unlocktime = ? where id = ?";
|
||||
|
||||
private static final String LOGIN_USERINFO_UPDATE_STATEMENT = "UPDATE MXK_USERINFO SET LASTLOGINTIME = ? , LASTLOGINIP = ? , LOGINCOUNT = ?, ONLINE = "
|
||||
+ UserInfo.ONLINE.ONLINE + " WHERE ID = ?";
|
||||
private static final String LOGIN_USERINFO_UPDATE_STATEMENT = "update mxk_userinfo set lastlogintime = ? , lastloginip = ? , logincount = ?, online = "
|
||||
+ UserInfo.ONLINE.ONLINE + " where id = ?";
|
||||
|
||||
private static final String LOGOUT_USERINFO_UPDATE_STATEMENT = "UPDATE MXK_USERINFO SET LASTLOGOFFTIME = ? , ONLINE = "
|
||||
+ UserInfo.ONLINE.OFFLINE + " WHERE ID = ?";
|
||||
private static final String LOGOUT_USERINFO_UPDATE_STATEMENT = "update mxk_userinfo set lastlogofftime = ? , online = "
|
||||
+ UserInfo.ONLINE.OFFLINE + " where id = ?";
|
||||
|
||||
private static final String GROUPS_SELECT_STATEMENT = "SELECT DISTINCT G.ID,G.NAME FROM MXK_USERINFO U,`MXK_GROUPS` G,MXK_GROUP_MEMBER GM WHERE U.ID = ? AND U.ID=GM.MEMBERID AND GM.GROUPID=G.ID ";
|
||||
private static final String GROUPS_SELECT_STATEMENT = "select distinct g.id,g.name from mxk_userinfo u,`mxk_groups` g,mxk_group_member gm where u.id = ? and u.id=gm.memberid and gm.groupid=g.id ";
|
||||
|
||||
private static final String DEFAULT_USERINFO_SELECT_STATEMENT = "SELECT * FROM MXK_USERINFO WHERE USERNAME = ?";
|
||||
private static final String DEFAULT_USERINFO_SELECT_STATEMENT = "select * from mxk_userinfo where username = ?";
|
||||
|
||||
private static final String DEFAULT_USERINFO_SELECT_STATEMENT_USERNAME_MOBILE = "SELECT * FROM MXK_USERINFO WHERE USERNAME = ? OR MOBILE = ? ";
|
||||
private static final String DEFAULT_USERINFO_SELECT_STATEMENT_USERNAME_MOBILE = "select * from mxk_userinfo where username = ? or mobile = ? ";
|
||||
|
||||
private static final String DEFAULT_USERINFO_SELECT_STATEMENT_USERNAME_MOBILE_EMAIL = "SELECT * FROM MXK_USERINFO WHERE USERNAME = ? OR MOBILE = ? OR EMAIL = ? ";
|
||||
private static final String DEFAULT_USERINFO_SELECT_STATEMENT_USERNAME_MOBILE_EMAIL = "select * from mxk_userinfo where username = ? or mobile = ? or email = ? ";
|
||||
|
||||
private static final String DEFAULT_MYAPPS_SELECT_STATEMENT = "SELECT DISTINCT APP.ID,APP.NAME FROM MXK_APPS APP,MXK_GROUP_PRIVILEGES GP,MXK_GROUPS G WHERE APP.ID=GP.APPID AND GP.GROUPID=G.ID AND G.ID IN(%s)";
|
||||
private static final String DEFAULT_MYAPPS_SELECT_STATEMENT = "select distinct app.id,app.name from mxk_apps app,mxk_group_privileges gp,mxk_groups g where app.id=gp.appid and gp.groupid=g.id and g.id in(%s)";
|
||||
|
||||
protected JdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
@ -92,15 +92,15 @@ public class PasswordPolicyValidator {
|
||||
|
||||
private static final String PASSWORD_POLICY_KEY = "PASSWORD_POLICY_KEY";
|
||||
|
||||
private static final String LOCK_USER_UPDATE_STATEMENT = "UPDATE MXK_USERINFO SET ISLOCKED = ? , UNLOCKTIME = ? WHERE ID = ?";
|
||||
private static final String LOCK_USER_UPDATE_STATEMENT = "update mxk_userinfo set islocked = ? , unlocktime = ? where id = ?";
|
||||
|
||||
private static final String PASSWORD_POLICY_SELECT_STATEMENT = "SELECT * FROM MXK_PASSWORD_POLICY ";
|
||||
private static final String PASSWORD_POLICY_SELECT_STATEMENT = "select * from mxk_password_policy ";
|
||||
|
||||
private static final String UNLOCK_USER_UPDATE_STATEMENT = "UPDATE MXK_USERINFO SET ISLOCKED = ? , UNLOCKTIME = ? WHERE ID = ?";
|
||||
private static final String UNLOCK_USER_UPDATE_STATEMENT = "update mxk_userinfo set islocked = ? , unlocktime = ? where id = ?";
|
||||
|
||||
private static final String BADPASSWORDCOUNT_UPDATE_STATEMENT = "UPDATE MXK_USERINFO SET BADPASSWORDCOUNT = ? , BADPASSWORDTIME = ? WHERE ID = ?";
|
||||
private static final String BADPASSWORDCOUNT_UPDATE_STATEMENT = "update mxk_userinfo set badpasswordcount = ? , badpasswordtime = ? where id = ?";
|
||||
|
||||
private static final String BADPASSWORDCOUNT_RESET_UPDATE_STATEMENT = "UPDATE MXK_USERINFO SET BADPASSWORDCOUNT = ? , ISLOCKED = ? ,UNLOCKTIME = ? WHERE ID = ?";
|
||||
private static final String BADPASSWORDCOUNT_RESET_UPDATE_STATEMENT = "update mxk_userinfo set badpasswordcount = ? , islocked = ? ,unlocktime = ? where id = ?";
|
||||
|
||||
public PasswordPolicyValidator() {
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.maxkey.configuration.ApplicationConfig;
|
||||
import org.maxkey.domain.UserInfo;
|
||||
import org.maxkey.util.DateUtils;
|
||||
import org.maxkey.util.StringGenerator;
|
||||
import org.maxkey.util.IdGenerator;
|
||||
import org.maxkey.web.message.Message;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -63,6 +63,8 @@ public final class WebContext {
|
||||
|
||||
public static ArrayList<String> sessionAttributeNameList = new ArrayList<String>();
|
||||
|
||||
public static IdGenerator idGenerator;
|
||||
|
||||
static {
|
||||
sessionAttributeNameList.add(WebConstants.CURRENT_LOGIN_USER_PASSWORD_SET_TYPE);
|
||||
sessionAttributeNameList.add(WebConstants.FIRST_SAVED_REQUEST_PARAMETER);
|
||||
@ -518,7 +520,10 @@ public final class WebContext {
|
||||
* @return String
|
||||
*/
|
||||
public static String genId() {
|
||||
return (new StringGenerator()).uuidGenerate();
|
||||
if(idGenerator == null) {
|
||||
idGenerator = new IdGenerator();
|
||||
}
|
||||
return idGenerator.generate();
|
||||
}
|
||||
|
||||
public static ModelAndView redirect(String redirectUrl) {
|
||||
|
||||
Binary file not shown.
BIN
maxkey-lib/mybatis-jpa-extra-2.3.jar
Normal file
BIN
maxkey-lib/mybatis-jpa-extra-2.3.jar
Normal file
Binary file not shown.
Binary file not shown.
BIN
maxkey-lib/mybatis-jpa-extra-spring-boot-starter-2.3.jar
Normal file
BIN
maxkey-lib/mybatis-jpa-extra-spring-boot-starter-2.3.jar
Normal file
Binary file not shown.
@ -37,7 +37,7 @@ public interface AppsMapper extends IJpaBaseMapper<Apps> {
|
||||
|
||||
public int updateApp(Apps app);
|
||||
|
||||
@Update("UPDATE MXK_APPS SET ISEXTENDATTR=#{isExtendAttr}, EXTENDATTR=#{extendAttr} WHERE id = #{id}")
|
||||
@Update("update mxk_apps set isextendattr=#{isExtendAttr}, extendattr=#{extendAttr} where id = #{id}")
|
||||
public int updateExtendAttr(Apps app);
|
||||
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ public interface UserInfoMapper extends IJpaBaseMapper<UserInfo>{
|
||||
|
||||
public int updateProfile(UserInfo userInfo);
|
||||
|
||||
@Select("SELECT * FROM MXK_USERINFO WHERE EMAIL = #{value} OR MOBILE= #{value}")
|
||||
@Select("select * from mxk_userinfo where email = #{value} or mobile= #{value}")
|
||||
public UserInfo queryUserInfoByEmailMobile(String emailMobile);
|
||||
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ public class GroupMemberController {
|
||||
|
||||
for (int i = 0; i < arrMemberIds.length; i++) {
|
||||
GroupMember newGroupMember = new GroupMember(groupId,groupMember.getGroupName(), arrMemberIds[i], arrMemberNames[i],"USER");
|
||||
newGroupMember.setId(newGroupMember.generateId());
|
||||
newGroupMember.setId(WebContext.genId());
|
||||
result = groupMemberService.insert(newGroupMember);
|
||||
}
|
||||
if(!result) {
|
||||
|
||||
@ -110,7 +110,7 @@ public class GroupPrivilegesController {
|
||||
|
||||
for (int i = 0; i < arrAppIds.length; i++) {
|
||||
GroupPrivileges newGroupApp = new GroupPrivileges(groupId, arrAppIds[i]);
|
||||
newGroupApp.setId(newGroupApp.generateId());
|
||||
newGroupApp.setId(WebContext.genId());
|
||||
result = groupPrivilegesService.insert(newGroupApp);
|
||||
}
|
||||
if(!result) {
|
||||
|
||||
@ -114,7 +114,7 @@ public class RoleMemberController {
|
||||
|
||||
for (int i = 0; i < arrMemberIds.length; i++) {
|
||||
RoleMember newRoleMember = new RoleMember(groupId,roleMember.getRoleName(), arrMemberIds[i], arrMemberNames[i],"USER");
|
||||
newRoleMember.setId(newRoleMember.generateId());
|
||||
newRoleMember.setId(WebContext.genId());
|
||||
result = roleMemberService.insert(newRoleMember);
|
||||
}
|
||||
if(!result) {
|
||||
|
||||
@ -116,7 +116,7 @@ public class UserInfoController {
|
||||
// new Message(WebContext.getValidErrorText(),result);
|
||||
}
|
||||
|
||||
userInfo.setId(userInfo.generateId());
|
||||
userInfo.setId(WebContext.genId());
|
||||
//userInfo.setNameZHShortSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), true));
|
||||
//userInfo.setNameZHSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), false));
|
||||
if( userInfoService.insert(userInfo)) {
|
||||
|
||||
@ -44,6 +44,8 @@ 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/persistence/mapper/xml/mysql/*.xml
|
||||
mybatis.table-column-snowflake-datacenter-id=1
|
||||
mybatis.table-column-snowflake-machine-id=1
|
||||
mybatis.table-column-escape=true
|
||||
|
||||
############################################################################
|
||||
|
||||
@ -88,7 +88,6 @@ public class HistoryLoginAppAdapter implements AsyncHandlerInterceptor {
|
||||
final UserInfo userInfo = WebContext.getUserInfo();
|
||||
_logger.debug("sessionId : " + sessionId + " ,appId : " + app.getId());
|
||||
HistoryLoginApps historyLoginApps = new HistoryLoginApps();
|
||||
historyLoginApps.setId(historyLoginApps.generateId());
|
||||
historyLoginApps.setAppId(app.getId());
|
||||
historyLoginApps.setSessionId(sessionId);
|
||||
historyLoginApps.setAppName(app.getName());
|
||||
|
||||
@ -49,6 +49,8 @@ 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/persistence/mapper/xml/mysql/*.xml
|
||||
mybatis.table-column-snowflake-datacenter-id=1
|
||||
mybatis.table-column-snowflake-machine-id=1
|
||||
mybatis.table-column-escape=true
|
||||
|
||||
############################################################################
|
||||
|
||||
@ -49,6 +49,8 @@ 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/persistence/mapper/xml/mysql/*.xml
|
||||
mybatis.table-column-snowflake-datacenter-id=1
|
||||
mybatis.table-column-snowflake-machine-id=1
|
||||
mybatis.table-column-escape=true
|
||||
|
||||
############################################################################
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user