Search in sources :

Example 51 with Config

use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.

the class TestAutoProvision method eagerModeTimer.

@Test
public void eagerModeTimer() throws Exception {
    Config config = prov.getConfig();
    config.setAutoProvPollingInterval("1000ms");
    String testName = getTestName();
    final String externalPassword = "test456";
    int totalAccts = 4;
    int batchSize = 1;
    String extAcctLocalPart1 = testName + "_11";
    String extAcctLocalPart2 = "zzz";
    String extAcctLocalPart3 = testName + "_13";
    String extAcctLocalPart4 = testName + "_14";
    String extAcctLocalPart5 = testName + "_15";
    createExternalAcctEntry(extAcctLocalPart1, externalPassword, null);
    createExternalAcctEntry(extAcctLocalPart2, externalPassword, null);
    createExternalAcctEntry(extAcctLocalPart3, externalPassword, null);
    createExternalAcctEntry(extAcctLocalPart4, externalPassword, null);
    createExternalAcctEntry(extAcctLocalPart5, externalPassword, null);
    Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
    // setup auto prov
    zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchBase, extDomainDn);
    zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchFilter, "(&(uid=%u)(mail=eagerMode*)" + AutoProvisionTestUtil.MarkEntryProvisionedListener.NOT_PROVED_FILTER + ")");
    zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvAccountNameMap, Provisioning.A_uid);
    zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvBatchSize, "" + batchSize);
    zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvListenerClass, AutoProvisionTestUtil.MarkEntryProvisionedListener.class.getName());
    Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
    // schedule the domain on local server
    prov.getLocalServer().addAutoProvScheduledDomains(zimbraDomain.getName());
    new MockAutoProvisionThread().start();
    //wait for eager thread to finish
    Thread.sleep(10000);
    List<Account> zimbraAccts = prov.getAllAccounts(zimbraDomain);
    assertEquals(totalAccts, zimbraAccts.size());
    Set<String> acctNames = new HashSet<String>();
    for (Account acct : zimbraAccts) {
        acctNames.add(acct.getName());
    }
    assertTrue(acctNames.contains(TestUtil.getAddress(extAcctLocalPart1, zimbraDomain.getName()).toLowerCase()));
    assertTrue(acctNames.contains(TestUtil.getAddress(extAcctLocalPart3, zimbraDomain.getName()).toLowerCase()));
    assertTrue(acctNames.contains(TestUtil.getAddress(extAcctLocalPart4, zimbraDomain.getName()).toLowerCase()));
    assertTrue(acctNames.contains(TestUtil.getAddress(extAcctLocalPart5, zimbraDomain.getName()).toLowerCase()));
    // clear scheduled domains on the local server
    prov.getLocalServer().unsetAutoProvScheduledDomains();
}
Also used : Account(com.zimbra.cs.account.Account) Config(com.zimbra.cs.account.Config) Domain(com.zimbra.cs.account.Domain) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 52 with Config

use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.

the class LdapProvisioning method getZMGProxyDataSourceAttrs.

private Map<String, Object> getZMGProxyDataSourceAttrs(String emailAddr, String password, boolean encryptPassword, String dsId) throws ServiceException {
    Map<String, Object> testAttrs = new HashMap<String, Object>();
    Config config = getConfig();
    testAttrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapConstants.LDAP_TRUE);
    testAttrs.put(Provisioning.A_zimbraDataSourceIsZmgProxy, LdapConstants.LDAP_TRUE);
    testAttrs.put(Provisioning.A_zimbraDataSourceHost, config.getMobileGatewayProxyImapHost());
    testAttrs.put(Provisioning.A_zimbraDataSourcePort, Integer.toString(config.getMobileGatewayProxyImapPort()));
    testAttrs.put(Provisioning.A_zimbraDataSourceConnectionType, config.getMobileGatewayProxyImapConnectionType().toString());
    testAttrs.put(Provisioning.A_zimbraDataSourceUsername, emailAddr);
    testAttrs.put(Provisioning.A_zimbraDataSourcePassword, encryptPassword ? DataSource.encryptData(dsId, password) : password);
    testAttrs.put(Provisioning.A_zimbraDataSourceSmtpEnabled, LdapConstants.LDAP_TRUE);
    testAttrs.put(Provisioning.A_zimbraDataSourceSmtpHost, config.getMobileGatewayProxySmtpHost());
    testAttrs.put(Provisioning.A_zimbraDataSourceSmtpPort, Integer.toString(config.getMobileGatewayProxySmtpPort()));
    testAttrs.put(Provisioning.A_zimbraDataSourceSmtpConnectionType, config.getMobileGatewayProxySmtpConnectionType().toString());
    testAttrs.put(Provisioning.A_zimbraDataSourceSmtpAuthRequired, LdapConstants.LDAP_TRUE);
    return testAttrs;
}
Also used : HashMap(java.util.HashMap) Config(com.zimbra.cs.account.Config) LdapConfig(com.zimbra.cs.account.ldap.entry.LdapConfig) ExternalLdapConfig(com.zimbra.cs.ldap.LdapServerConfig.ExternalLdapConfig) GalSearchConfig(com.zimbra.cs.gal.GalSearchConfig)

Example 53 with Config

use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.

the class LdapProvisioning method updateLastLogon.

private void updateLastLogon(Account acct) throws ServiceException {
    if (EphemeralStore.getFactory() instanceof LdapEphemeralStore.Factory) {
        Config config = Provisioning.getInstance().getConfig();
        long freq = config.getLastLogonTimestampFrequency();
        // never update timestamp if frequency is 0
        if (freq == 0) {
            return;
        }
        Date lastLogon = acct.getLastLogonTimestamp();
        // hasn't passed since the last timestamp was logged
        if (lastLogon != null && (lastLogon.getTime() + freq > System.currentTimeMillis())) {
            return;
        }
    }
    try {
        acct.setLastLogonTimestamp(new Date());
    } catch (ServiceException e) {
        ZimbraLog.account.warn("error updating zimbraLastLogonTimestamp", e);
    }
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) Config(com.zimbra.cs.account.Config) LdapConfig(com.zimbra.cs.account.ldap.entry.LdapConfig) ExternalLdapConfig(com.zimbra.cs.ldap.LdapServerConfig.ExternalLdapConfig) GalSearchConfig(com.zimbra.cs.gal.GalSearchConfig) LogFactory(com.zimbra.common.util.LogFactory) ZLdapFilterFactory(com.zimbra.cs.ldap.ZLdapFilterFactory) Date(java.util.Date)

Example 54 with Config

use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.

the class ZimbraLmtpBackend method checkDedupeCacheSize.

/**
     * If the configured Message-ID cache size has changed, create a new cache and copy
     * values from the old one.
     */
private void checkDedupeCacheSize() {
    try {
        Config config = Provisioning.getInstance().getConfig();
        int cacheSize = config.getMessageIdDedupeCacheSize();
        long entryTimeout = config.getMessageIdDedupeCacheTimeout();
        synchronized (ZimbraLmtpBackend.class) {
            Map<String, Set<Integer>> newMap = null;
            if (receivedMessageIDs == null) {
                // if non-zero entry timeout is specified then use a timeout map, else use an lru map
                receivedMessageIDs = entryTimeout == 0 ? new LruMap<String, Set<Integer>>(cacheSize) : new TimeoutMap<String, Set<Integer>>(entryTimeout);
            } else if (receivedMessageIDs instanceof LruMap) {
                if (entryTimeout != 0) {
                    // change to a timeout map
                    newMap = MapUtil.newTimeoutMap(entryTimeout);
                } else if (((LruMap) receivedMessageIDs).getMaxSize() != cacheSize) {
                    // adjust lru map size
                    newMap = MapUtil.newLruMap(cacheSize);
                }
            } else if (receivedMessageIDs instanceof TimeoutMap) {
                if (entryTimeout == 0) {
                    // change to a lru map
                    newMap = MapUtil.newLruMap(cacheSize);
                } else {
                    ((TimeoutMap) receivedMessageIDs).setTimeout(entryTimeout);
                }
            }
            if (newMap != null) {
                // Copy entries from the old map to the new one.  The old map
                // is iterated in order from least-recently accessed to last accessed.
                // If the new map size is smaller, we'll get the latest entries.
                newMap.putAll(receivedMessageIDs);
                receivedMessageIDs = newMap;
            }
        }
    } catch (ServiceException e) {
        ZimbraLog.lmtp.warn("Unable to update dedupe cache size.", e);
        // create an empty lru map if it doesn't exist already.
        synchronized (ZimbraLmtpBackend.class) {
            if (receivedMessageIDs == null) {
                receivedMessageIDs = new LruMap<String, Set<Integer>>(0);
            }
        }
    }
}
Also used : LruMap(com.zimbra.common.util.LruMap) Set(java.util.Set) HashSet(java.util.HashSet) ServiceException(com.zimbra.common.service.ServiceException) DeliveryServiceException(com.zimbra.common.service.DeliveryServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Config(com.zimbra.cs.account.Config) DebugConfig(com.zimbra.common.localconfig.DebugConfig) TimeoutMap(com.zimbra.common.util.TimeoutMap)

Example 55 with Config

use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.

the class TestJaxbProvisioning method testGetConfig.

@Test
public void testGetConfig() throws Exception {
    ZimbraLog.test.debug("Starting test %s", testName());
    Config cfg = prov.getConfig();
    assertNotNull("Config", cfg);
    cfg = prov.getConfig("zimbra_user");
    assertNotNull("Config", cfg);
}
Also used : Config(com.zimbra.cs.account.Config) Test(org.junit.Test)

Aggregations

Config (com.zimbra.cs.account.Config)73 HashMap (java.util.HashMap)24 Provisioning (com.zimbra.cs.account.Provisioning)10 Test (org.junit.Test)8 ServiceException (com.zimbra.common.service.ServiceException)7 Account (com.zimbra.cs.account.Account)7 RetentionPolicy (com.zimbra.soap.mail.type.RetentionPolicy)7 Element (com.zimbra.common.soap.Element)6 Policy (com.zimbra.soap.mail.type.Policy)6 Cos (com.zimbra.cs.account.Cos)5 Server (com.zimbra.cs.account.Server)5 Domain (com.zimbra.cs.account.Domain)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 Pair (com.zimbra.common.util.Pair)3 HashSet (java.util.HashSet)3 SMTPMessage (com.sun.mail.smtp.SMTPMessage)2 ZFilterAction (com.zimbra.client.ZFilterAction)2 ZFileIntoAction (com.zimbra.client.ZFilterAction.ZFileIntoAction)2 ZFilterCondition (com.zimbra.client.ZFilterCondition)2 ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)2