Search in sources :

Example 96 with Provisioning

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

the class ZimbraLmtpBackend method getAddressStatus.

@Override
public LmtpReply getAddressStatus(LmtpAddress address) {
    String addr = address.getEmailAddress();
    try {
        Provisioning prov = Provisioning.getInstance();
        Account acct = prov.get(AccountBy.name, addr);
        if (acct == null) {
            ZimbraLog.lmtp.info("rejecting address " + addr + ": no account");
            return LmtpReply.NO_SUCH_USER;
        }
        String acctStatus = acct.getAccountStatus(prov);
        if (acctStatus == null) {
            ZimbraLog.lmtp.warn("rejecting address " + addr + ": no account status");
            return LmtpReply.NO_SUCH_USER;
        }
        if (acctStatus.equals(Provisioning.ACCOUNT_STATUS_MAINTENANCE)) {
            ZimbraLog.lmtp.info("try again for address " + addr + ": account status maintenance");
            return LmtpReply.MAILBOX_DISABLED;
        }
        if (Provisioning.onLocalServer(acct)) {
            address.setOnLocalServer(true);
        } else if (Provisioning.getInstance().getServer(acct) != null) {
            address.setOnLocalServer(false);
            address.setRemoteServer(acct.getMailHost());
        } else {
            ZimbraLog.lmtp.warn("try again for address " + addr + ": mailbox is not on this server");
            return LmtpReply.MAILBOX_NOT_ON_THIS_SERVER;
        }
        if (acctStatus.equals(Provisioning.ACCOUNT_STATUS_PENDING)) {
            ZimbraLog.lmtp.info("rejecting address " + addr + ": account status pending");
            return LmtpReply.NO_SUCH_USER;
        }
        if (acctStatus.equals(Provisioning.ACCOUNT_STATUS_CLOSED)) {
            ZimbraLog.lmtp.info("rejecting address " + addr + ": account status closed");
            return LmtpReply.NO_SUCH_USER;
        }
        if (acctStatus.equals(Provisioning.ACCOUNT_STATUS_ACTIVE) || acctStatus.equals(Provisioning.ACCOUNT_STATUS_LOCKOUT) || acctStatus.equals(Provisioning.ACCOUNT_STATUS_LOCKED)) {
            return LmtpReply.RECIPIENT_OK;
        }
        ZimbraLog.lmtp.info("rejecting address " + addr + ": unknown account status " + acctStatus);
        return LmtpReply.NO_SUCH_USER;
    } catch (ServiceException e) {
        if (e.isReceiversFault()) {
            ZimbraLog.lmtp.warn("try again for address " + addr + ": exception occurred", e);
            return LmtpReply.MAILBOX_DISABLED;
        } else {
            ZimbraLog.lmtp.warn("rejecting address " + addr + ": exception occurred", e);
            return LmtpReply.NO_SUCH_USER;
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) DeliveryServiceException(com.zimbra.common.service.DeliveryServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Provisioning(com.zimbra.cs.account.Provisioning)

Example 97 with Provisioning

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

the class MilterServer method main.

public static void main(String[] args) {
    try {
        Provisioning prov = Provisioning.getInstance();
        if (prov instanceof LdapProv) {
            ((LdapProv) prov).waitForLdapServer();
        }
        MilterConfig config = new MilterConfig();
        MilterServer server = new MilterServer(config);
        // register the signal handler
        ClearCacheSignalHandler.register();
        MilterShutdownHook shutdownHook = new MilterShutdownHook(server);
        Runtime.getRuntime().addShutdownHook(shutdownHook);
        ZimbraLog.milter.info("Starting milter server");
        server.start();
    } catch (ServiceException e) {
        ZimbraLog.milter.error("Unable to start milter server", e);
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning) LdapProv(com.zimbra.cs.account.ldap.LdapProv)

Example 98 with Provisioning

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

the class MimeHandlerManager method getIndexedTextLimit.

/**
     * Returns the maximum number of characters that can be returned by
     * {@link MimeHandler#getContent}.
     * @see Provisioning#A_zimbraAttachmentsIndexedTextLimit
     */
public static int getIndexedTextLimit() {
    int length = 1024 * 1024;
    try {
        Provisioning prov = Provisioning.getInstance();
        Server server = prov.getLocalServer();
        length = server.getIntAttr(Provisioning.A_zimbraAttachmentsIndexedTextLimit, length);
    } catch (ServiceException e) {
        sLog.warn("Unable to determine maximum indexed content length", e);
    }
    return length;
}
Also used : Server(com.zimbra.cs.account.Server) ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning)

Example 99 with Provisioning

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

the class DumpSessions method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Server localServer = Provisioning.getInstance().getLocalServer();
    checkRight(zsc, context, localServer, Admin.R_getSessions);
    Element response = zsc.createElement(AdminConstants.DUMP_SESSIONS_RESPONSE);
    boolean includeAccounts = request.getAttributeBool(AdminConstants.A_LIST_SESSIONS, false);
    boolean groupByAccount = request.getAttributeBool(AdminConstants.A_GROUP_BY_ACCOUNT, false);
    int totalActiveSessions = 0;
    Provisioning prov = Provisioning.getInstance();
    for (Session.Type type : Session.Type.values()) {
        if (type == Session.Type.NULL)
            continue;
        if (!includeAccounts) {
            int[] stats = SessionCache.countActive(type);
            if (stats[1] == 0)
                // no active sessions, skip this type!
                continue;
            Element e = response.addElement(type.name().toLowerCase());
            totalActiveSessions += stats[1];
            e.addAttribute(AdminConstants.A_ACTIVE_ACCOUNTS, stats[0]);
            e.addAttribute(AdminConstants.A_ACTIVE_SESSIONS, stats[1]);
        } else {
            List<Session> sessions = SessionCache.getActiveSessions(type);
            if (sessions.size() == 0)
                // no active sessions, skip this type!
                continue;
            Element e = response.addElement(type.name().toLowerCase());
            totalActiveSessions += sessions.size();
            e.addAttribute(AdminConstants.A_ACTIVE_SESSIONS, sessions.size());
            if (sessions.size() == 0)
                continue;
            if (groupByAccount) {
                // stick the sessions into a big map organized by the account ID
                HashMap<String, List<Session>> /*accountid*/
                map = new HashMap<String, List<Session>>();
                for (Session s : sessions) {
                    List<Session> list = map.get(s.getAuthenticatedAccountId());
                    if (list == null) {
                        list = new ArrayList<Session>();
                        map.put(s.getAuthenticatedAccountId(), list);
                    }
                    list.add(s);
                }
                e.addAttribute(AdminConstants.A_ACTIVE_ACCOUNTS, map.size());
                for (Map.Entry<String, List<Session>> entry : map.entrySet()) {
                    Element acctElt = e.addElement(AdminConstants.A_ZIMBRA_ID);
                    acctElt.addAttribute(AdminConstants.A_NAME, getName(prov, entry.getKey()));
                    acctElt.addAttribute(AdminConstants.A_ID, entry.getKey());
                    for (Session s : entry.getValue()) {
                        encodeSession(acctElt, s, false, prov);
                    }
                }
            } else {
                int[] stats = SessionCache.countActive(type);
                e.addAttribute(AdminConstants.A_ACTIVE_ACCOUNTS, stats[0]);
                for (Session s : sessions) {
                    encodeSession(e, s, true, prov);
                }
            }
        }
    }
    response.addAttribute(AdminConstants.A_ACTIVE_SESSIONS, totalActiveSessions);
    return response;
}
Also used : Server(com.zimbra.cs.account.Server) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Session(com.zimbra.cs.session.Session)

Example 100 with Provisioning

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

the class FixCalendarEndTime method getAccountsOnServer.

private static List<NamedEntry> getAccountsOnServer() throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    Server server = prov.getLocalServer();
    String serverName = server.getAttr(Provisioning.A_zimbraServiceHostname);
    SearchAccountsOptions searchOpts = new SearchAccountsOptions(new String[] { Provisioning.A_zimbraId });
    searchOpts.setSortOpt(SortOpt.SORT_DESCENDING);
    List<NamedEntry> accts = prov.searchAccountsOnServer(server, searchOpts);
    ZimbraLog.calendar.info("Found " + accts.size() + " accounts on server " + serverName);
    return accts;
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions) Server(com.zimbra.cs.account.Server) Provisioning(com.zimbra.cs.account.Provisioning)

Aggregations

Provisioning (com.zimbra.cs.account.Provisioning)532 Account (com.zimbra.cs.account.Account)216 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)158 Element (com.zimbra.common.soap.Element)144 ServiceException (com.zimbra.common.service.ServiceException)96 BeforeClass (org.junit.BeforeClass)93 MockProvisioning (com.zimbra.cs.account.MockProvisioning)89 Server (com.zimbra.cs.account.Server)83 HashMap (java.util.HashMap)76 Domain (com.zimbra.cs.account.Domain)70 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)53 Mailbox (com.zimbra.cs.mailbox.Mailbox)50 Cos (com.zimbra.cs.account.Cos)32 Test (org.junit.Test)30 NamedEntry (com.zimbra.cs.account.NamedEntry)25 AuthToken (com.zimbra.cs.account.AuthToken)23 Group (com.zimbra.cs.account.Group)23 ArrayList (java.util.ArrayList)23 AccountServiceException (com.zimbra.cs.account.AccountServiceException)22 DistributionList (com.zimbra.cs.account.DistributionList)22