Search in sources :

Example 1 with OperationContextData

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

the class ToXML method encodeACL.

// encode mailbox ACL
public static Element encodeACL(OperationContext octxt, Element parent, ACL acl, boolean exposeAclAccessKey) {
    Element eACL = parent.addUniqueElement(MailConstants.E_ACL);
    if (acl == null) {
        return eACL;
    }
    if (acl.getInternalGrantExpiry() != 0) {
        eACL.addAttribute(MailConstants.A_INTERNAL_GRANT_EXPIRY, acl.getInternalGrantExpiry());
    }
    if (acl.getGuestGrantExpiry() != 0) {
        eACL.addAttribute(MailConstants.A_GUEST_GRANT_EXPIRY, acl.getGuestGrantExpiry());
    }
    boolean needDispName = OperationContextData.getNeedGranteeName(octxt);
    for (ACL.Grant grant : acl.getGrants()) {
        String name = null;
        byte granteeType = grant.getGranteeType();
        if (needDispName) {
            //
            // Get name of the grantee
            //
            // 1. try getting the name from the Grant, the name is set on the Grant
            //    if we are in the path of proxying sharing in ZD
            name = grant.getGranteeName();
            if (name == null) {
                // 2. (for bug 35079), see if the name is already resolved in the in the OperationContextData
                OperationContextData.GranteeNames granteeNames = OperationContextData.getGranteeNames(octxt);
                if (granteeNames != null) {
                    name = granteeNames.getNameById(grant.getGranteeId(), granteeType);
                }
                //    this *may* lead to a LDAP search if the id is not in cache
                if (name == null) {
                    NamedEntry nentry = FolderAction.lookupGranteeByZimbraId(grant.getGranteeId(), granteeType);
                    if (nentry != null) {
                        name = nentry.getName();
                    }
                }
            }
        }
        Element eGrant = eACL.addElement(MailConstants.E_GRANT);
        eGrant.addAttribute(MailConstants.A_ZIMBRA_ID, grant.getGranteeId()).addAttribute(MailConstants.A_GRANT_TYPE, ACL.typeToString(granteeType)).addAttribute(MailConstants.A_RIGHTS, ACL.rightsToString(grant.getGrantedRights()));
        if (grant.getExpiry() != 0) {
            eGrant.addAttribute(MailConstants.A_EXPIRY, grant.getExpiry());
        }
        if (needDispName) {
            // refer to the same object
            if (OperationContextData.GranteeNames.INVALID_GRANT == name) {
                eGrant.addAttribute(MailConstants.A_INVALID, true);
                eGrant.addAttribute(MailConstants.A_DISPLAY, OperationContextData.GranteeNames.EMPTY_NAME);
            } else {
                eGrant.addAttribute(MailConstants.A_DISPLAY, name);
            }
        }
        if (granteeType == ACL.GRANTEE_KEY) {
            if (exposeAclAccessKey) {
                eGrant.addAttribute(MailConstants.A_ACCESSKEY, grant.getPassword());
            }
        } else {
            eGrant.addAttribute(MailConstants.A_PASSWORD, grant.getPassword());
        }
    }
    return eACL;
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) Element(com.zimbra.common.soap.Element) ACL(com.zimbra.cs.mailbox.ACL) OperationContextData(com.zimbra.cs.mailbox.OperationContextData)

Aggregations

Element (com.zimbra.common.soap.Element)1 NamedEntry (com.zimbra.cs.account.NamedEntry)1 ACL (com.zimbra.cs.mailbox.ACL)1 OperationContextData (com.zimbra.cs.mailbox.OperationContextData)1