feat:增加自动完成数据源
This commit is contained in:
parent
18f26cc8b7
commit
32cc830fdc
@ -16,4 +16,6 @@ public class FrameworkConfiguration {
|
||||
private boolean resultStyle = false;
|
||||
|
||||
private boolean debug = false;
|
||||
|
||||
private boolean shortPassword = false;
|
||||
}
|
||||
|
@ -16,6 +16,11 @@ public interface Frameworks {
|
||||
return config;
|
||||
}
|
||||
|
||||
static FrameworkConfiguration shortPassword() {
|
||||
config.setShortPassword(true);
|
||||
return config;
|
||||
}
|
||||
|
||||
static FrameworkConfiguration debug() {
|
||||
config.setDebug(true);
|
||||
return config;
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.flyfish.framework.validation.annotations;
|
||||
|
||||
import com.flyfish.framework.validation.annotations.Password.List;
|
||||
import com.flyfish.framework.validation.validators.IdCardValidator;
|
||||
import com.flyfish.framework.validation.validators.PasswordValidator;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Repeatable;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@Constraint(validatedBy = {PasswordValidator.class})
|
||||
@Repeatable(List.class)
|
||||
public @interface Password {
|
||||
|
||||
String message() default "密码强度不够,12-18位,至少应该包含数字、大小写字母、符号组合!";
|
||||
|
||||
//分组
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
//负载
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
|
||||
//指定多个时使用
|
||||
@Target({FIELD, METHOD, PARAMETER, ANNOTATION_TYPE})
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@interface List {
|
||||
Password[] value();
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.flyfish.framework.validation.validators;
|
||||
|
||||
import com.flyfish.framework.constant.Frameworks;
|
||||
import com.flyfish.framework.validation.annotations.Password;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 身份证验证,使用正则
|
||||
*
|
||||
* @author wangyu
|
||||
*/
|
||||
public class PasswordValidator implements ConstraintValidator<Password, String> {
|
||||
|
||||
public static final String PATTERN = "^(?![a-zA-z]+$)(?!\\d+$)(?![,.!?~`_+=@#$%^&*;<>':]+$)(?![a-zA-z\\d]+$)(?![a-zA-z,.!?~`_+=@#$%^&*;<>':]+$)(?![\\d,.!?~`_+=@#$%^&*;<>':]+$)[a-zA-Z\\d,.!?~`_+=@#$%^&*;<>':]{12,18}$";
|
||||
public static final String SHORT_PATTERN = "^(?![a-zA-z]+$)(?!\\d+$)(?![,.!?~`_+=@#$%^&*;<>':]+$)(?![a-zA-z\\d]+$)(?![a-zA-z,.!?~`_+=@#$%^&*;<>':]+$)(?![\\d,.!?~`_+=@#$%^&*;<>':]+$)[a-zA-Z\\d,.!?~`_+=@#$%^&*;<>':]{8,18}$";
|
||||
|
||||
/**
|
||||
* 此处传入密码明文判定密码可用性
|
||||
*
|
||||
* @param password 密码
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean isValid(String password) {
|
||||
if (Frameworks.config.isShortPassword()) {
|
||||
return LazyHolder.shortRegex.matcher(password).matches();
|
||||
}
|
||||
return LazyHolder.normalRegex.matcher(password).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the validation logic.
|
||||
* The state of {@code value} must not be altered.
|
||||
* <p>
|
||||
* This method can be accessed concurrently, thread-safety must be ensured
|
||||
* by the implementation.
|
||||
*
|
||||
* @param value object to validate
|
||||
* @param context context in which the constraint is evaluated
|
||||
* @return {@code false} if {@code value} does not pass the constraint
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext context) {
|
||||
return null == value || isValid(value);
|
||||
}
|
||||
|
||||
private static class LazyHolder {
|
||||
private static final Pattern normalRegex = Pattern.compile(PATTERN);
|
||||
private static final Pattern shortRegex = Pattern.compile(SHORT_PATTERN);
|
||||
}
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
package com.flyfish.framework.domain;
|
||||
|
||||
import com.flyfish.framework.utils.StrengthUtils;
|
||||
import com.flyfish.framework.validation.annotations.Password;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* 修改密码dto
|
||||
*
|
||||
* @author wangyu
|
||||
*/
|
||||
@Getter
|
||||
@ -19,6 +19,6 @@ public class UserPasswordDto {
|
||||
private String oldPassword;
|
||||
|
||||
@NotBlank(message = "新密码不可为空!")
|
||||
@Pattern(regexp = StrengthUtils.PATTERN, message = "密码强度不够,12-18位,至少应该包含数字、大小写字母、符号组合!")
|
||||
@Password
|
||||
private String password;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.flyfish.framework.utils;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import com.flyfish.framework.validation.validators.PasswordValidator;
|
||||
|
||||
/**
|
||||
* 密码强度工具
|
||||
@ -9,19 +9,10 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public abstract class StrengthUtils {
|
||||
|
||||
public static final String PATTERN = "^(?![a-zA-z]+$)(?!\\d+$)(?![,.!?~`_+=@#$%^&*;<>':]+$)(?![a-zA-z\\d]+$)(?![a-zA-z,.!?~`_+=@#$%^&*;<>':]+$)(?![\\d,.!?~`_+=@#$%^&*;<>':]+$)[a-zA-Z\\d,.!?~`_+=@#$%^&*;<>':]{12,18}$";
|
||||
public static final String PATTERN = PasswordValidator.PATTERN;
|
||||
public static final String SHORT_PATTERN = PasswordValidator.SHORT_PATTERN;
|
||||
|
||||
/**
|
||||
* 此处传入密码明文判定密码可用性
|
||||
*
|
||||
* @param password 密码
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean isValid(String password) {
|
||||
return LazyHolder.validRegex.matcher(password).matches();
|
||||
}
|
||||
|
||||
private static class LazyHolder {
|
||||
private static final Pattern validRegex = Pattern.compile(PATTERN);
|
||||
return PasswordValidator.isValid(password);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user