String pFile = "./__TestOfSRPAuthInfoProvider";
Map context = new HashMap();
context.put(SRPRegistry.PASSWORD_FILE, pFile);
IAuthInfoProvider authenticator = new SRPAuthInfoProvider();
try
{
authenticator.activate(context);
harness.check(true, "activate()");
}
catch (AuthenticationException x)
{
harness.debug(x);
harness.fail("activate()");
}
byte[] salt = new byte[10];
Map user1 = new HashMap();
user1.put(Registry.SASL_USERNAME, "user1");
user1.put(Registry.SASL_PASSWORD, "password1");
user1.put(SRPRegistry.CONFIG_NDX_FIELD, "1");
prng.nextBytes(salt);
user1.put(SRPRegistry.SALT_FIELD, Util.toBase64(salt));
user1.put(SRPRegistry.MD_NAME_FIELD, Registry.MD5_HASH);
Map user2 = new HashMap();
user2.put(Registry.SASL_USERNAME, "user2");
user2.put(Registry.SASL_PASSWORD, "password2");
user2.put(SRPRegistry.CONFIG_NDX_FIELD, "2");
prng.nextBytes(salt);
user2.put(SRPRegistry.SALT_FIELD, Util.toBase64(salt));
user2.put(SRPRegistry.MD_NAME_FIELD, Registry.SHA1_HASH);
Map user3 = new HashMap();
user3.put(Registry.SASL_USERNAME, "user3");
user3.put(Registry.SASL_PASSWORD, "password3");
user3.put(SRPRegistry.CONFIG_NDX_FIELD, "3");
prng.nextBytes(salt);
user3.put(SRPRegistry.SALT_FIELD, Util.toBase64(salt));
user3.put(SRPRegistry.MD_NAME_FIELD, Registry.MD5_HASH);
Map user4 = new HashMap();
user4.put(Registry.SASL_USERNAME, "user4");
user4.put(Registry.SASL_PASSWORD, "password4");
user4.put(SRPRegistry.CONFIG_NDX_FIELD, "4");
prng.nextBytes(salt);
user4.put(SRPRegistry.SALT_FIELD, Util.toBase64(salt));
user4.put(SRPRegistry.MD_NAME_FIELD, Registry.SHA_HASH);
Map credentials;
try
{
credentials = authenticator.lookup(user1);
harness.fail("lookup(user1)");
}
catch (AuthenticationException x)
{
harness.check(true, "lookup(user1)");
}
try
{
credentials = authenticator.lookup(user2);
harness.fail("lookup(user2)");
}
catch (AuthenticationException x)
{
harness.check(true, "lookup(user2)");
}
try
{
credentials = authenticator.lookup(user3);
harness.fail("lookup(user3)");
}
catch (AuthenticationException x)
{
harness.check(true, "lookup(user3)");
}
try
{
credentials = authenticator.lookup(user4);
harness.fail("lookup(user4)");
}
catch (AuthenticationException x)
{
harness.check(true, "lookup(user4)");
}
// ----------------------------------------------------------------------
try
{
authenticator.update(user1);
harness.check(true, "update(user1)");
}
catch (AuthenticationException x)
{
harness.debug(x);
harness.fail("update(user1)");
}
try
{
authenticator.update(user2);
harness.check(true, "update(user2)");
}
catch (AuthenticationException x)
{
harness.debug(x);
harness.fail("update(user2)");
}
try
{
authenticator.update(user3);
harness.check(true, "update(user3)");
}
catch (AuthenticationException x)
{
harness.debug(x);
harness.fail("update(user3)");
}
// ----------------------------------------------------------------------
String saltString;
try
{
credentials = authenticator.lookup(user1);
saltString = (String) credentials.get(SRPRegistry.SALT_FIELD);
harness.check(saltString.equals(user1.get(SRPRegistry.SALT_FIELD)),
"user1 OK");
}
catch (AuthenticationException x)
{
harness.fail("update(user1)");
}
try
{
credentials = authenticator.lookup(user2);
saltString = (String) credentials.get(SRPRegistry.SALT_FIELD);
harness.check(saltString.equals(user2.get(SRPRegistry.SALT_FIELD)),
"user2 OK");
}
catch (AuthenticationException x)
{
harness.fail("update(user2)");
}
try
{
credentials = authenticator.lookup(user3);
saltString = (String) credentials.get(SRPRegistry.SALT_FIELD);
harness.check(saltString.equals(user3.get(SRPRegistry.SALT_FIELD)),
"user3 OK");
}
catch (AuthenticationException x)
{
harness.fail("update(user3)");
}
// ----------------------------------------------------------------------
try
{
authenticator.update(user4);
harness.check(true, "update(user4)");
}
catch (AuthenticationException x)
{
harness.debug(x);
harness.fail("update(user4)");
}
// ----------------------------------------------------------------------
try
{
authenticator.passivate();
harness.check(true, "passivate()");
}
catch (AuthenticationException x)
{
harness.debug(x);
harness.fail("passivate()");
}
try
{
authenticator.activate(context);
harness.check(true, "activate()");
}
catch (AuthenticationException x)
{
harness.debug(x);
harness.fail("activate()");
}
try
{
credentials = authenticator.lookup(user4);
saltString = (String) credentials.get(SRPRegistry.SALT_FIELD);
harness.check(saltString.equals(user4.get(SRPRegistry.SALT_FIELD)));
}
catch (AuthenticationException x)
{