Search in sources :

Example 51 with Account

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

the class BUG_57866 method upgradeHamAccount.

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

Example 52 with Account

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

the class BUG_57866 method upgradeGalSyncAccounts.

private void upgradeGalSyncAccounts(ZLdapContext zlc) throws ServiceException {
    LdapDIT dit = prov.getDIT();
    String[] returnAttrs = new String[] { Provisioning.A_zimbraGalAccountId };
    String base = dit.mailBranchBaseDN();
    String query = "(&(objectclass=zimbraDomain)(zimbraGalAccountId=*))";
    final Set<String> galAcctIds = new HashSet<String>();
    SearchLdapVisitor visitor = new SearchLdapVisitor(false) {

        @Override
        public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
            try {
                String acctId;
                acctId = ldapAttrs.getAttrString(Provisioning.A_zimbraGalAccountId);
                if (acctId != null) {
                    galAcctIds.add(acctId);
                }
            } catch (ServiceException e) {
                printer.printStackTrace("unsble to search domains for GAL sync accounts", e);
            }
        }
    };
    SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), returnAttrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
    zlc.searchPaged(searchOpts);
    for (String galAcctId : galAcctIds) {
        printer.format("Checking GAL sync account %s\n", galAcctId);
        Account acct = prov.get(AccountBy.id, galAcctId);
        setIsSystemAccount(zlc, acct);
    }
}
Also used : LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor) Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) IAttributes(com.zimbra.cs.ldap.IAttributes) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions) HashSet(java.util.HashSet)

Example 53 with Account

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

the class BUG_43147 method upgradeGalSyncAcct.

private void upgradeGalSyncAcct(ZLdapContext zlc, Set<String> galSyncAcctIds) throws ServiceException {
    printer.println();
    printer.println("Upgrading zimbraContactMaxNumEntries on GAL sync accounts ...");
    printer.println();
    HashMap<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraContactMaxNumEntries, "0");
    // got all GAL sync account ids, upgrade them
    for (String id : galSyncAcctIds) {
        Account acct = prov.getAccountById(id);
        if (acct != null) {
            // upgrade only when the gal sync account does not have zimbraContactMaxNumEntries 
            // set on the account entry
            String curValue = acct.getAttr(Provisioning.A_zimbraContactMaxNumEntries, false);
            if (curValue == null) {
                try {
                    printer.println("Account: " + acct.getId() + "(" + acct.getName() + ") - " + "modifying zimbraContactMaxNumEntries to 0");
                    modifyAttrs(zlc, acct, attrs);
                } catch (ServiceException e) {
                    printer.println("Caught ServiceException while modifying GAL sync account entry " + acct.getName());
                    printer.printStackTrace(e);
                }
            } else
                printer.println("Account: " + acct.getId() + "(" + acct.getName() + ") - " + "already has value " + curValue + ", skipping");
        } else {
            printer.println("Account: " + id + " - no such account");
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap)

Example 54 with Account

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

the class OAuthAccessTokenServlet method processRequest.

public void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    try {
        String origUrl = request.getHeader("X-Zimbra-Orig-Url");
        OAuthMessage oAuthMessage = StringUtil.isNullOrEmpty(origUrl) ? OAuthServlet.getMessage(request, null) : OAuthServlet.getMessage(request, origUrl);
        OAuthAccessor accessor = OAuthServiceProvider.getAccessor(oAuthMessage);
        OAuthServiceProvider.VALIDATOR.validateAccTokenMessage(oAuthMessage, accessor);
        // make sure token is authorized
        if (!Boolean.TRUE.equals(accessor.getProperty("authorized"))) {
            OAuthProblemException problem = new OAuthProblemException("permission_denied");
            LOG.debug("permission_denied");
            throw problem;
        }
        AuthToken userAuthToken = ZimbraAuthToken.getAuthToken((String) accessor.getProperty("ZM_AUTH_TOKEN"));
        String accountId = userAuthToken.getAccountId();
        Account account = Provisioning.getInstance().getAccountById(accountId);
        // generate access token and secret
        OAuthServiceProvider.generateAccessToken(accessor);
        account.addForeignPrincipal("oAuthAccessToken:" + accessor.accessToken);
        account.addOAuthAccessor(accessor.accessToken + "::" + new OAuthAccessorSerializer().serialize(accessor));
        response.setContentType("text/plain");
        OutputStream out = response.getOutputStream();
        OAuth.formEncode(OAuth.newList("oauth_token", accessor.accessToken, "oauth_token_secret", accessor.tokenSecret), out);
        out.close();
    } catch (Exception e) {
        LOG.debug("AccessTokenHandler exception", e);
        OAuthServiceProvider.handleException(e, request, response, true);
    }
}
Also used : OAuthAccessor(net.oauth.OAuthAccessor) OAuthProblemException(net.oauth.OAuthProblemException) Account(com.zimbra.cs.account.Account) OAuthMessage(net.oauth.OAuthMessage) OutputStream(java.io.OutputStream) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) AuthToken(com.zimbra.cs.account.AuthToken) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) OAuthProblemException(net.oauth.OAuthProblemException)

Example 55 with Account

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

the class BUG_66387 method fixAccount.

private void fixAccount(String name, String[] allowFromAddresses) throws ServiceException {
    ++numInspected;
    Account account = prov.get(AccountBy.name, name);
    if (account == null) {
        // this shouldn't happen
        printer.println("Account " + name + " not found!  Skipping.");
        return;
    }
    boolean modified = false;
    printer.println("# Account: " + account.getName());
    String[] addrs = account.getAllowFromAddress();
    printer.println("  Current value = " + StringUtil.join(", ", addrs));
    Set<String> remainingAddrs = new HashSet<String>();
    for (String addr : addrs) {
        NamedEntry entry = lookupEntry(addr);
        if (entry instanceof Account) {
            if (!entry.getId().equalsIgnoreCase(account.getId())) {
                doGrant(entry, account, addr);
                modified = true;
            } else {
                printer.println("    - removing redundant address " + addr);
                modified = true;
            }
        } else if (entry instanceof Group) {
            doGrant(entry, account, addr);
            modified = true;
        } else {
            remainingAddrs.add(addr);
        }
    }
    if (modified) {
        Map<String, Object> attrsMap = new HashMap<String, Object>();
        if (!remainingAddrs.isEmpty()) {
            String[] remaining = remainingAddrs.toArray(new String[0]);
            attrsMap.put(Provisioning.A_zimbraAllowFromAddress, remaining);
            printer.println("  New value = " + StringUtil.join(", ", remaining));
        } else {
            attrsMap.put(Provisioning.A_zimbraAllowFromAddress, "");
            printer.println("  New value = <unset>");
        }
        prov.modifyAttrs(account, attrsMap, false, false);
        ++numFixed;
    } else {
        printer.println("  No change needed");
    }
    printer.println();
}
Also used : Account(com.zimbra.cs.account.Account) NamedEntry(com.zimbra.cs.account.NamedEntry) Group(com.zimbra.cs.account.Group) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

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