Search in sources :

Example 1 with AttributeInfo

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

the class LdapProvisioning method getBasicDynamicGroupAttrs.

private String[] getBasicDynamicGroupAttrs() throws ServiceException {
    AttributeManager attrMgr = AttributeManager.getInstance();
    Set<String> dynGroupAttrs = attrMgr.getAllAttrsInClass(AttributeClass.group);
    Set<String> attrs = Sets.newHashSet(dynGroupAttrs);
    attrs.add(Provisioning.A_objectClass);
    // remove deprecated attrs
    for (Iterator<String> iter = attrs.iterator(); iter.hasNext(); ) {
        String attr = iter.next();
        AttributeInfo ai = attrMgr.getAttributeInfo(attr);
        if (ai != null && ai.isDeprecated()) {
            iter.remove();
        }
    }
    return Lists.newArrayList(attrs).toArray(new String[attrs.size()]);
}
Also used : AttributeInfo(com.zimbra.cs.account.AttributeInfo) AttributeManager(com.zimbra.cs.account.AttributeManager)

Example 2 with AttributeInfo

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

the class LdapProvisioning method modifyAttrsInternal.

/**
 * should only be called internally.
 *
 * @param initCtxt
 * @param attrs
 * @throws ServiceException
 */
protected void modifyAttrsInternal(Entry entry, ZLdapContext initZlc, Map<String, ? extends Object> attrs, boolean storeEphemeralInLdap) throws ServiceException {
    if (entry instanceof Account && !(entry instanceof CalendarResource)) {
        Account acct = (Account) entry;
        validate(ProvisioningValidator.MODIFY_ACCOUNT_CHECK_DOMAIN_COS_AND_FEATURE, acct.getAttr(A_zimbraMailDeliveryAddress), attrs, acct);
    }
    if (!storeEphemeralInLdap) {
        Map<String, AttributeInfo> ephemeralAttrMap = AttributeManager.getInstance().getEphemeralAttrs();
        Map<String, Object> ephemeralAttrs = new HashMap<String, Object>();
        // remove after iteration to avoid ConcurrentModificationException
        List<String> toRemove = null;
        for (Map.Entry<String, ? extends Object> e : attrs.entrySet()) {
            String key = e.getKey();
            String attrName;
            if (key.startsWith("+") || key.startsWith("-")) {
                attrName = key.substring(1);
            } else {
                attrName = key;
            }
            if (ephemeralAttrMap.containsKey(attrName.toLowerCase())) {
                ephemeralAttrs.put(key, e.getValue());
                if (null == toRemove) {
                    // only 3 ephemeral attrs currently
                    toRemove = Lists.newArrayListWithExpectedSize(3);
                }
                toRemove.add(key);
            }
        }
        if (null != toRemove) {
            for (String key : toRemove) {
                attrs.remove(key);
            }
        }
        if (!ephemeralAttrs.isEmpty()) {
            modifyEphemeralAttrs(entry, ephemeralAttrs, ephemeralAttrMap);
        }
    }
    modifyLdapAttrs(entry, initZlc, attrs);
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) AttributeInfo(com.zimbra.cs.account.AttributeInfo) HashMap(java.util.HashMap) LdapCalendarResource(com.zimbra.cs.account.ldap.entry.LdapCalendarResource) CalendarResource(com.zimbra.cs.account.CalendarResource) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 3 with AttributeInfo

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

the class EphemeralAttributesTest method initEphemeralAttributes.

private static void initEphemeralAttributes() throws Exception {
    Set<AttributeClass> requiredIn = Sets.newHashSet(AttributeClass.account);
    Set<AttributeFlag> flags = Sets.newHashSet(AttributeFlag.ephemeral, AttributeFlag.dynamic, AttributeFlag.expirable);
    AttributeInfo ai1 = new AttributeInfo(Provisioning.A_zimbraAuthTokens, 1, null, 0, null, AttributeType.TYPE_ASTRING, null, "", true, null, null, AttributeCardinality.multi, requiredIn, null, flags, null, null, null, null, null, "auth tokens", null, null, null);
    AttributeInfo ai2 = new AttributeInfo(Provisioning.A_zimbraCsrfTokenData, 1, null, 0, null, AttributeType.TYPE_ASTRING, null, "", true, null, null, AttributeCardinality.multi, requiredIn, null, flags, null, null, null, null, null, "csrf tokens", null, null, null);
    AttributeInfo ai3 = new AttributeInfo(Provisioning.A_zimbraLastLogonTimestamp, 1, null, 0, null, AttributeType.TYPE_GENTIME, null, "", true, null, null, AttributeCardinality.single, requiredIn, null, flags, null, null, null, null, null, "last logon timestamp", null, null, null);
    AttributeInfo ai4 = new AttributeInfo(Provisioning.A_zimbraAppSpecificPassword, 1, null, 0, null, AttributeType.TYPE_ASTRING, null, "", true, null, null, AttributeCardinality.single, requiredIn, null, flags, null, null, null, null, null, "app-specific passwords", null, null, null);
    AttributeManager am = new AttributeManager();
    am.addAttribute(ai1);
    am.addAttribute(ai2);
    am.addAttribute(ai3);
    am.addAttribute(ai4);
}
Also used : AttributeFlag(com.zimbra.cs.account.AttributeFlag) AttributeInfo(com.zimbra.cs.account.AttributeInfo) AttributeManager(com.zimbra.cs.account.AttributeManager) AttributeClass(com.zimbra.cs.account.AttributeClass)

Example 4 with AttributeInfo

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

the class LdapProvisioning method copyCos.

private Cos copyCos(String srcCosId, String destCosName, Map<String, Object> cosAttrs) throws ServiceException {
    destCosName = destCosName.toLowerCase().trim();
    Cos srcCos = getCosById(srcCosId, null);
    if (srcCos == null)
        throw AccountServiceException.NO_SUCH_COS(srcCosId);
    // bug 67716, use a case insensitive map because provided attr names may not be
    // the canonical name and that will cause multiple entries in the map
    Map<String, Object> allAttrs = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
    allAttrs.putAll(srcCos.getAttrs());
    allAttrs.remove(Provisioning.A_objectClass);
    allAttrs.remove(Provisioning.A_zimbraId);
    allAttrs.remove(Provisioning.A_zimbraCreateTimestamp);
    allAttrs.remove(Provisioning.A_zimbraACE);
    allAttrs.remove(Provisioning.A_cn);
    allAttrs.remove(Provisioning.A_description);
    if (cosAttrs != null) {
        for (Map.Entry<String, Object> e : cosAttrs.entrySet()) {
            String attr = e.getKey();
            Object value = e.getValue();
            if (value instanceof String && Strings.isNullOrEmpty((String) value)) {
                allAttrs.remove(attr);
            } else {
                allAttrs.put(attr, value);
            }
        }
    }
    CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
    // get rid of deprecated attrs
    Map<String, Object> allNewAttrs = new HashMap<String, Object>(allAttrs);
    for (String attr : allAttrs.keySet()) {
        AttributeInfo info = AttributeManager.getInstance().getAttributeInfo(attr);
        if (info != null && info.isDeprecated()) {
            allNewAttrs.remove(attr);
        }
    }
    allAttrs = allNewAttrs;
    AttributeManager.getInstance().preModify(allAttrs, null, callbackContext, true);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_COS);
        ZMutableEntry entry = LdapClient.createMutableEntry();
        entry.mapToAttrs(allAttrs);
        Set<String> ocs = LdapObjectClass.getCosObjectClasses(this);
        entry.addAttr(A_objectClass, ocs);
        String zimbraIdStr = LdapUtil.generateUUID();
        entry.setAttr(A_zimbraId, zimbraIdStr);
        entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
        entry.setAttr(A_cn, destCosName);
        String dn = mDIT.cosNametoDN(destCosName);
        entry.setDN(dn);
        zlc.createEntry(entry);
        Cos cos = getCosById(zimbraIdStr, zlc);
        AttributeManager.getInstance().postModify(allAttrs, cos, callbackContext);
        return cos;
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.COS_EXISTS(destCosName);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to create cos: " + destCosName, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) HashMap(java.util.HashMap) LdapCos(com.zimbra.cs.account.ldap.entry.LdapCos) Cos(com.zimbra.cs.account.Cos) TreeMap(java.util.TreeMap) Date(java.util.Date) AttributeInfo(com.zimbra.cs.account.AttributeInfo) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) CallbackContext(com.zimbra.cs.account.callback.CallbackContext) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) LdapException(com.zimbra.cs.ldap.LdapException)

Example 5 with AttributeInfo

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

the class GetAttributeInfo method encodeAttr.

private void encodeAttr(Element response, AttributeManager attrMgr, String attr) {
    AttributeInfo attrInfo = attrMgr.getAttributeInfo(attr);
    if (attrInfo == null) {
        ZimbraLog.account.info("no attribte info for " + attr);
        return;
    }
    String desc = attrInfo.getDescription();
    String deSpacedDesc = FileGenUtil.wrapComments((desc == null ? "" : desc), Integer.MAX_VALUE, "");
    Element eAttr = response.addElement(AdminConstants.E_A);
    eAttr.addAttribute(AdminConstants.A_N, attr);
    eAttr.addAttribute(AdminConstants.A_DESC, deSpacedDesc);
}
Also used : AttributeInfo(com.zimbra.cs.account.AttributeInfo) Element(com.zimbra.common.soap.Element)

Aggregations

AttributeInfo (com.zimbra.cs.account.AttributeInfo)9 HashMap (java.util.HashMap)5 AttributeManager (com.zimbra.cs.account.AttributeManager)4 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 ServiceException (com.zimbra.common.service.ServiceException)2 Element (com.zimbra.common.soap.Element)2 Account (com.zimbra.cs.account.Account)2 KeyValuePair (com.zimbra.common.soap.Element.KeyValuePair)1 Version (com.zimbra.common.util.Version)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)1 AttributeClass (com.zimbra.cs.account.AttributeClass)1 AttributeFlag (com.zimbra.cs.account.AttributeFlag)1 CalendarResource (com.zimbra.cs.account.CalendarResource)1 Cos (com.zimbra.cs.account.Cos)1 GuestAccount (com.zimbra.cs.account.GuestAccount)1 CallbackContext (com.zimbra.cs.account.callback.CallbackContext)1 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)1 LdapCalendarResource (com.zimbra.cs.account.ldap.entry.LdapCalendarResource)1