Search in sources :

Example 1 with LdapIdentity

use of com.zimbra.cs.account.ldap.entry.LdapIdentity 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;
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) LdapIdentity(com.zimbra.cs.account.ldap.entry.LdapIdentity) Identity(com.zimbra.cs.account.Identity) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry) LdapIdentity(com.zimbra.cs.account.ldap.entry.LdapIdentity)

Example 2 with LdapIdentity

use of com.zimbra.cs.account.ldap.entry.LdapIdentity in project zm-mailbox by Zimbra.

the class LdapProvisioning method modifyIdentity.

@Override
public void modifyIdentity(Account account, String identityName, Map<String, Object> identityAttrs) throws ServiceException {
    removeAttrIgnoreCase("objectclass", identityAttrs);
    validateIdentityAttrs(identityAttrs);
    LdapEntry ldapEntry = (LdapEntry) (account instanceof LdapEntry ? account : getAccountById(account.getId()));
    if (ldapEntry == null)
        throw AccountServiceException.NO_SUCH_ACCOUNT(account.getName());
    // clear cache
    account.setCachedData(IDENTITY_LIST_CACHE_KEY, null);
    if (identityName.equalsIgnoreCase(ProvisioningConstants.DEFAULT_IDENTITY_NAME)) {
        modifyAttrs(account, identityAttrs);
    } else {
        LdapIdentity identity = (LdapIdentity) getIdentityByName(ldapEntry, identityName, null);
        if (identity == null)
            throw AccountServiceException.NO_SUCH_IDENTITY(identityName);
        String name = (String) identityAttrs.get(A_zimbraPrefIdentityName);
        boolean newName = (name != null && !name.equals(identityName));
        if (newName)
            identityAttrs.remove(A_zimbraPrefIdentityName);
        modifyAttrs(identity, identityAttrs, true);
        if (newName) {
            // the identity cache could've been loaded again if getAllIdentities were called in pre/poseModify callback, so we clear it again
            account.setCachedData(IDENTITY_LIST_CACHE_KEY, null);
            renameIdentity(ldapEntry, identity, name);
        }
    }
}
Also used : LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) LdapIdentity(com.zimbra.cs.account.ldap.entry.LdapIdentity)

Aggregations

LdapIdentity (com.zimbra.cs.account.ldap.entry.LdapIdentity)2 ServiceException (com.zimbra.common.service.ServiceException)1 Account (com.zimbra.cs.account.Account)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)1 GuestAccount (com.zimbra.cs.account.GuestAccount)1 Identity (com.zimbra.cs.account.Identity)1 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)1 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)1 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)1 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)1 ArrayList (java.util.ArrayList)1