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:
Andy Stadler 2011-03-16 09:48:08 -07:00
parent 714b2f2da3
commit 22759bacd9
3 changed files with 41 additions and 2 deletions

View File

@ -222,7 +222,11 @@ public class PolicySet implements Parcelable {
case PASSWORD_MODE_SIMPLE: case PASSWORD_MODE_SIMPLE:
return DevicePolicyManager.PASSWORD_QUALITY_NUMERIC; return DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
case PASSWORD_MODE_STRONG: case PASSWORD_MODE_STRONG:
return DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC; if (mPasswordComplexChars == 0) {
return DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC;
} else {
return DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
}
default: default:
return DevicePolicyManager .PASSWORD_QUALITY_UNSPECIFIED; return DevicePolicyManager .PASSWORD_QUALITY_UNSPECIFIED;
} }

View File

@ -439,7 +439,13 @@ public class SecurityPolicy {
policies.getDPManagerPasswordExpirationTimeout()); policies.getDPManagerPasswordExpirationTimeout());
// password history length (number of previous passwords that may not be reused) // password history length (number of previous passwords that may not be reused)
dpm.setPasswordHistoryLength(mAdminName, policies.mPasswordHistory); 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); dpm.setPasswordMinimumNonLetter(mAdminName, policies.mPasswordComplexChars);
// encryption required // encryption required
dpm.setStorageEncryption(mAdminName, policies.mRequireEncryption); dpm.setStorageEncryption(mAdminName, policies.mRequireEncryption);

View File

@ -688,4 +688,33 @@ public class SecurityPolicyTests extends ProviderTestCase2<EmailProvider> {
assertEquals(policyExpect, p3Result); 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());
}
} }