Search in sources :

Example 6 with LdapEntryLocation

use of com.zimbra.cs.ephemeral.LdapEntryLocation 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);
    Multimap<String, Object> deletedAttrs = LinkedListMultimap.create();
    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, deletedAttrs);
    AttributeMigration migration = new AttributeMigration(attrsToMigrate, source, callback, null);
    //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());
    Collection<Object> deleted = deletedAttrs.get(Provisioning.A_zimbraAuthTokens);
    assertTrue(deleted.contains(authToken1));
    assertTrue(deleted.contains(authToken2));
    deleted = deletedAttrs.get(Provisioning.A_zimbraCsrfTokenData);
    assertTrue(deleted.contains(csrfToken1));
    assertTrue(deleted.contains(csrfToken2));
    deleted = deletedAttrs.get(Provisioning.A_zimbraLastLogonTimestamp);
    assertTrue(deleted.contains(lastLogon));
}
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) FallbackEphemeralStore(com.zimbra.cs.ephemeral.FallbackEphemeralStore) LdapEphemeralStore(com.zimbra.cs.ephemeral.LdapEphemeralStore) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) InMemoryEphemeralStore(com.zimbra.cs.ephemeral.InMemoryEphemeralStore) Test(org.junit.Test)

Example 7 with LdapEntryLocation

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

the class LdapProvisioning method modifyEphemeralAttrs.

private void modifyEphemeralAttrs(Entry entry, Map<String, Object> attrs, Map<String, AttributeInfo> ephemeralAttrMap) throws ServiceException {
    EphemeralLocation location = new LdapEntryLocation(entry);
    EphemeralStore store = EphemeralStore.getFactory().getStore();
    for (Map.Entry<String, Object> e : attrs.entrySet()) {
        String key = e.getKey();
        Object value = e.getValue();
        boolean doAdd = key.charAt(0) == '+';
        boolean doRemove = key.charAt(0) == '-';
        if (doAdd || doRemove) {
            key = key.substring(1);
            if (attrs.containsKey(key))
                throw ServiceException.INVALID_REQUEST("can't mix +attrName/-attrName with attrName", null);
        }
        AttributeInfo ai = ephemeralAttrMap.get(key.toLowerCase());
        AttributeConverter converter = null;
        if (ai == null) {
            continue;
        }
        if (ai.isDynamic()) {
            converter = AttributeMigration.getConverter(key);
            if (converter == null) {
                ZimbraLog.ephemeral.warn("Dynamic ephemeral attribute %s has no registered AttributeConverter, so cannot be modified with modifyAttrs", key);
                continue;
            }
        }
        if (value instanceof Collection) {
            Collection values = (Collection) value;
            if (values.size() == 0) {
                ZimbraLog.ephemeral.warn("Ephemeral attribute %s doesn't support deletion by key; only deletion by key+value is supported", key);
                continue;
            } else {
                for (Object v : values) {
                    if (v == null) {
                        continue;
                    }
                    String s = v.toString();
                    handleEphemeralAttrChange(store, key, s, location, ai, converter, doAdd, doRemove);
                }
            }
        } else if (value instanceof Map) {
            throw ServiceException.FAILURE("Map is not a supported value type", null);
        } else if (value != null) {
            String s = value.toString();
            handleEphemeralAttrChange(store, key, s, location, ai, converter, doAdd, doRemove);
        } else {
            ZimbraLog.ephemeral.warn("Ephemeral attribute %s doesn't support deletion by key; only deletion by key+value is supported", key);
        }
    }
}
Also used : LdapEntryLocation(com.zimbra.cs.ephemeral.LdapEntryLocation) AttributeInfo(com.zimbra.cs.account.AttributeInfo) AttributeConverter(com.zimbra.cs.ephemeral.migrate.AttributeConverter) EphemeralLocation(com.zimbra.cs.ephemeral.EphemeralLocation) Collection(java.util.Collection) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) LdapEphemeralStore(com.zimbra.cs.ephemeral.LdapEphemeralStore)

Example 8 with LdapEntryLocation

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

the class Entry method hasEphemeralAttr.

public boolean hasEphemeralAttr(String key, String dynamicComponent) throws ServiceException {
    EphemeralLocation location = new LdapEntryLocation(this);
    EphemeralStore store = EphemeralStore.getFactory().getStore();
    return store.has(new EphemeralKey(key, dynamicComponent), 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 9 with LdapEntryLocation

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

the class Entry method getEphemeralAttr.

public EphemeralResult getEphemeralAttr(String key, String dynamicComponent) throws ServiceException {
    EphemeralLocation location = new LdapEntryLocation(this);
    EphemeralStore store = EphemeralStore.getFactory().getStore();
    EphemeralKey ephemeralKey = new EphemeralKey(key, dynamicComponent);
    EphemeralResult result = store.get(ephemeralKey, location);
    return result == null ? EphemeralResult.emptyResult(ephemeralKey) : result;
}
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) EphemeralResult(com.zimbra.cs.ephemeral.EphemeralResult)

Example 10 with LdapEntryLocation

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

the class Entry method deleteEphemeralAttr.

public void deleteEphemeralAttr(String key, String dynamicComponent, String value) throws ServiceException {
    EphemeralLocation location = new LdapEntryLocation(this);
    EphemeralStore store = EphemeralStore.getFactory().getStore();
    store.delete(new EphemeralKey(key, dynamicComponent), value, 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)

Aggregations

EphemeralStore (com.zimbra.cs.ephemeral.EphemeralStore)10 LdapEntryLocation (com.zimbra.cs.ephemeral.LdapEntryLocation)10 LdapEphemeralStore (com.zimbra.cs.ephemeral.LdapEphemeralStore)10 EphemeralLocation (com.zimbra.cs.ephemeral.EphemeralLocation)9 EphemeralKey (com.zimbra.cs.ephemeral.EphemeralKey)5 EphemeralResult (com.zimbra.cs.ephemeral.EphemeralResult)2 HashMap (java.util.HashMap)2 ServiceException (com.zimbra.common.service.ServiceException)1 LogFactory (com.zimbra.common.util.LogFactory)1 Account (com.zimbra.cs.account.Account)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)1 AttributeInfo (com.zimbra.cs.account.AttributeInfo)1 GuestAccount (com.zimbra.cs.account.GuestAccount)1 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)1 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)1 FallbackEphemeralStore (com.zimbra.cs.ephemeral.FallbackEphemeralStore)1 InMemoryEphemeralStore (com.zimbra.cs.ephemeral.InMemoryEphemeralStore)1 AttributeConverter (com.zimbra.cs.ephemeral.migrate.AttributeConverter)1 EntrySource (com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource)1