Search in sources :

Example 1 with EphemeralInput

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;
}
Also used : EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) AbsoluteExpiration(com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration) Expiration(com.zimbra.cs.ephemeral.EphemeralInput.Expiration) AbsoluteExpiration(com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration) EphemeralKey(com.zimbra.cs.ephemeral.EphemeralKey)

Example 2 with EphemeralInput

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());
}
Also used : Account(com.zimbra.cs.account.Account) EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) Provisioning(com.zimbra.cs.account.Provisioning) LinkedList(java.util.LinkedList) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) Test(org.junit.Test)

Example 3 with EphemeralInput

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);
}
Also used : MigrationTask(com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationTask) HashMap(java.util.HashMap) EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 4 with EphemeralInput

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);
}
Also used : MigrationTask(com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationTask) HashMap(java.util.HashMap) EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 5 with EphemeralInput

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");
}
Also used : EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) Test(org.junit.Test)

Aggregations

EphemeralInput (com.zimbra.cs.ephemeral.EphemeralInput)9 Test (org.junit.Test)6 LinkedList (java.util.LinkedList)5 AbsoluteExpiration (com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration)3 Expiration (com.zimbra.cs.ephemeral.EphemeralInput.Expiration)3 EphemeralKey (com.zimbra.cs.ephemeral.EphemeralKey)3 MigrationTask (com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationTask)3 HashMap (java.util.HashMap)3 EntrySource (com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource)2 ServiceException (com.zimbra.common.service.ServiceException)1 Account (com.zimbra.cs.account.Account)1 Provisioning (com.zimbra.cs.account.Provisioning)1 EphemeralLocation (com.zimbra.cs.ephemeral.EphemeralLocation)1 LdapEntryLocation (com.zimbra.cs.ephemeral.LdapEntryLocation)1