Search in sources :

Example 1 with ZLdapSchema

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

the class LdapProvisioning method getAttrsInOCs.

@Override
public void getAttrsInOCs(String[] ocs, Set<String> attrsInOCs) throws ServiceException {
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.GET_SCHEMA);
        ZLdapSchema schema = zlc.getSchema();
        for (String oc : ocs) {
            try {
                ZLdapSchema.ZObjectClassDefinition ocSchema = schema.getObjectClass(oc);
                if (ocSchema != null) {
                    List<String> optAttrs = ocSchema.getOptionalAttributes();
                    for (String attr : optAttrs) {
                        attrsInOCs.add(attr);
                    }
                    List<String> reqAttrs = ocSchema.getRequiredAttributes();
                    for (String attr : reqAttrs) {
                        attrsInOCs.add(attr);
                    }
                }
            } catch (ServiceException e) {
                ZimbraLog.account.debug("unable to lookup attributes for objectclass: " + oc, e);
            }
        }
    } catch (ServiceException e) {
        ZimbraLog.account.warn("unable to get LDAP schema", e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZLdapSchema(com.zimbra.cs.ldap.ZLdapSchema) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException)

Example 2 with ZLdapSchema

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

the class LdapProvisioning method dumpLdapSchema.

@Override
public void dumpLdapSchema(PrintWriter writer) throws ServiceException {
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.GET_SCHEMA);
        ZLdapSchema schema = zlc.getSchema();
        for (ZLdapSchema.ZObjectClassDefinition oc : schema.getObjectClasses()) {
            writer.println(oc.getName());
        }
    // TODO print more stuff
    } catch (ServiceException e) {
        ZimbraLog.account.warn("unable to get LDAP schema", e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZLdapSchema(com.zimbra.cs.ldap.ZLdapSchema) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException)

Example 3 with ZLdapSchema

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

the class LdapProvisioning method searchOCsForSuperClasses.

@Override
public void searchOCsForSuperClasses(Map<String, Set<String>> ocs) {
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.GET_SCHEMA);
        ZLdapSchema schema = zlc.getSchema();
        for (Map.Entry<String, Set<String>> entry : ocs.entrySet()) {
            String oc = entry.getKey();
            Set<String> superOCs = entry.getValue();
            try {
                ZimbraLog.account.debug("Looking up OC: " + oc);
                ZLdapSchema.ZObjectClassDefinition ocSchema = schema.getObjectClass(oc);
                if (ocSchema != null) {
                    List<String> superClasses = ocSchema.getSuperiorClasses();
                    for (String superOC : superClasses) {
                        superOCs.add(superOC.toLowerCase());
                    }
                }
            } catch (ServiceException e) {
                ZimbraLog.account.debug("unable to load LDAP schema extension for objectclass: " + oc, e);
            }
        }
    } catch (ServiceException e) {
        ZimbraLog.account.warn("unable to get LDAP schema", e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZLdapSchema(com.zimbra.cs.ldap.ZLdapSchema) HashSet(java.util.HashSet) Set(java.util.Set) TreeSet(java.util.TreeSet) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)3 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)3 ZLdapSchema (com.zimbra.cs.ldap.ZLdapSchema)3 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1