Search in sources :

Example 91 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class RenameCos method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext lc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    String id = request.getElement(AdminConstants.E_ID).getText();
    String newName = request.getElement(AdminConstants.E_NEW_NAME).getText();
    Cos cos = prov.get(Key.CosBy.id, id);
    if (cos == null)
        throw AccountServiceException.NO_SUCH_COS(id);
    // check if the admin can rename the cos
    checkRight(lc, context, cos, Admin.R_renameCos);
    String oldName = cos.getName();
    prov.renameCos(id, newName);
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "RenameCos", "name", oldName, "newName", newName }));
    // get again with new name...
    cos = prov.get(Key.CosBy.id, id);
    if (cos == null)
        throw ServiceException.FAILURE("unabled to get renamed cos: " + id, null);
    Element response = lc.createElement(AdminConstants.RENAME_COS_RESPONSE);
    GetCos.encodeCos(response, cos);
    return response;
}
Also used : ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Cos(com.zimbra.cs.account.Cos) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Example 92 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class ResetAllLoggers method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    LogFactory.reset();
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Element response = zsc.createElement(AdminConstants.RESET_ALL_LOGGERS_RESPONSE);
    return response;
}
Also used : ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element)

Example 93 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class RemoveDistributionListAlias method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    RemoveDistributionListAliasRequest req = JaxbUtil.elementToJaxb(request);
    String id = req.getId();
    String alias = req.getAlias();
    Group group = getGroupFromContext(context);
    String dlName = "";
    try {
        defendAgainstGroupHarvesting(group, DistributionListBy.id, id, zsc, Admin.R_removeGroupAlias, Admin.R_removeDistributionListAlias);
    } catch (AccountServiceException ase) {
    // still may want to remove the alias, even if it doesn't point at anything
    // note: if we got a permission denied instead of AccountServiceException,
    //       means we don't have the rights so shouldn't get any further
    }
    if (group != null) {
        dlName = group.getName();
    }
    // if the admin can remove an alias in the domain
    checkDomainRightByEmail(zsc, alias, Admin.R_deleteAlias);
    // even if dl is null, we still invoke removeAlias and throw an exception afterwards.
    // this is so dangling aliases can be cleaned up as much as possible
    prov.removeGroupAlias(group, alias);
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "RemoveDistributionListAlias", "name", dlName, "alias", alias }));
    if (group == null) {
        throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(id);
    }
    return zsc.jaxbToElement(new RemoveDistributionListAliasResponse());
}
Also used : Group(com.zimbra.cs.account.Group) AccountServiceException(com.zimbra.cs.account.AccountServiceException) RemoveDistributionListAliasResponse(com.zimbra.soap.admin.message.RemoveDistributionListAliasResponse) RemoveDistributionListAliasRequest(com.zimbra.soap.admin.message.RemoveDistributionListAliasRequest) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Provisioning(com.zimbra.cs.account.Provisioning)

Example 94 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class CreateCos method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    String name = request.getElement(AdminConstants.E_NAME).getText().toLowerCase();
    Map<String, Object> attrs = AdminService.getAttrs(request);
    checkRight(zsc, context, null, Admin.R_createCos);
    checkSetAttrsOnCreate(zsc, TargetType.cos, name, attrs);
    Cos cos = prov.createCos(name, attrs);
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "CreateCos", "name", name }, attrs));
    Element response = zsc.createElement(AdminConstants.CREATE_COS_RESPONSE);
    GetCos.encodeCos(response, cos);
    return response;
}
Also used : ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Cos(com.zimbra.cs.account.Cos) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Example 95 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class CreateGalSyncAccount method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    CreateGalSyncAccountRequest cgaRequest = JaxbUtil.elementToJaxb(request);
    String name = cgaRequest.getName();
    String domainStr = cgaRequest.getDomain();
    GalMode type = cgaRequest.getType();
    AccountSelector acctSelector = cgaRequest.getAccount();
    AccountBy acctBy = acctSelector.getBy();
    String acctValue = acctSelector.getKey();
    String password = cgaRequest.getPassword();
    String folder = cgaRequest.getFolder();
    String mailHost = cgaRequest.getMailHost();
    Domain domain = prov.getDomainByName(domainStr);
    if (domain == null) {
        throw AccountServiceException.NO_SUCH_DOMAIN(domainStr);
    }
    Account account = null;
    try {
        account = prov.get(acctBy.toKeyAccountBy(), acctValue, zsc.getAuthToken());
    } catch (ServiceException se) {
        ZimbraLog.gal.warn("error checking GalSyncAccount", se);
    }
    // create the system account if not already exists.
    if (account == null) {
        if (acctBy != AccountBy.name) {
            throw AccountServiceException.NO_SUCH_ACCOUNT(acctValue);
        }
        // there should be one gal sync account per domain per mailhost
        for (String acctId : domain.getGalAccountId()) {
            Account acct = prov.getAccountById(acctId);
            if ((acct != null) && (acct.getMailHost().equals(mailHost))) {
                throw AccountServiceException.ACCOUNT_EXISTS(acct.getName());
            }
        }
        // XXX revisit
        checkDomainRightByEmail(zsc, acctValue, Admin.R_createAccount);
        Map<String, Object> accountAttrs = new HashMap<String, Object>();
        StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraIsSystemResource, LdapConstants.LDAP_TRUE);
        StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraIsSystemAccount, LdapConstants.LDAP_TRUE);
        StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraHideInGal, LdapConstants.LDAP_TRUE);
        StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraContactMaxNumEntries, "0");
        StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraMailHost, mailHost);
        checkSetAttrsOnCreate(zsc, TargetType.account, acctValue, accountAttrs);
        account = prov.createAccount(acctValue, password, accountAttrs);
    }
    if (!Provisioning.onLocalServer(account)) {
        String host = account.getMailHost();
        Server server = prov.getServerByName(host);
        return proxyRequest(request, context, server);
    }
    addDataSource(request, zsc, account, domain, folder, name, type);
    Element response = zsc.createElement(AdminConstants.CREATE_GAL_SYNC_ACCOUNT_RESPONSE);
    ToXML.encodeAccount(response, account, false, emptySet, null);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) GalMode(com.zimbra.soap.admin.type.GalMode) Server(com.zimbra.cs.account.Server) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) Provisioning(com.zimbra.cs.account.Provisioning) CreateGalSyncAccountRequest(com.zimbra.soap.admin.message.CreateGalSyncAccountRequest) AccountBy(com.zimbra.soap.type.AccountBy) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Domain(com.zimbra.cs.account.Domain)

Aggregations

ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)382 Element (com.zimbra.common.soap.Element)315 Provisioning (com.zimbra.cs.account.Provisioning)162 Account (com.zimbra.cs.account.Account)158 Mailbox (com.zimbra.cs.mailbox.Mailbox)106 OperationContext (com.zimbra.cs.mailbox.OperationContext)82 ItemId (com.zimbra.cs.service.util.ItemId)58 Server (com.zimbra.cs.account.Server)47 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)44 ServiceException (com.zimbra.common.service.ServiceException)40 HashMap (java.util.HashMap)37 Domain (com.zimbra.cs.account.Domain)32 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)23 IOException (java.io.IOException)20 Group (com.zimbra.cs.account.Group)17 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)17 Message (com.zimbra.cs.mailbox.Message)17 MimeMessage (javax.mail.internet.MimeMessage)16 Map (java.util.Map)15