Search in sources :

Example 46 with Account

use of com.zimbra.cs.account.Account 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 47 with Account

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

the class LdapProvisioning method makeAccount.

private Account makeAccount(String dn, ZAttributes attrs, MakeObjectOpt makeObjOpt) throws ServiceException {
    String userType = attrs.getAttrString(Provisioning.A_zimbraAccountCalendarUserType);
    boolean isAccount = (userType == null) || userType.equals(AccountCalendarUserType.USER.toString());
    String emailAddress = attrs.getAttrString(Provisioning.A_zimbraMailDeliveryAddress);
    if (emailAddress == null)
        emailAddress = mDIT.dnToEmail(dn, attrs);
    Account acct = (isAccount) ? new LdapAccount(dn, emailAddress, attrs, null, this) : new LdapCalendarResource(dn, emailAddress, attrs, null, this);
    setAccountDefaults(acct, makeObjOpt);
    return acct;
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) LdapCalendarResource(com.zimbra.cs.account.ldap.entry.LdapCalendarResource) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount)

Example 48 with Account

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

the class LdapProvisioning method getAccountByForeignPrincipal.

private Account getAccountByForeignPrincipal(String foreignPrincipal, boolean loadFromMaster) throws ServiceException {
    Account a = accountCache.getByForeignPrincipal(foreignPrincipal);
    // bug 27966, always do a search so dup entries can be thrown
    Account acct = getAccountByQuery(mDIT.mailBranchBaseDN(), filterFactory.accountByForeignPrincipal(foreignPrincipal), null, loadFromMaster);
    // before bug 23372 was fixed.
    if (a == null) {
        a = acct;
        accountCache.put(a);
    }
    return a;
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount)

Example 49 with Account

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

the class LdapProvisioning method getAccountByForeignName.

@Override
public Account getAccountByForeignName(String foreignName, String application, Domain domain) throws ServiceException {
    // first try direct match
    Account acct = getAccountByForeignPrincipal(application + ":" + foreignName);
    if (acct != null)
        return acct;
    if (domain == null) {
        String[] parts = foreignName.split("@");
        if (parts.length != 2)
            return null;
        String domainName = parts[1];
        domain = getDomain(Key.DomainBy.foreignName, application + ":" + domainName, true);
    }
    if (domain == null)
        return null;
    // see if there is a custom hander on the domain
    DomainNameMappingHandler.HandlerConfig handlerConfig = DomainNameMappingHandler.getHandlerConfig(domain, application);
    String acctName;
    if (handlerConfig != null) {
        // invoke the custom handler
        acctName = DomainNameMappingHandler.mapName(handlerConfig, foreignName, domain.getName());
    } else {
        // do our builtin mapping of {localpart}@{zimbra domain name}
        acctName = foreignName.split("@")[0] + "@" + domain.getName();
    }
    return get(AccountBy.name, acctName);
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount)

Example 50 with Account

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

the class BUG_57866 method upgradeQuarantineAccount.

private void upgradeQuarantineAccount(ZLdapContext zlc) throws ServiceException {
    String acctName = prov.getConfig().getAmavisQuarantineAccount();
    if (acctName != null) {
        printer.format("Checking quarantine account %s\n", acctName);
        Account acct = prov.get(AccountBy.name, acctName);
        setIsSystemAccount(zlc, acct);
    }
}
Also used : Account(com.zimbra.cs.account.Account)

Aggregations

Account (com.zimbra.cs.account.Account)1244 Test (org.junit.Test)520 Mailbox (com.zimbra.cs.mailbox.Mailbox)389 OperationContext (com.zimbra.cs.mailbox.OperationContext)292 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)274 Message (com.zimbra.cs.mailbox.Message)255 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)242 Provisioning (com.zimbra.cs.account.Provisioning)222 Element (com.zimbra.common.soap.Element)220 ItemId (com.zimbra.cs.service.util.ItemId)219 ServiceException (com.zimbra.common.service.ServiceException)201 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)158 HashMap (java.util.HashMap)154 Domain (com.zimbra.cs.account.Domain)145 MimeMessage (javax.mail.internet.MimeMessage)104 GuestAccount (com.zimbra.cs.account.GuestAccount)98 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)92 AccountServiceException (com.zimbra.cs.account.AccountServiceException)77 ZMailbox (com.zimbra.client.ZMailbox)72 Header (javax.mail.Header)67