Handle complex chars policy correctly
* We needed to set DevicePolicyMnager.PASSWORD_QUALITY_COMPLEX * Setting this, we also need to clear some of the defaults for complex mode that are not correct for Exchange's definition of "complex". * Unit tests Bug: 4092218 Change-Id: Iea7bd05d48f1aa9406222c1db5937cfd7f2662b8
This commit is contained in:
parent
714b2f2da3
commit
22759bacd9
@ -222,7 +222,11 @@ public class PolicySet implements Parcelable {
|
||||
case PASSWORD_MODE_SIMPLE:
|
||||
return DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
|
||||
case PASSWORD_MODE_STRONG:
|
||||
if (mPasswordComplexChars == 0) {
|
||||
return DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC;
|
||||
} else {
|
||||
return DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
|
||||
}
|
||||
default:
|
||||
return DevicePolicyManager .PASSWORD_QUALITY_UNSPECIFIED;
|
||||
}
|
||||
|
@ -439,7 +439,13 @@ public class SecurityPolicy {
|
||||
policies.getDPManagerPasswordExpirationTimeout());
|
||||
// password history length (number of previous passwords that may not be reused)
|
||||
dpm.setPasswordHistoryLength(mAdminName, policies.mPasswordHistory);
|
||||
// password minimum complex characters
|
||||
// password minimum complex characters.
|
||||
// Note, in Exchange, "complex chars" simply means "non alpha", but in the DPM,
|
||||
// setting the quality to complex also defaults min symbols=1 and min numeric=1.
|
||||
// We always / safely clear minSymbols & minNumeric to zero (there is no policy
|
||||
// configuration in which we explicitly require a minimum number of digits or symbols.)
|
||||
dpm.setPasswordMinimumSymbols(mAdminName, 0);
|
||||
dpm.setPasswordMinimumNumeric(mAdminName, 0);
|
||||
dpm.setPasswordMinimumNonLetter(mAdminName, policies.mPasswordComplexChars);
|
||||
// encryption required
|
||||
dpm.setStorageEncryption(mAdminName, policies.mRequireEncryption);
|
||||
|
@ -688,4 +688,33 @@ public class SecurityPolicyTests extends ProviderTestCase2<EmailProvider> {
|
||||
assertEquals(policyExpect, p3Result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the code that converts from exchange-style quality to DPM/Lockscreen style quality.
|
||||
*/
|
||||
public void testGetDPManagerPasswordQuality() {
|
||||
// PolicySet.PASSWORD_MODE_NONE -> DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED
|
||||
PolicySet p1 = new PolicySet(0, PolicySet.PASSWORD_MODE_NONE,
|
||||
0, 0, false, 0, 0, 0, false, false);
|
||||
assertEquals(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
|
||||
p1.getDPManagerPasswordQuality());
|
||||
|
||||
// PASSWORD_MODE_SIMPLE -> PASSWORD_QUALITY_NUMERIC
|
||||
PolicySet p2 = new PolicySet(4, PolicySet.PASSWORD_MODE_SIMPLE,
|
||||
0, 0, false, 0, 0, 0, false, false);
|
||||
assertEquals(DevicePolicyManager.PASSWORD_QUALITY_NUMERIC,
|
||||
p2.getDPManagerPasswordQuality());
|
||||
|
||||
// PASSWORD_MODE_STRONG -> PASSWORD_QUALITY_ALPHANUMERIC
|
||||
PolicySet p3 = new PolicySet(4, PolicySet.PASSWORD_MODE_STRONG,
|
||||
0, 0, false, 0, 0, 0, false, false);
|
||||
assertEquals(DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC,
|
||||
p3.getDPManagerPasswordQuality());
|
||||
|
||||
// PASSWORD_MODE_STRONG + complex chars -> PASSWORD_QUALITY_COMPLEX
|
||||
PolicySet p4 = new PolicySet(4, PolicySet.PASSWORD_MODE_STRONG,
|
||||
0, 0, false, 0, 0 , 2, false, false);
|
||||
assertEquals(DevicePolicyManager.PASSWORD_QUALITY_COMPLEX,
|
||||
p4.getDPManagerPasswordQuality());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user