/
PasswordPolicy.java
144 lines (119 loc) · 5.05 KB
/
PasswordPolicy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package org.cloudfoundry.identity.uaa.config;
/**
* ****************************************************************************
* Cloud Foundry
* Copyright (c) [2009-2015] Pivotal Software, Inc. All Rights Reserved.
* <p>
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
* <p>
* This product includes a number of subcomponents with
* separate copyright notices and license terms. Your use of these
* subcomponents is subject to the terms and conditions of the
* subcomponent's license, as noted in the LICENSE file.
* *****************************************************************************
*/
public class PasswordPolicy {
public static final String PASSWORD_POLICY_FIELD = "passwordPolicy";
private int minLength;
private int maxLength;
private int requireUpperCaseCharacter;
private int requireLowerCaseCharacter;
private int requireDigit;
private int requireSpecialCharacter;
private int expirePasswordInMonths;
public PasswordPolicy() {
minLength = maxLength = requireUpperCaseCharacter = requireLowerCaseCharacter = requireDigit = requireSpecialCharacter = expirePasswordInMonths = -1;
}
public PasswordPolicy(int minLength,
int maxLength,
int requireUpperCaseCharacter,
int requireLowerCaseCharacter,
int requireDigit,
int requireSpecialCharacter,
int expirePasswordsInMonths) {
this.minLength = minLength;
this.maxLength = maxLength;
this.requireUpperCaseCharacter = requireUpperCaseCharacter;
this.requireLowerCaseCharacter = requireLowerCaseCharacter;
this.requireDigit = requireDigit;
this.requireSpecialCharacter = requireSpecialCharacter;
this.expirePasswordInMonths = expirePasswordsInMonths;
}
public int getMinLength() {
return minLength;
}
public int getMaxLength() {
return maxLength;
}
public int getRequireUpperCaseCharacter() {
return requireUpperCaseCharacter;
}
public int getRequireLowerCaseCharacter() {
return requireLowerCaseCharacter;
}
public int getRequireDigit() {
return requireDigit;
}
public PasswordPolicy setMaxLength(int maxLength) {
this.maxLength = maxLength;
return this;
}
public PasswordPolicy setMinLength(int minLength) {
this.minLength = minLength;
return this;
}
public PasswordPolicy setRequireDigit(int requireDigit) {
this.requireDigit = requireDigit;
return this;
}
public PasswordPolicy setRequireLowerCaseCharacter(int requireLowerCaseCharacter) {
this.requireLowerCaseCharacter = requireLowerCaseCharacter;
return this;
}
public PasswordPolicy setRequireUpperCaseCharacter(int requireUpperCaseCharacter) {
this.requireUpperCaseCharacter = requireUpperCaseCharacter;
return this;
}
public int getRequireSpecialCharacter() {
return requireSpecialCharacter;
}
public PasswordPolicy setRequireSpecialCharacter(int requireSpecialCharacter) {
this.requireSpecialCharacter = requireSpecialCharacter;
return this;
}
public int getExpirePasswordInMonths() {
return expirePasswordInMonths;
}
public PasswordPolicy setExpirePasswordInMonths(int expirePasswordInMonths) {
this.expirePasswordInMonths = expirePasswordInMonths;
return this;
}
public boolean allPresentAndPositive() {
return minLength >= 0 && maxLength >= 0 && requireUpperCaseCharacter >= 0 && requireLowerCaseCharacter >= 0 && requireDigit >= 0 && requireSpecialCharacter >= 0 && expirePasswordInMonths >= 0;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PasswordPolicy that = (PasswordPolicy) o;
if (getMinLength() != that.getMinLength()) return false;
if (getMaxLength() != that.getMaxLength()) return false;
if (getRequireUpperCaseCharacter() != that.getRequireUpperCaseCharacter()) return false;
if (getRequireLowerCaseCharacter() != that.getRequireLowerCaseCharacter()) return false;
if (getRequireDigit() != that.getRequireDigit()) return false;
if (getRequireSpecialCharacter() != that.getRequireSpecialCharacter()) return false;
return getExpirePasswordInMonths() == that.getExpirePasswordInMonths();
}
@Override
public int hashCode() {
int result = getMinLength();
result = 31 * result + getMaxLength();
result = 31 * result + getRequireUpperCaseCharacter();
result = 31 * result + getRequireLowerCaseCharacter();
result = 31 * result + getRequireDigit();
result = 31 * result + getRequireSpecialCharacter();
result = 31 * result + getExpirePasswordInMonths();
return result;
}
}