use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class LdapProvisioning method deleteIdentity.
@Override
public void deleteIdentity(Account account, String identityName) throws ServiceException {
LdapEntry ldapEntry = (LdapEntry) (account instanceof LdapEntry ? account : getAccountById(account.getId()));
if (ldapEntry == null)
throw AccountServiceException.NO_SUCH_ACCOUNT(account.getName());
if (identityName.equalsIgnoreCase(ProvisioningConstants.DEFAULT_IDENTITY_NAME))
throw ServiceException.INVALID_REQUEST("can't delete default identity", null);
account.setCachedData(IDENTITY_LIST_CACHE_KEY, null);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.DELETE_IDENTITY);
Identity identity = getIdentityByName(ldapEntry, identityName, zlc);
if (identity == null)
throw AccountServiceException.NO_SUCH_IDENTITY(identityName);
String dn = getIdentityDn(ldapEntry, identityName);
zlc.deleteEntry(dn);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to delete identity: " + identityName, e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class LdapProvisioning method getIdentitiesByQuery.
private List<Identity> getIdentitiesByQuery(LdapEntry entry, ZLdapFilter filter, ZLdapContext initZlc) throws ServiceException {
List<Identity> result = new ArrayList<Identity>();
try {
String base = entry.getDN();
ZSearchResultEnumeration ne = helper.searchDir(base, filter, ZSearchControls.SEARCH_CTLS_SUBTREE(), initZlc, LdapServerType.REPLICA);
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
result.add(new LdapIdentity((Account) entry, sr.getDN(), sr.getAttributes(), this));
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to lookup identity via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
}
return result;
}
use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class ACLUtil method getSendOnBehalfOf.
/**
* Returns {@link UserRights#R_sendOnBehalfOf} rights granted to the grantee.
*/
public static List<Identity> getSendOnBehalfOf(Account grantee) throws ServiceException {
Multimap<Right, Entry> rights = getGrantedRights(grantee, Collections.singleton(Provisioning.A_displayName));
ImmutableList.Builder<Identity> result = ImmutableList.<Identity>builder();
for (Entry entry : rights.get(UserRights.R_sendOnBehalfOf)) {
Account grantor = (Account) entry;
String mail = grantor.getName();
String name = MoreObjects.firstNonNull(grantor.getDisplayName(), mail);
Map<String, Object> attrs = ImmutableMap.<String, Object>builder().put(Provisioning.A_zimbraPrefIdentityId, grantor.getId()).put(Provisioning.A_zimbraPrefIdentityName, name).put(Provisioning.A_zimbraPrefFromDisplay, name).put(Provisioning.A_zimbraPrefFromAddress, mail).put(Provisioning.A_objectClass, AttributeClass.OC_zimbraAclTarget).build();
result.add(new Identity(grantee, name, grantor.getId(), attrs, grantee.getProvisioning()));
}
return result.build();
}
use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAllIdentities.
@Override
public List<Identity> getAllIdentities(Account account) throws ServiceException {
LdapEntry ldapEntry = (LdapEntry) (account instanceof LdapEntry ? account : getAccountById(account.getId()));
if (ldapEntry == null)
throw AccountServiceException.NO_SUCH_ACCOUNT(account.getName());
@SuppressWarnings("unchecked") List<Identity> result = (List<Identity>) account.getCachedData(IDENTITY_LIST_CACHE_KEY);
if (result != null) {
return result;
}
result = getIdentitiesByQuery(ldapEntry, filterFactory.allIdentities(), null);
for (Identity identity : result) {
// gross hack for 4.5beta. should be able to remove post 4.5
if (identity.getId() == null) {
String id = LdapUtil.generateUUID();
identity.setId(id);
Map<String, Object> newAttrs = new HashMap<String, Object>();
newAttrs.put(Provisioning.A_zimbraPrefIdentityId, id);
try {
modifyIdentity(account, identity.getName(), newAttrs);
} catch (ServiceException se) {
ZimbraLog.account.warn("error updating identity: " + account.getName() + " " + identity.getName() + " " + se.getMessage(), se);
}
}
}
result.add(getDefaultIdentity(account));
result = Collections.unmodifiableList(result);
account.setCachedData(IDENTITY_LIST_CACHE_KEY, result);
return result;
}
use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class PlainTextSignature method preModify.
@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) throws ServiceException {
SingleValueMod mod = singleValueMod(attrName, value);
if (mod.unsetting())
return;
Account account;
if (entry instanceof Account) {
account = (Account) entry;
} else if (entry instanceof Identity) {
account = ((Identity) entry).getAccount();
} else if (entry instanceof DataSource) {
account = ((DataSource) entry).getAccount();
} else {
return;
}
Signature sig = Provisioning.getInstance().get(account, Key.SignatureBy.id, mod.value());
if (sig == null) {
throw ServiceException.INVALID_REQUEST("No such signature " + mod.value() + " for account " + account.getName(), null);
}
String sigAttr = SignatureUtil.mimeTypeToAttrName(MimeConstants.CT_TEXT_PLAIN);
String plainSig = sig.getAttr(sigAttr, null);
if (StringUtil.isNullOrEmpty(plainSig)) {
throw ServiceException.INVALID_REQUEST("Signature " + mod.value() + " must have plain text content", null);
}
}
Aggregations