Search in sources :

Example 1 with EphemeralKey

use of com.zimbra.cs.ephemeral.EphemeralKey in project zm-mailbox by Zimbra.

the class Entry method purgeEphemeralAttr.

public void purgeEphemeralAttr(String key) throws ServiceException {
    EphemeralLocation location = new LdapEntryLocation(this);
    EphemeralStore store = EphemeralStore.getFactory().getStore();
    store.purgeExpired(new EphemeralKey(key), location);
}
Also used : LdapEntryLocation(com.zimbra.cs.ephemeral.LdapEntryLocation) EphemeralLocation(com.zimbra.cs.ephemeral.EphemeralLocation) LdapEphemeralStore(com.zimbra.cs.ephemeral.LdapEphemeralStore) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) EphemeralKey(com.zimbra.cs.ephemeral.EphemeralKey)

Example 2 with EphemeralKey

use of com.zimbra.cs.ephemeral.EphemeralKey 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 3 with EphemeralKey

use of com.zimbra.cs.ephemeral.EphemeralKey in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method testAttributeMigration.

/*
     * Test end-to-end AttributeMigration
     */
@Test
public void testAttributeMigration() throws Exception {
    EphemeralStore destination = EphemeralStore.getFactory().getStore();
    EntrySource source = new DummyEntrySource(acct);
    List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
    // DummyMigrationCallback will store attributes in InMemoryEphemeralStore, and track deletions in deletedAttrs map
    MigrationCallback callback = new DummyMigrationCallback(destination);
    AttributeMigration.setCallback(callback);
    AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
    MigrationInfo info = MigrationInfo.getFactory().getInfo();
    // disable running in separate thread
    // run migration
    migration.migrateAllAccounts();
    EphemeralLocation location = new LdapEntryLocation(acct);
    EphemeralResult result = destination.get(new EphemeralKey(Provisioning.A_zimbraAuthTokens, "1234"), location);
    assertEquals("server_1", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraAuthTokens, "5678"), location);
    assertEquals("server_2", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb1"), location);
    assertEquals("data1", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb2"), location);
    assertEquals("data2", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraLastLogonTimestamp), location);
    assertEquals("currentdate", result.getValue());
    assertTrue(info.getStatus() == Status.COMPLETED);
}
Also used : EphemeralLocation(com.zimbra.cs.ephemeral.EphemeralLocation) MigrationCallback(com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback) EphemeralKey(com.zimbra.cs.ephemeral.EphemeralKey) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) EphemeralResult(com.zimbra.cs.ephemeral.EphemeralResult) LdapEntryLocation(com.zimbra.cs.ephemeral.LdapEntryLocation) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) Test(org.junit.Test)

Example 4 with EphemeralKey

use of com.zimbra.cs.ephemeral.EphemeralKey in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method verifyCsrfTokenEphemeralInput.

private void verifyCsrfTokenEphemeralInput(EphemeralInput input, String crumb, String data, Long expiration) {
    EphemeralKey key = input.getEphemeralKey();
    assertEquals(Provisioning.A_zimbraCsrfTokenData, key.getKey());
    assertEquals(crumb, key.getDynamicComponent());
    assertEquals(data, input.getValue());
    assertEquals(expiration, input.getExpiration());
}
Also used : EphemeralKey(com.zimbra.cs.ephemeral.EphemeralKey)

Example 5 with EphemeralKey

use of com.zimbra.cs.ephemeral.EphemeralKey in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method verifyAuthTokenEphemeralInput.

private void verifyAuthTokenEphemeralInput(EphemeralInput input, String token, String serverVersion, Long expiration) {
    EphemeralKey key = input.getEphemeralKey();
    assertEquals(Provisioning.A_zimbraAuthTokens, key.getKey());
    assertEquals(token, key.getDynamicComponent());
    assertEquals(serverVersion, input.getValue());
    assertEquals(expiration, input.getExpiration());
}
Also used : EphemeralKey(com.zimbra.cs.ephemeral.EphemeralKey)

Aggregations

EphemeralKey (com.zimbra.cs.ephemeral.EphemeralKey)11 EphemeralLocation (com.zimbra.cs.ephemeral.EphemeralLocation)6 LdapEntryLocation (com.zimbra.cs.ephemeral.LdapEntryLocation)6 EphemeralStore (com.zimbra.cs.ephemeral.EphemeralStore)5 LdapEphemeralStore (com.zimbra.cs.ephemeral.LdapEphemeralStore)4 EphemeralInput (com.zimbra.cs.ephemeral.EphemeralInput)3 AbsoluteExpiration (com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration)3 Expiration (com.zimbra.cs.ephemeral.EphemeralInput.Expiration)3 EphemeralResult (com.zimbra.cs.ephemeral.EphemeralResult)2 EntrySource (com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource)1 MigrationCallback (com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback)1 Test (org.junit.Test)1