Skip to content

Commit fc2f300

Browse files
committed
issue #701 - random pw generator not honoring min length policy value - fix for v2_0 branch
1 parent 5f92738 commit fc2f300

File tree

11 files changed

+427
-131
lines changed

11 files changed

+427
-131
lines changed

build/checkstyle-import.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<allow pkg="org.apache.log4j"/>
5959

6060
<!-- testing -->
61+
<allow pkg="org.assertj.core.api"/>
6162
<allow pkg="org.junit"/>
6263
<allow pkg="org.mockito"/>
6364
<allow pkg="com.github.tomakehurst.wiremock"/>

server/src/main/java/password/pwm/AppProperty.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ public enum AppProperty
279279
PASSWORD_RANDOMGEN_MAX_ATTEMPTS ( "password.randomGenerator.maxAttempts" ),
280280
PASSWORD_RANDOMGEN_MAX_LENGTH ( "password.randomGenerator.maxLength" ),
281281
PASSWORD_RANDOMGEN_JITTER_COUNT ( "password.randomGenerator.jitter.count" ),
282+
PASSWORD_RANDOMGEN_MIN_LENGTH ( "password.randomGenerator.minLength" ),
283+
PASSWORD_RANDOMGEN_DEFAULT_STRENGTH ( "password.randomGenerator.defaultStrength" ),
282284

283285
/* Strength thresholds, introduced by the addition of the zxcvbn strength meter library (since it has 5 levels) */
284286
PASSWORD_STRENGTH_THRESHOLD_VERY_STRONG ( "password.strength.threshold.veryStrong" ),

server/src/main/java/password/pwm/config/profile/PwmPasswordPolicy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.Locale;
4646
import java.util.Map;
4747
import java.util.Set;
48+
import java.util.TreeMap;
4849
import java.util.TreeSet;
4950
import java.util.regex.Pattern;
5051

@@ -133,7 +134,7 @@ private PwmPasswordPolicy(
133134
final PolicyMetaData policyMetaData
134135
)
135136
{
136-
final Map<String, String> effectivePolicyMap = new HashMap<>();
137+
final Map<String, String> effectivePolicyMap = new TreeMap<>();
137138
if ( policyMap != null )
138139
{
139140
effectivePolicyMap.putAll( policyMap );

server/src/main/java/password/pwm/http/servlet/helpdesk/HelpdeskServlet.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,12 +1333,10 @@ private ProcessStatus processRandomPasswordAction( final PwmRequest pwmRequest )
13331333
chaiUser.getChaiProvider()
13341334
);
13351335

1336-
final RandomPasswordGenerator.RandomGeneratorConfig.RandomGeneratorConfigBuilder randomConfigBuilder
1337-
= RandomPasswordGenerator.RandomGeneratorConfig.builder();
1336+
final RandomPasswordGenerator.RandomGeneratorConfig randomConfig = RandomPasswordGenerator.RandomGeneratorConfig.fromPolicy(
1337+
pwmRequest.getConfig(),
1338+
userInfo.getPasswordPolicy() );
13381339

1339-
randomConfigBuilder.passwordPolicy( userInfo.getPasswordPolicy() );
1340-
1341-
final RandomPasswordGenerator.RandomGeneratorConfig randomConfig = randomConfigBuilder.build();
13421340
final PasswordData randomPassword = RandomPasswordGenerator.createRandomPassword( pwmRequest.getLabel(), randomConfig, pwmRequest.getPwmApplication() );
13431341
final RestRandomPasswordServer.JsonOutput jsonOutput = new RestRandomPasswordServer.JsonOutput();
13441342
jsonOutput.setPassword( randomPassword.getStringValue() );

server/src/main/java/password/pwm/http/servlet/newuser/NewUserUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,10 @@ static void createUser(
208208
NewUserUtils.LOGGER.trace( pwmRequest, () -> "will use temporary password process for new user entry: " + newUserDN );
209209
final PasswordData temporaryPassword;
210210
{
211-
final RandomPasswordGenerator.RandomGeneratorConfig randomGeneratorConfig = RandomPasswordGenerator.RandomGeneratorConfig.builder()
212-
.passwordPolicy( newUserProfile.getNewUserPasswordPolicy( pwmApplication, pwmRequest.getLocale() ) )
213-
.build();
211+
final RandomPasswordGenerator.RandomGeneratorConfig randomGeneratorConfig = RandomPasswordGenerator.RandomGeneratorConfig.fromPolicy(
212+
pwmApplication.getConfig(),
213+
newUserProfile.getNewUserPasswordPolicy( pwmApplication, pwmRequest.getLocale() ) );
214+
214215
temporaryPassword = RandomPasswordGenerator.createRandomPassword( pwmRequest.getLabel(), randomGeneratorConfig, pwmApplication );
215216
}
216217
final ChaiUser proxiedUser = chaiProvider.getEntryFactory().newChaiUser( newUserDN );

server/src/main/java/password/pwm/ldap/LdapDebugDataGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ private static LdapDebugDataGenerator.LdapDebugServerInfo makeLdapDebugServerInf
120120
final LdapDebugServerInfo.LdapDebugServerInfoBuilder builder = LdapDebugServerInfo.builder();
121121

122122
builder.ldapServerlUrl( chaiConfiguration.getSetting( ChaiSetting.BIND_URLS ) );
123+
builder.vendorName( chaiProvider.getDirectoryVendor().name() );
124+
123125
final ChaiProvider loopProvider = chaiProvider.getProviderFactory().newProvider( chaiConfiguration );
124126

125127
{
@@ -188,6 +190,7 @@ public static class LdapDebugInfo implements Serializable
188190
public static class LdapDebugServerInfo implements Serializable
189191
{
190192
private String ldapServerlUrl;
193+
private String vendorName;
191194
private String testUserDN;
192195
private Map<String, List<String>> testUserAttributes;
193196
private String proxyDN;

server/src/main/java/password/pwm/ldap/auth/LDAPAuthenticationRequest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,9 @@ private PasswordData setTempUserPassword(
497497
);
498498

499499
// create random password for user
500-
final RandomPasswordGenerator.RandomGeneratorConfig randomGeneratorConfig = RandomPasswordGenerator.RandomGeneratorConfig.builder()
501-
.seedlistPhrases( RandomPasswordGenerator.DEFAULT_SEED_PHRASES )
502-
.passwordPolicy( passwordPolicy )
503-
.build();
500+
final RandomPasswordGenerator.RandomGeneratorConfig randomGeneratorConfig = RandomPasswordGenerator.RandomGeneratorConfig.fromPolicy(
501+
pwmApplication.getConfig(),
502+
passwordPolicy );
504503

505504
final PasswordData currentPass = RandomPasswordGenerator.createRandomPassword( sessionLabel, randomGeneratorConfig, pwmApplication );
506505

0 commit comments

Comments
 (0)