Search in sources :

Example 36 with SoapHttpTransport

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

the class TestAutoProvision method authRequestByPreauth.

/*
     * Note: need to restart server each time before re-run.  Otherwise server would still 
     * have the account created in previous run cached.
     */
@Test
public void authRequestByPreauth() throws Exception {
    String testName = getTestName();
    String externalPassword = "test456";
    String extAcctLocalPart = testName;
    String extAcctName = createExternalAcctEntry(extAcctLocalPart, externalPassword, null);
    Map<String, Object> zimbraDomainAttrs = commonZimbraDomainAttrs();
    // setup auto prov
    // commonZimbraDomainAttrs added only LDAP, add preauth here
    StringUtil.addToMultiMap(zimbraDomainAttrs, Provisioning.A_zimbraAutoProvAuthMech, AutoProvAuthMech.PREAUTH.name());
    zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchBase, extDomainDn);
    zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchFilter, "(uid=%u)");
    // setup external LDAP auth
    zimbraDomainAttrs.put(Provisioning.A_zimbraAuthMech, AuthMech.ldap.name());
    zimbraDomainAttrs.put(Provisioning.A_zimbraAuthLdapURL, "ldap://localhost:389");
    zimbraDomainAttrs.put(Provisioning.A_zimbraAuthLdapBindDn, "uid=%u,ou=people," + extDomainDn);
    // setup preauth
    String preAuthKey = PreAuthKey.generateRandomPreAuthKey();
    zimbraDomainAttrs.put(Provisioning.A_zimbraPreAuthKey, preAuthKey);
    Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
    String loginName = extAcctLocalPart + "@" + zimbraDomain.getName();
    // preauth data
    HashMap<String, String> params = new HashMap<String, String>();
    String authBy = "name";
    long timestamp = System.currentTimeMillis();
    long expires = 0;
    params.put("account", loginName);
    params.put("by", authBy);
    params.put("timestamp", timestamp + "");
    params.put("expires", expires + "");
    String preAuth = PreAuthKey.computePreAuth(params, preAuthKey);
    // make the soap request
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    Element request = Element.create(transport.getRequestProtocol(), AccountConstants.AUTH_REQUEST);
    request.addElement(AccountConstants.E_ACCOUNT).addAttribute(AccountConstants.A_BY, authBy).setText(loginName);
    Element ePreAuth = request.addElement(AccountConstants.E_PREAUTH).setText(preAuth);
    ePreAuth.addAttribute(AccountConstants.A_TIMESTAMP, timestamp);
    ePreAuth.addAttribute(AccountConstants.A_EXPIRES, expires);
    Element response = transport.invoke(request);
    String encodedAuthToken = response.getElement(AccountConstants.E_AUTH_TOKEN).getText();
    assertNotNull(encodedAuthToken);
    String acctId = getAuthTokenAcctId(encodedAuthToken);
    Account acct = prov.get(AccountBy.id, acctId);
    verifyAcctAutoProvisioned(acct, loginName.toLowerCase());
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) Domain(com.zimbra.cs.account.Domain) Test(org.junit.Test)

Example 37 with SoapHttpTransport

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

the class TestAutoProvision method authRequestByPassword.

/* ========================
     * SOAP and servlets tests
     * ========================
     */
/*
     * Note: need to restart server each time before re-run.  Otherwise server would still 
     * have the account created in previous run cached.
     */
@Test
public void authRequestByPassword() throws Exception {
    String testName = getTestName();
    String externalPassword = "test456";
    String extAcctLocalPart = testName;
    String extAcctName = createExternalAcctEntry(extAcctLocalPart, externalPassword, null);
    Map<String, Object> zimbraDomainAttrs = commonZimbraDomainAttrs();
    // setup auto prov
    zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchBase, extDomainDn);
    zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchFilter, "(uid=%u)");
    // setup external LDAP auth
    zimbraDomainAttrs.put(Provisioning.A_zimbraAuthMech, AuthMech.ldap.name());
    zimbraDomainAttrs.put(Provisioning.A_zimbraAuthLdapURL, "ldap://localhost:389");
    zimbraDomainAttrs.put(Provisioning.A_zimbraAuthLdapBindDn, "uid=%u,ou=people," + extDomainDn);
    Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
    String loginName = extAcctLocalPart + "@" + zimbraDomain.getName();
    // make the soap request
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    Element request = Element.create(transport.getRequestProtocol(), AccountConstants.AUTH_REQUEST);
    request.addElement(AccountConstants.E_ACCOUNT).addAttribute(AccountConstants.A_BY, AccountBy.name.name()).setText(loginName);
    request.addElement(AccountConstants.E_PASSWORD).setText(externalPassword);
    Element response = transport.invoke(request);
    String encodedAuthToken = response.getElement(AccountConstants.E_AUTH_TOKEN).getText();
    assertNotNull(encodedAuthToken);
    String acctId = getAuthTokenAcctId(encodedAuthToken);
    Account acct = prov.get(AccountBy.id, acctId);
    verifyAcctAutoProvisioned(acct, loginName.toLowerCase());
}
Also used : Account(com.zimbra.cs.account.Account) Element(com.zimbra.common.soap.Element) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) Domain(com.zimbra.cs.account.Domain) Test(org.junit.Test)

Example 38 with SoapHttpTransport

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

the class SoapTest method authUser.

/**
     * @param name
     * @param csrfEnabled
     * @return
     * @throws IOException
     * @throws ServiceException
     */
public static SoapTransport authUser(String acctName, boolean csrfEnabled, boolean setCsrfToken) throws ServiceException, IOException {
    com.zimbra.soap.type.AccountSelector acct = new com.zimbra.soap.type.AccountSelector(com.zimbra.soap.type.AccountBy.name, acctName);
    SoapHttpTransport transport = new SoapHttpTransport("http://localhost:7070/service/soap/");
    transport.setHttpDebugListener(soapDebugListener);
    AuthRequest req = new AuthRequest(acct, PASSWORD);
    req.setCsrfSupported(csrfEnabled);
    AuthResponse resp = invokeJaxb(transport, req);
    transport.setAuthToken(resp.getAuthToken());
    if (setCsrfToken) {
        transport.setCsrfToken(resp.getCsrfToken());
    }
    return transport;
}
Also used : AuthRequest(com.zimbra.soap.account.message.AuthRequest) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) AuthResponse(com.zimbra.soap.account.message.AuthResponse)

Example 39 with SoapHttpTransport

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

the class SoapTest method authAdmin.

public static SoapTransport authAdmin(String acctName, String password) throws Exception {
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
    transport.setHttpDebugListener(soapDebugListener);
    com.zimbra.soap.admin.message.AuthRequest req = new com.zimbra.soap.admin.message.AuthRequest(acctName, password);
    com.zimbra.soap.admin.message.AuthResponse resp = invokeJaxb(transport, req);
    transport.setAuthToken(resp.getAuthToken());
    return transport;
}
Also used : AuthRequest(com.zimbra.soap.account.message.AuthRequest) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport)

Example 40 with SoapHttpTransport

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

the class TestAuth method attrsReturnedInAuthResponse.

@Test
public void attrsReturnedInAuthResponse() throws Exception {
    String ATTR_NAME = Provisioning.A_zimbraFeatureExternalFeedbackEnabled;
    String ATTR_VALUE = ProvisioningConstants.TRUE;
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(ATTR_NAME, ATTR_VALUE);
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain, attrs);
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    transport.setHttpDebugListener(new SoapDebugListener());
    com.zimbra.soap.type.AccountSelector acctSel = new com.zimbra.soap.type.AccountSelector(com.zimbra.soap.type.AccountBy.name, acct.getName());
    AuthRequest req = new AuthRequest(acctSel, "test123");
    req.addAttr(ATTR_NAME);
    AuthResponse resp = invokeJaxb(transport, req);
    Set<String> result = Sets.newHashSet();
    for (Attr attr : resp.getAttrs()) {
        String attrName = attr.getName();
        String attrValue = attr.getValue();
        result.add(Verify.makeResultStr(attrName, attrValue));
    }
    Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(ATTR_NAME, ATTR_VALUE)), result);
    /*
         * test the auth by auth toke npath
         */
    String authTokenStr = resp.getAuthToken();
    AuthToken authToken = new AuthToken(authTokenStr, Boolean.FALSE);
    req = new AuthRequest();
    req.setAuthToken(authToken);
    req.addAttr(ATTR_NAME);
    transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    transport.setHttpDebugListener(new SoapDebugListener());
    resp = invokeJaxb(transport, req);
    result = Sets.newHashSet();
    for (Attr attr : resp.getAttrs()) {
        String attrName = attr.getName();
        String attrValue = attr.getValue();
        result.add(Verify.makeResultStr(attrName, attrValue));
    }
    Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(ATTR_NAME, ATTR_VALUE)), result);
}
Also used : Account(com.zimbra.cs.account.Account) AuthRequest(com.zimbra.soap.account.message.AuthRequest) AccountSelector(com.zimbra.soap.type.AccountSelector) Attr(com.zimbra.soap.account.type.Attr) AuthResponse(com.zimbra.soap.account.message.AuthResponse) AccountSelector(com.zimbra.soap.type.AccountSelector) ZAuthToken(com.zimbra.common.auth.ZAuthToken) AuthToken(com.zimbra.soap.account.type.AuthToken) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) Test(org.junit.Test)

Aggregations

SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)69 Element (com.zimbra.common.soap.Element)54 Test (org.junit.Test)32 SoapFaultException (com.zimbra.common.soap.SoapFaultException)16 ServiceException (com.zimbra.common.service.ServiceException)13 Account (com.zimbra.cs.account.Account)13 DeployZimletRequest (com.zimbra.soap.admin.message.DeployZimletRequest)13 AuthRequest (com.zimbra.soap.account.message.AuthRequest)12 AttachmentIdAttrib (com.zimbra.soap.admin.type.AttachmentIdAttrib)12 XMLElement (com.zimbra.common.soap.Element.XMLElement)11 AuthToken (com.zimbra.cs.account.AuthToken)10 ZAuthToken (com.zimbra.common.auth.ZAuthToken)8 AuthResponse (com.zimbra.soap.account.message.AuthResponse)8 IOException (java.io.IOException)8 ZMailbox (com.zimbra.client.ZMailbox)7 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)6 AccountSelector (com.zimbra.soap.type.AccountSelector)6 HashMap (java.util.HashMap)5 Domain (com.zimbra.cs.account.Domain)4 Server (com.zimbra.cs.account.Server)4