use of com.zimbra.cs.ephemeral.EphemeralInput in project zm-mailbox by Zimbra.
the class CsrfTokenConverter method convert.
@Override
public EphemeralInput convert(String attrName, Object ldapValue) {
String ldapValueStr = (String) ldapValue;
String[] parts = ldapValueStr.split(":");
if (parts.length != 3) {
ZimbraLog.ephemeral.warn("CSRF auth token %s cannot be parsed", ldapValueStr);
return null;
}
String data = parts[0];
String crumb = parts[1];
Long expirationMillis;
try {
expirationMillis = Long.parseLong(parts[2]);
} catch (NumberFormatException e) {
ZimbraLog.ephemeral.warn("CSRF auth token %s does not have a valid expiration value", ldapValueStr);
return null;
}
EphemeralKey key = new EphemeralKey(attrName, crumb);
EphemeralInput input = new EphemeralInput(key, data);
Expiration expiration = new AbsoluteExpiration(expirationMillis);
input.setExpiration(expiration);
return input;
}
use of com.zimbra.cs.ephemeral.EphemeralInput in project zm-mailbox by Zimbra.
the class MigrateAttributesTest method testMigrateAlreadyMigratedAccount.
@Test
public void testMigrateAlreadyMigratedAccount() throws Exception {
Provisioning prov = Provisioning.getInstance();
// create a new account that will not have any data to migrate
Account acct = prov.createAccount("user2", "test123", new HashMap<String, Object>());
EntrySource source = new DummyEntrySource(acct);
Multimap<String, Object> deletedAttrs = LinkedListMultimap.create();
List<EphemeralInput> results = new LinkedList<EphemeralInput>();
List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
DummyMigrationCallback callback = new DummyMigrationCallback(results);
callback.throwErrorDuringMigration = false;
AttributeMigration.setCallback(callback);
AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
migration.migrateAllAccounts();
assertTrue(results.isEmpty());
}
use of com.zimbra.cs.ephemeral.EphemeralInput in project zm-mailbox by Zimbra.
the class MigrateAttributesTest method testCsrfTokenMigrationTask.
/*
* Test MigrationTask for CSRF tokens
*/
@Test
public void testCsrfTokenMigrationTask() throws ServiceException {
List<EphemeralInput> results = new LinkedList<EphemeralInput>();
Map<String, AttributeConverter> converters = new HashMap<String, AttributeConverter>();
converters.put(Provisioning.A_zimbraCsrfTokenData, new CsrfTokenConverter());
MigrationTask task = new MigrationTask(acct, converters, new DummyMigrationCallback(results));
task.migrateAttributes();
assertEquals(2, results.size());
verifyCsrfTokenEphemeralInput(results.get(0), "crumb1", "data1", 100000L);
verifyCsrfTokenEphemeralInput(results.get(1), "crumb2", "data2", 100000L);
}
use of com.zimbra.cs.ephemeral.EphemeralInput in project zm-mailbox by Zimbra.
the class MigrateAttributesTest method testAuthTokenMigrationTask.
/*
* Test MigrationTask for auth tokens
*/
@Test
public void testAuthTokenMigrationTask() throws ServiceException {
List<EphemeralInput> results = new LinkedList<EphemeralInput>();
Map<String, AttributeConverter> converters = new HashMap<String, AttributeConverter>();
converters.put(Provisioning.A_zimbraAuthTokens, new AuthTokenConverter());
MigrationTask task = new MigrationTask(acct, converters, new DummyMigrationCallback(results));
task.migrateAttributes();
assertEquals(2, results.size());
verifyAuthTokenEphemeralInput(results.get(0), "1234", "server_1", 100000L);
verifyAuthTokenEphemeralInput(results.get(1), "5678", "server_2", 100000L);
}
use of com.zimbra.cs.ephemeral.EphemeralInput in project zm-mailbox by Zimbra.
the class MigrateAttributesTest method testConverters.
/*
* Test the individual converters
*/
@Test
public void testConverters() {
EphemeralInput input = runConverter(Provisioning.A_zimbraAuthTokens, new AuthTokenConverter());
verifyAuthTokenEphemeralInput(input, "1234", "server_1", 100000L);
input = runConverter(Provisioning.A_zimbraCsrfTokenData, new CsrfTokenConverter());
verifyCsrfTokenEphemeralInput(input, "crumb1", "data1", 100000L);
input = runConverter(Provisioning.A_zimbraLastLogonTimestamp, new StringAttributeConverter());
verifyLastLogonTimestampEphemeralInput(input, "currentdate");
}
Aggregations