本文整理汇总了Java中org.passay.CharacterRule类的典型用法代码示例。如果您正苦于以下问题:Java CharacterRule类的具体用法?Java CharacterRule怎么用?Java CharacterRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CharacterRule类属于org.passay包,在下文中一共展示了CharacterRule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCharacterRules
import org.passay.CharacterRule; //导入依赖的package包/类
public static List<CharacterRule> getCharacterRules(StringGenerationParameters parameters) {
List<CharacterRule> characterRules = new ArrayList<>();
if (parameters.isIncludeSpecial()) {
characterRules.add(new CharacterRule(CredHubCharacterData.Special));
}
if (!parameters.isExcludeNumber()) {
characterRules.add(new CharacterRule(EnglishCharacterData.Digit));
}
if (!parameters.isExcludeUpper()) {
characterRules.add(new CharacterRule(EnglishCharacterData.UpperCase));
}
if (!parameters.isExcludeLower()) {
characterRules.add(new CharacterRule(EnglishCharacterData.LowerCase));
}
return characterRules;
}
示例2: generatePassword
import org.passay.CharacterRule; //导入依赖的package包/类
public void generatePassword() {
char[] special = new char[]{'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*',
'+', '-', '.', '/', ':', '<', '=', '>', '?', '@', '[', '\\', ']',
'^', '_', '`', '{', '|', '}', '~'};
List<CharacterRule> rules = Arrays.asList(
// at least one upper-case character
new CharacterRule(EnglishCharacterData.UpperCase, 1),
// at least one lower-case character
new CharacterRule(EnglishCharacterData.LowerCase, 1),
// at least one digit character
new CharacterRule(EnglishCharacterData.Digit, 1),
new CharacterRule(new CharacterData() {
@Override
public String getErrorCode() {
return "INSUFFICIENT_SPECIAL";
}
@Override
public String getCharacters() {
return new String(special);
}
}, 1));
PasswordGenerator generator = new PasswordGenerator();
// Generated password is 16 characters long, which complies with policy
String password = generator.generatePassword(16, rules);
this.password = password.toCharArray();
}
示例3: generateEncryptionPassword
import org.passay.CharacterRule; //导入依赖的package包/类
public void generateEncryptionPassword() {
char[] special = new char[]{'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*',
'+', ',', '-', '.', '/', ':', '<', '=', '>', '?', '@', '[', '\\', ']',
'^', '_', '`', '{', '|', '}', '~'};
List<CharacterRule> rules = Arrays.asList(
// at least one upper-case character
new CharacterRule(EnglishCharacterData.UpperCase, 1),
// at least one lower-case character
new CharacterRule(EnglishCharacterData.LowerCase, 1),
// at least one digit character
new CharacterRule(EnglishCharacterData.Digit, 1),
new CharacterRule(new CharacterData() {
@Override
public String getErrorCode() {
return "INSUFFICIENT_SPECIAL";
}
@Override
public String getCharacters() {
return new String(special);
}
}, 1));
PasswordGenerator generator = new PasswordGenerator();
// Generated password is 16 characters long, which complies with policy
String password = generator.generatePassword(16, rules);
this.encryptionPassword = password.toCharArray();
}
示例4: getCharacterRules_canCreateCharacterRulesWithoutUppercase
import org.passay.CharacterRule; //导入依赖的package包/类
@Test
public void getCharacterRules_canCreateCharacterRulesWithoutUppercase() {
StringGenerationParameters generationParameters = new StringGenerationParameters();
generationParameters.setExcludeUpper(true);
List<CharacterRule> characterRules = CharacterRuleProvider
.getCharacterRules(generationParameters);
assertThat(characterRules, iterableWithSize(2));
assertThat(characterRules, containsInAnyOrder(
usesCharacters(EnglishCharacterData.LowerCase),
usesCharacters(EnglishCharacterData.Digit)
));
assertThat(characterRules, not(containsInAnyOrder(
usesCharacters(EnglishCharacterData.UpperCase),
usesCharacters(CredHubCharacterData.Special),
usesCharacters(CredHubCharacterData.Hex)
)));
}
示例5: getCharacterRules_canCreateCharacterRulesWithoutLowercase
import org.passay.CharacterRule; //导入依赖的package包/类
@Test
public void getCharacterRules_canCreateCharacterRulesWithoutLowercase() {
StringGenerationParameters generationParameters = new StringGenerationParameters();
generationParameters.setExcludeLower(true);
List<CharacterRule> characterRules = CharacterRuleProvider
.getCharacterRules(generationParameters);
assertThat(characterRules, iterableWithSize(2));
assertThat(characterRules, containsInAnyOrder(
usesCharacters(EnglishCharacterData.UpperCase),
usesCharacters(EnglishCharacterData.Digit)
));
assertThat(characterRules, not(containsInAnyOrder(
usesCharacters(EnglishCharacterData.LowerCase),
usesCharacters(CredHubCharacterData.Special),
usesCharacters(CredHubCharacterData.Hex)
)));
}
示例6: getCharacterRules_canCreateCharacterRulesWithoutSpecialCharacters
import org.passay.CharacterRule; //导入依赖的package包/类
@Test
public void getCharacterRules_canCreateCharacterRulesWithoutSpecialCharacters() {
StringGenerationParameters generationParameters = new StringGenerationParameters();
generationParameters.setIncludeSpecial(false);
List<CharacterRule> characterRules = CharacterRuleProvider
.getCharacterRules(generationParameters);
assertThat(characterRules, iterableWithSize(3));
assertThat(characterRules, containsInAnyOrder(
usesCharacters(EnglishCharacterData.UpperCase),
usesCharacters(EnglishCharacterData.LowerCase),
usesCharacters(EnglishCharacterData.Digit)
));
assertThat(characterRules, not(hasItem(usesCharacters(CredHubCharacterData.Special))));
assertThat(characterRules, not(hasItem(usesCharacters(CredHubCharacterData.Hex))));
}
示例7: getCharacterRules_canCreateCharacterRulesWithoutNumbers
import org.passay.CharacterRule; //导入依赖的package包/类
@Test
public void getCharacterRules_canCreateCharacterRulesWithoutNumbers() {
StringGenerationParameters generationParameters = new StringGenerationParameters();
generationParameters.setExcludeNumber(true);
List<CharacterRule> characterRules = CharacterRuleProvider
.getCharacterRules(generationParameters);
assertThat(characterRules, iterableWithSize(2));
assertThat(characterRules, containsInAnyOrder(
usesCharacters(EnglishCharacterData.UpperCase),
usesCharacters(EnglishCharacterData.LowerCase)
));
assertThat(characterRules, not(containsInAnyOrder(
usesCharacters(EnglishCharacterData.Digit),
usesCharacters(CredHubCharacterData.Special)
)));
}
示例8: usesCharacters
import org.passay.CharacterRule; //导入依赖的package包/类
private Matcher<CharacterRule> usesCharacters(CharacterData characterData) {
return new BaseMatcher<CharacterRule>() {
@Override
public boolean matches(final Object item) {
final CharacterRule rule = (CharacterRule) item;
return rule.getValidCharacters().equals(characterData.getCharacters());
}
@Override
public void describeTo(final Description description) {
description.appendText("getValidCharacters() should equal")
.appendValue(characterData.getCharacters());
}
};
}
示例9: generateCredential
import org.passay.CharacterRule; //导入依赖的package包/类
public StringCredentialValue generateCredential(StringGenerationParameters parameters) {
int passwordLength = normalizedLength(parameters.getLength());
List<CharacterRule> characterRules = CharacterRuleProvider.getCharacterRules(parameters);
return new StringCredentialValue(
passwordGenerator.generatePassword(passwordLength, characterRules));
}
示例10: getCharacterRules_createdCharacterRulesFromDefaultParameters
import org.passay.CharacterRule; //导入依赖的package包/类
@Test
public void getCharacterRules_createdCharacterRulesFromDefaultParameters() {
StringGenerationParameters generationParameters = new StringGenerationParameters();
List<CharacterRule> characterRules = CharacterRuleProvider
.getCharacterRules(generationParameters);
assertThat(characterRules, containsInAnyOrder(
usesCharacters(EnglishCharacterData.Digit),
usesCharacters(EnglishCharacterData.LowerCase),
usesCharacters(EnglishCharacterData.UpperCase)
));
assertThat(characterRules, not(hasItem(usesCharacters(CredHubCharacterData.Hex))));
}
示例11: getCharacterRules_canCreateCharacterRulesWithAllIncluded
import org.passay.CharacterRule; //导入依赖的package包/类
@Test
public void getCharacterRules_canCreateCharacterRulesWithAllIncluded() {
StringGenerationParameters generationParameters = new StringGenerationParameters();
generationParameters.setIncludeSpecial(true);
List<CharacterRule> characterRules = CharacterRuleProvider
.getCharacterRules(generationParameters);
assertThat(characterRules, iterableWithSize(4));
assertThat(characterRules, containsInAnyOrder(
usesCharacters(EnglishCharacterData.UpperCase),
usesCharacters(EnglishCharacterData.LowerCase),
usesCharacters(EnglishCharacterData.Digit),
usesCharacters(CredHubCharacterData.Special)
));
}
示例12: getCharacterRules_returnsAnEmptyListWhenAllAreExcluded
import org.passay.CharacterRule; //导入依赖的package包/类
@Test
public void getCharacterRules_returnsAnEmptyListWhenAllAreExcluded() {
StringGenerationParameters generationParameters = new StringGenerationParameters();
generationParameters.setIncludeSpecial(false);
generationParameters.setExcludeNumber(true);
generationParameters.setExcludeUpper(true);
generationParameters.setExcludeLower(true);
List<CharacterRule> characterRules = CharacterRuleProvider
.getCharacterRules(generationParameters);
assertThat(characterRules, iterableWithSize(0));
}
示例13: generatePassword
import org.passay.CharacterRule; //导入依赖的package包/类
private String generatePassword() {
PasswordGenerator passwordGenerator = new PasswordGenerator();
List<CharacterRule> rules = Arrays.asList(
// at least one upper-case character
new CharacterRule(EnglishCharacterData.UpperCase, 1),
// at least one lower-case character
new CharacterRule(EnglishCharacterData.LowerCase, 1),
// at least one digit character
new CharacterRule(EnglishCharacterData.Digit, 1),
// at least one symbol (special character)
new CharacterRule(SpecialCharacterData.INSTANCE, 1));
return passwordGenerator.generatePassword(8, rules);
}
示例14: mandatoryDigits
import org.passay.CharacterRule; //导入依赖的package包/类
public SecurityPasswordRulesBuilder mandatoryDigits(int min) {
rules.add(new CharacterRule(EnglishCharacterData.Digit, min));
return this;
}
示例15: mandatoryNonAlphanumericCharacters
import org.passay.CharacterRule; //导入依赖的package包/类
public SecurityPasswordRulesBuilder mandatoryNonAlphanumericCharacters() {
rules.add(new CharacterRule(EnglishCharacterData.Special));
return this;
}