Search in sources :

Example 26 with ZAttributes

use of com.zimbra.cs.ldap.ZAttributes in project zm-mailbox by Zimbra.

the class LdapProvisioning method getZimlet.

private Zimlet getZimlet(String name, ZLdapContext initZlc, boolean useZimletCache) throws ServiceException {
    LdapZimlet zimlet = null;
    if (useZimletCache) {
        zimlet = zimletCache.getByName(name);
    }
    if (zimlet != null) {
        return zimlet;
    }
    try {
        String dn = mDIT.zimletNameToDN(name);
        ZAttributes attrs = helper.getAttributes(initZlc, LdapServerType.REPLICA, LdapUsage.GET_ZIMLET, dn, null);
        zimlet = new LdapZimlet(dn, attrs, this);
        if (useZimletCache) {
            ZimletUtil.reloadZimlet(name);
            // put LdapZimlet into the cache after successful ZimletUtil.reloadZimlet()
            zimletCache.put(zimlet);
        }
        return zimlet;
    } catch (LdapEntryNotFoundException e) {
        return null;
    } catch (ServiceException ne) {
        throw ServiceException.FAILURE("unable to get zimlet: " + name, ne);
    } catch (ZimletException ze) {
        throw ServiceException.FAILURE("unable to load zimlet: " + name, ze);
    }
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapEntryNotFoundException(com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException) LdapZimlet(com.zimbra.cs.account.ldap.entry.LdapZimlet) ZAttributes(com.zimbra.cs.ldap.ZAttributes) ZimletException(com.zimbra.cs.zimlet.ZimletException)

Example 27 with ZAttributes

use of com.zimbra.cs.ldap.ZAttributes in project zm-mailbox by Zimbra.

the class LdapProvisioning method getConfig.

@Override
public synchronized Config getConfig() throws ServiceException {
    if (cachedGlobalConfig == null) {
        String configDn = mDIT.configDN();
        try {
            ZAttributes attrs = helper.getAttributes(LdapUsage.GET_GLOBALCONFIG, configDn);
            LdapConfig config = new LdapConfig(configDn, attrs, this);
            if (useCache) {
                cachedGlobalConfig = config;
            } else {
                return config;
            }
        } catch (ServiceException e) {
            throw ServiceException.FAILURE("unable to get config", e);
        }
    }
    return cachedGlobalConfig;
}
Also used : LdapConfig(com.zimbra.cs.account.ldap.entry.LdapConfig) ExternalLdapConfig(com.zimbra.cs.ldap.LdapServerConfig.ExternalLdapConfig) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZAttributes(com.zimbra.cs.ldap.ZAttributes)

Example 28 with ZAttributes

use of com.zimbra.cs.ldap.ZAttributes in project zm-mailbox by Zimbra.

the class LdapProvisioning method getGlobalGrant.

@Override
public synchronized GlobalGrant getGlobalGrant() throws ServiceException {
    if (cachedGlobalGrant == null) {
        String globalGrantDn = mDIT.globalGrantDN();
        try {
            ZAttributes attrs = helper.getAttributes(LdapUsage.GET_GLOBALGRANT, globalGrantDn);
            LdapGlobalGrant globalGrant = new LdapGlobalGrant(globalGrantDn, attrs, this);
            if (useCache) {
                cachedGlobalGrant = globalGrant;
            } else {
                return globalGrant;
            }
        } catch (ServiceException e) {
            throw ServiceException.FAILURE("unable to get globalgrant", e);
        }
    }
    return cachedGlobalGrant;
}
Also used : LdapGlobalGrant(com.zimbra.cs.account.ldap.entry.LdapGlobalGrant) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZAttributes(com.zimbra.cs.ldap.ZAttributes)

Example 29 with ZAttributes

use of com.zimbra.cs.ldap.ZAttributes in project zm-mailbox by Zimbra.

the class TestLdapZMutableEntry method setAttr.

@Test
public void setAttr() throws Exception {
    String KEY = "key";
    String VALUE1 = "value1";
    String VALUE2 = "value2";
    ZMutableEntry entry = LdapClient.createMutableEntry();
    entry.setAttr(KEY, VALUE1);
    // should REPLACE
    entry.setAttr(KEY, VALUE2);
    ZAttributes zattrs = entry.getAttributes();
    Map<String, Object> attrs = zattrs.getAttrs();
    Object valueGot = attrs.get(KEY);
    assertTrue(valueGot instanceof String);
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) ZAttributes(com.zimbra.cs.ldap.ZAttributes)

Example 30 with ZAttributes

use of com.zimbra.cs.ldap.ZAttributes in project zm-mailbox by Zimbra.

the class TestLdapZMutableEntry method addAttr.

@Test
public void addAttr() throws Exception {
    String KEY = "key";
    String VALUE1 = "value1";
    String VALUE2 = "value2";
    String VALUE3 = "value3";
    ZMutableEntry entry = LdapClient.createMutableEntry();
    Set<String> values = new HashSet<String>();
    values.add(VALUE1);
    values.add(VALUE2);
    entry.addAttr(KEY, values);
    values.clear();
    values.add(VALUE1);
    values.add(VALUE3);
    // should MERGE
    entry.addAttr(KEY, values);
    ZAttributes zattrs = entry.getAttributes();
    Map<String, Object> attrs = zattrs.getAttrs();
    Object valueGot = attrs.get(KEY);
    assertTrue(valueGot instanceof String[]);
    List<String> valuesGot = Arrays.asList((String[]) valueGot);
    assertTrue(valuesGot.contains(VALUE1));
    assertTrue(valuesGot.contains(VALUE2));
    assertTrue(valuesGot.contains(VALUE3));
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) ZAttributes(com.zimbra.cs.ldap.ZAttributes) HashSet(java.util.HashSet)

Aggregations

ZAttributes (com.zimbra.cs.ldap.ZAttributes)30 ServiceException (com.zimbra.common.service.ServiceException)18 AccountServiceException (com.zimbra.cs.account.AccountServiceException)16 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)15 LdapEntryNotFoundException (com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException)8 Account (com.zimbra.cs.account.Account)6 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)6 Domain (com.zimbra.cs.account.Domain)4 GuestAccount (com.zimbra.cs.account.GuestAccount)4 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)4 HashMap (java.util.HashMap)4 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)3 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)3 ZMutableEntry (com.zimbra.cs.ldap.ZMutableEntry)3 Alias (com.zimbra.cs.account.Alias)2 AlwaysOnCluster (com.zimbra.cs.account.AlwaysOnCluster)2 DynamicGroup (com.zimbra.cs.account.DynamicGroup)2 Group (com.zimbra.cs.account.Group)2 NamedEntry (com.zimbra.cs.account.NamedEntry)2 Server (com.zimbra.cs.account.Server)2