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);
}
}
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);
}
}
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");
}
}
}
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);
}
}
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();
}
Aggregations