Search in sources :

Example 11 with AccountSelector

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

the class TestAuthentication method testSimpleAuth.

/**
     * test detault auth request with login/password
     * @throws Exception
     */
public void testSimpleAuth() throws Exception {
    //regular auth request
    Account a = TestUtil.getAccount(USER_NAME);
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    AccountSelector acctSel = new AccountSelector(com.zimbra.soap.type.AccountBy.name, a.getName());
    AuthRequest req = new AuthRequest(acctSel, "test123");
    Element resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    AuthResponse authResp = JaxbUtil.elementToJaxb(resp);
    String newAuthToken = authResp.getAuthToken();
    assertNotNull("should have received a new authtoken", newAuthToken);
    AuthToken at = ZimbraAuthToken.getAuthToken(newAuthToken);
    assertTrue("new auth token should be registered", at.isRegistered());
    assertFalse("new auth token should not be expired yet", at.isExpired());
}
Also used : Account(com.zimbra.cs.account.Account) AuthRequest(com.zimbra.soap.account.message.AuthRequest) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) AuthToken(com.zimbra.cs.account.AuthToken) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) AuthResponse(com.zimbra.soap.account.message.AuthResponse)

Example 12 with AccountSelector

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

the class AddGalSyncDataSource method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    AddGalSyncDataSourceRequest dsRequest = JaxbUtil.elementToJaxb(request);
    String name = dsRequest.getName();
    String domainStr = dsRequest.getDomain();
    GalMode type = dsRequest.getType();
    AccountSelector acctSelector = dsRequest.getAccount();
    AccountBy acctBy = acctSelector.getBy();
    String acctValue = acctSelector.getKey();
    String folder = dsRequest.getFolder();
    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);
    }
    if (account == null) {
        throw AccountServiceException.NO_SUCH_ACCOUNT(acctValue);
    }
    if (!Provisioning.onLocalServer(account)) {
        String host = account.getMailHost();
        Server server = prov.getServerByName(host);
        return proxyRequest(request, context, server);
    }
    CreateGalSyncAccount.addDataSource(request, zsc, account, domain, folder, name, type);
    Element response = zsc.createElement(AdminConstants.ADD_GAL_SYNC_DATASOURCE_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) AddGalSyncDataSourceRequest(com.zimbra.soap.admin.message.AddGalSyncDataSourceRequest) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Server(com.zimbra.cs.account.Server) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning) AccountBy(com.zimbra.soap.type.AccountBy)

Example 13 with AccountSelector

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

the class GetShareInfo method doGetShareInfo.

/**
     * @param zsc
     * @param targetAcct
     * @param request
     * @param response
     */
private void doGetShareInfo(ZimbraSoapContext zsc, Map<String, Object> context, Account targetAcct, Element request, GetShareInfoResponse response) throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    GetShareInfoRequest req = JaxbUtil.elementToJaxb(request);
    GranteeChooser granteeChooser = req.getGrantee();
    byte granteeType = getGranteeType(granteeChooser);
    String granteeId = granteeChooser == null ? null : granteeChooser.getId();
    String granteeName = granteeChooser == null ? null : granteeChooser.getName();
    Account owner = null;
    AccountSelector ownerSelector = req.getOwner();
    if (ownerSelector != null) {
        owner = prov.get(ownerSelector);
        // when an invalid user name/id is used.
        if ((owner == null) || (owner.isAccountExternal())) {
            return;
        } else {
            AccountStatus status = owner.getAccountStatus();
            if (status != null && status.isClosed()) {
                return;
            }
        }
    }
    OperationContext octxt = getOperationContext(zsc, context);
    ShareInfo.MountedFolders mountedFolders = null;
    if (!Boolean.TRUE.equals(req.getInternal())) {
        // this (new ShareInfo.MountedFolders) should be executed on the requested
        // account's home server.
        // If we get here, we should be proxied to the right server naturally by the framework.
        mountedFolders = new ShareInfo.MountedFolders(octxt, targetAcct);
    }
    ResultFilter resultFilter;
    if (Boolean.FALSE.equals(req.getIncludeSelf())) {
        resultFilter = new ResultFilterByTargetExcludeSelf(granteeId, granteeName, targetAcct);
    } else {
        resultFilter = new ResultFilterByTarget(granteeId, granteeName);
    }
    String filterDomain = null;
    if (LC.PUBLIC_SHARE_VISIBILITY.samePrimaryDomain.equals(LC.getPublicShareAdvertisingScope())) {
        filterDomain = targetAcct.getDomainName();
    }
    ResultFilter resultFilter2 = new ResultFilterForPublicShares(filterDomain);
    ShareInfoVisitor visitor = new ShareInfoVisitor(prov, response, mountedFolders, resultFilter, resultFilter2);
    if (owner == null) {
        // retrieve from published share info
        ShareInfo.Published.get(prov, targetAcct, granteeType, owner, visitor);
    } else {
        if (targetAcct.getId().equals(owner.getId()))
            throw ServiceException.INVALID_REQUEST("cannot discover shares on self", null);
        if (Provisioning.onLocalServer(owner))
            ShareInfo.Discover.discover(octxt, prov, targetAcct, granteeType, owner, visitor);
        else {
            // issue an GetShareInfoRequest to the home server of the owner, and tell it *not*
            // to proxy to the requesting account's mailbox server.
            fetchRemoteShareInfo(context, request, owner.getId(), visitor);
        }
    }
    visitor.finish();
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) GranteeChooser(com.zimbra.soap.type.GranteeChooser) AccountSelector(com.zimbra.soap.type.AccountSelector) ShareInfo(com.zimbra.cs.account.ShareInfo) Provisioning(com.zimbra.cs.account.Provisioning) AccountStatus(com.zimbra.common.account.ZAttrProvisioning.AccountStatus) GetShareInfoRequest(com.zimbra.soap.account.message.GetShareInfoRequest) PublishedShareInfoVisitor(com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor)

Example 14 with AccountSelector

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

the class GetAccount method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    GetAccountRequest req = JaxbUtil.elementToJaxb(request);
    AccountSelector acctSel = req.getAccount();
    if (acctSel == null) {
        throw ServiceException.INVALID_REQUEST(String.format("missing <%s>", AdminConstants.E_ACCOUNT), null);
    }
    String accountSelectorKey = acctSel.getKey();
    AccountBy by = acctSel.getBy().toKeyAccountBy();
    Account account = prov.get(by, accountSelectorKey, zsc.getAuthToken());
    defendAgainstAccountHarvesting(account, by, accountSelectorKey, zsc, Admin.R_getAccountInfo);
    AdminAccessControl aac = checkAccountRight(zsc, account, AdminRight.PR_ALWAYS_ALLOW);
    Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_RESPONSE);
    boolean applyCos = !Boolean.FALSE.equals(req.isApplyCos());
    Set<String> reqAttrs = getReqAttrs(req.getAttrs(), AttributeClass.account);
    ToXML.encodeAccount(response, account, applyCos, reqAttrs, aac.getAttrRightChecker(account));
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) GetAccountRequest(com.zimbra.soap.admin.message.GetAccountRequest) Provisioning(com.zimbra.cs.account.Provisioning) AccountBy(com.zimbra.common.account.Key.AccountBy)

Aggregations

AccountSelector (com.zimbra.soap.type.AccountSelector)14 Account (com.zimbra.cs.account.Account)9 Element (com.zimbra.common.soap.Element)8 AuthRequest (com.zimbra.soap.account.message.AuthRequest)7 Provisioning (com.zimbra.cs.account.Provisioning)5 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 AuthResponse (com.zimbra.soap.account.message.AuthResponse)4 ServiceException (com.zimbra.common.service.ServiceException)3 AuthToken (com.zimbra.cs.account.AuthToken)3 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)3 Test (org.junit.Test)3 AccountBy (com.zimbra.common.account.Key.AccountBy)2 ZAuthToken (com.zimbra.common.auth.ZAuthToken)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 Domain (com.zimbra.cs.account.Domain)2 Server (com.zimbra.cs.account.Server)2 ChangePasswordRequest (com.zimbra.soap.account.message.ChangePasswordRequest)2 GalMode (com.zimbra.soap.admin.type.GalMode)2 AccountBy (com.zimbra.soap.type.AccountBy)2