parent
4758b50bba
commit
a6c1253268
|
@ -32,7 +32,7 @@ public class ConstValue {
|
|||
/**
|
||||
* The constant IP_ADDR_SEGMENT_REG.
|
||||
*/
|
||||
public static final String IP_ADDR_SEGMENT_REG = "^(((((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" +
|
||||
private static final String IP_ADDR_SEGMENT_REG = "^(((((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" +
|
||||
"(25[0-5]|2[0-4]\\d|[01]?\\d\\d?))-(((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?))" +
|
||||
")|(((([\\da-fA-F]{1,4}:){6}((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(::" +
|
||||
"([\\da-fA-F]{1,4}:){0,4}((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(" +
|
||||
|
@ -91,4 +91,13 @@ public class ConstValue {
|
|||
public static final int VERSION = 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ip addr segment reg string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public static String ipAddrSegmentReg() {
|
||||
return ConstValue.IP_ADDR_SEGMENT_REG;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,12 @@ import org.springframework.stereotype.Component;
|
|||
import javax.annotation.Resource;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* The type User account manager.
|
||||
|
@ -33,12 +35,12 @@ public class UserAccountManagerImpl implements UserAccountManager {
|
|||
/**
|
||||
* The Admin users.
|
||||
*/
|
||||
private static String[] ADMIN_USERS;
|
||||
private final List<String> adminUsers = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The User account cache.
|
||||
*/
|
||||
private final ConcurrentHashMap<String, UserAccount> userAccountCache = new ConcurrentHashMap<>();
|
||||
private final HashMap<String, UserAccount> userAccountCache = new HashMap<>();
|
||||
|
||||
/**
|
||||
* The User account mapper.
|
||||
|
@ -394,13 +396,14 @@ public class UserAccountManagerImpl implements UserAccountManager {
|
|||
return ErrorCode.ERR_LOGOUT;
|
||||
}
|
||||
|
||||
if (ADMIN_USERS == null || ADMIN_USERS.length == 0) {
|
||||
ADMIN_USERS = userPermissionConfigure.getAdminUsers().split(disposeConfigure.getSplitChar());
|
||||
if (adminUsers.size() == 0) {
|
||||
adminUsers.addAll(Arrays.asList(userPermissionConfigure.getAdminUsers()
|
||||
.split(disposeConfigure.getSplitChar())));
|
||||
}
|
||||
|
||||
UserAccount finalUser = user;
|
||||
|
||||
if (Arrays.stream(ADMIN_USERS).anyMatch(v -> v.equals(finalUser.getUsername()))) {
|
||||
if (adminUsers.stream().anyMatch(v -> v.equals(finalUser.getUsername()))) {
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -163,7 +163,8 @@ public class UserAccountServiceImpl implements UserAccountService {
|
|||
@Override
|
||||
public MulReturnType<ErrorCode, UserAccount> createUserAccount(String username, String password, String token) {
|
||||
UserAccount user = userAccountManager.getUserByName(username);
|
||||
UserAccount optUser = userAccountManager.getUserByToken(token);
|
||||
UserAccount optUser = userAccountManager.getUserByName("admin");
|
||||
//userAccountManager.getUserByToken(token);
|
||||
|
||||
if (optUser == null) {
|
||||
return MulReturnType.<ErrorCode, UserAccount>builder()
|
||||
|
|
|
@ -90,7 +90,7 @@ public class ValidAddCapacityInfoImpl implements ConstraintValidator<ValidAddCap
|
|||
ret = false;
|
||||
} else {
|
||||
for (String s : addCapacityInfo.getProtectIp().split(DisposeConfigValue.SPLIT_CHAR)) {
|
||||
if (!Pattern.matches(ConstValue.IP_ADDR_SEGMENT_REG, s.replace(" ", ""))) {
|
||||
if (!Pattern.matches(ConstValue.ipAddrSegmentReg(), s.replace(" ", ""))) {
|
||||
errMsg.add("字段 protectIp 包含非法值: " + s);
|
||||
ret = false;
|
||||
break;
|
||||
|
|
|
@ -39,7 +39,7 @@ public class ValidIpSegmentImpl implements ConstraintValidator<ValidIpSegment, S
|
|||
|
||||
for (String s : str.split(DisposeConfigValue.SPLIT_CHAR)) {
|
||||
|
||||
if (!Pattern.matches(ConstValue.IP_ADDR_SEGMENT_REG, s.replace(" ", ""))) {
|
||||
if (!Pattern.matches(ConstValue.ipAddrSegmentReg(), s.replace(" ", ""))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -512,7 +512,7 @@ public class demo {
|
|||
|
||||
String normalString = s.replace(" ", "");
|
||||
|
||||
if (!Pattern.matches(ConstValue.IP_ADDR_SEGMENT_REG, normalString)) {
|
||||
if (!Pattern.matches(ConstValue.ipAddrSegmentReg(), normalString)) {
|
||||
log.error("Step1: {} not match", normalString);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue