Search in sources :

Example 1 with CreateAccountRequest

use of com.zimbra.soap.admin.message.CreateAccountRequest in project zm-mailbox by Zimbra.

the class TestDomainAdmin method createAdminConsoleStyleDomainAdmin.

public String createAdminConsoleStyleDomainAdmin(String domAdminName) throws ServiceException {
    List<Attr> attrs = Lists.newArrayList();
    attrs.add(new Attr(Provisioning.A_zimbraIsDelegatedAdminAccount, "TRUE"));
    attrs.add(new Attr(Provisioning.A_zimbraAdminConsoleUIComponents, "accountListView"));
    attrs.add(new Attr(Provisioning.A_zimbraAdminConsoleUIComponents, "downloadsView"));
    attrs.add(new Attr(Provisioning.A_zimbraAdminConsoleUIComponents, "DLListView"));
    attrs.add(new Attr(Provisioning.A_zimbraAdminConsoleUIComponents, "aliasListView"));
    attrs.add(new Attr(Provisioning.A_zimbraAdminConsoleUIComponents, "resourceListView"));
    attrs.add(new Attr(Provisioning.A_zimbraAdminConsoleUIComponents, "saveSearch"));
    CreateAccountRequest caReq = new CreateAccountRequest(domAdminName, TestUtil.DEFAULT_PASSWORD, attrs);
    CreateAccountResponse caResp = adminSoapProv.invokeJaxb(caReq);
    assertNotNull("CreateAccountResponse for " + domAdminName, caResp);
    grantRight(adminSoapProv, TargetType.domain, ADMINISTERED_DOMAIN, domAdminName, RightConsts.RT_domainAdminConsoleRights);
    grantRight(adminSoapProv, TargetType.global, "globalacltarget", domAdminName, RightConsts.RT_domainAdminZimletRights);
    grantRight(adminSoapProv, TargetType.global, "globalacltarget", domAdminName, RightConsts.RT_adminLoginCalendarResourceAs);
    adminSoapProv.flushCache(CacheEntryType.acl, null);
    return caResp.getAccount().getId();
}
Also used : CreateAccountRequest(com.zimbra.soap.admin.message.CreateAccountRequest) CreateAccountResponse(com.zimbra.soap.admin.message.CreateAccountResponse) Attr(com.zimbra.soap.admin.type.Attr)

Example 2 with CreateAccountRequest

use of com.zimbra.soap.admin.message.CreateAccountRequest in project zm-mailbox by Zimbra.

the class TestCookieReuse method testUnauthorizedAdminPostWithCsrf.

/**
 * Verify that we CANNOT make an admin POST request by reusing a valid csrf-enabled cookie without a csrf token
 */
@Test
public void testUnauthorizedAdminPostWithCsrf() throws Exception {
    AuthToken at = AuthProvider.getAdminAuthToken();
    at.setCsrfTokenEnabled(true);
    SoapTransport transport = TestUtil.getAdminSoapTransport();
    transport.setAuthToken(at.getEncoded());
    Map<String, Object> attrs = null;
    CreateAccountRequest request = new CreateAccountRequest(UNAUTHORIZED_USER, "test123", attrs);
    try {
        transport.invoke(JaxbUtil.jaxbToElement(request));
    } catch (ServiceException e) {
        Assert.assertEquals("should be catching AUTH EXPIRED here", ServiceException.AUTH_REQUIRED, e.getCode());
        return;
    }
    Assert.fail("should have caught an exception");
}
Also used : CreateAccountRequest(com.zimbra.soap.admin.message.CreateAccountRequest) ServiceException(com.zimbra.common.service.ServiceException) AuthToken(com.zimbra.cs.account.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 3 with CreateAccountRequest

use of com.zimbra.soap.admin.message.CreateAccountRequest in project zm-mailbox by Zimbra.

the class JaxbToElementTest method jaxbSubclassFixupTest.

/**
 * Check that @{link JaxbUtil.elementToJaxb} will accept XML where
 * JAXB expects various attributes that have been specified as elements.
 * Ensure that attributes in elements of superclasses are handled
 * In this case:
 *                  <a><n>attrName1</n></a>
 * should be recognised as meaning:
 *                  <a n="attrName1"></a>
 * @throws Exception
 */
@Test
public void jaxbSubclassFixupTest() throws Exception {
    Element rootElem = Element.XMLElement.mFactory.createElement(AdminConstants.CREATE_ACCOUNT_REQUEST);
    // JAXB Attribute E_NAME
    rootElem.addNonUniqueElement(AdminConstants.E_NAME).addText("acctName");
    // JAXB Attribute E_PASSWORD
    rootElem.addNonUniqueElement(AdminConstants.E_PASSWORD).addText("AcctPassword");
    // JAXB Element E_A ---> Attr (actually a List)
    Element a1 = rootElem.addNonUniqueElement(AdminConstants.E_A);
    // JAXB Attribute A_N
    a1.addNonUniqueElement(AdminConstants.A_N).addText("attrName1");
    // value can't be set when we've specified an attribute as an element
    CreateAccountRequest req = JaxbUtil.elementToJaxb(rootElem);
    Assert.assertEquals("Account name", "acctName", req.getName());
    Assert.assertEquals("Account Password", "AcctPassword", req.getPassword());
    List<Attr> attrs = req.getAttrs();
    Assert.assertEquals("Number of attrs", 1, attrs.size());
    Assert.assertEquals("attr 1 name", "attrName1", attrs.get(0).getKey());
    Assert.assertEquals("attr 1 value", "", attrs.get(0).getValue());
}
Also used : CreateAccountRequest(com.zimbra.soap.admin.message.CreateAccountRequest) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) JAXBElement(javax.xml.bind.JAXBElement) Attr(com.zimbra.soap.admin.type.Attr) Test(org.junit.Test)

Example 4 with CreateAccountRequest

use of com.zimbra.soap.admin.message.CreateAccountRequest in project zm-mailbox by Zimbra.

the class CreateAccount method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    CreateAccountRequest req = zsc.elementToJaxb(request);
    String name = req.getName().toLowerCase();
    Map<String, Object> attrs = req.getAttrsAsOldMultimap(true);
    checkDomainRightByEmail(zsc, name, Admin.R_createAccount);
    checkSetAttrsOnCreate(zsc, TargetType.account, name, attrs);
    checkCos(zsc, attrs);
    Account account = prov.createAccount(name, req.getPassword(), attrs);
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "CreateAccount", "name", name }, attrs));
    Element response = zsc.createElement(AdminConstants.CREATE_ACCOUNT_RESPONSE);
    ToXML.encodeAccount(response, account);
    return response;
}
Also used : CreateAccountRequest(com.zimbra.soap.admin.message.CreateAccountRequest) Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Example 5 with CreateAccountRequest

use of com.zimbra.soap.admin.message.CreateAccountRequest in project zm-mailbox by Zimbra.

the class TestDomainAdmin method testViaGroupDelegatedAdminAssignSendToDistList.

/**
 * Test that delegated admin with adminConsoleDLACLTabRights can grant sendToDistList right
 * @throws Exception
 */
@Test
public void testViaGroupDelegatedAdminAssignSendToDistList() throws Exception {
    String domAdminGroupId = createAdminConsoleStyleDomainAdminGroup(DOMADMINGROUP);
    CreateAccountResponse caResp;
    List<Attr> attrs = Lists.newArrayList();
    attrs.add(new Attr(Provisioning.A_zimbraIsDelegatedAdminAccount, "TRUE"));
    CreateAccountRequest caReq = new CreateAccountRequest(DOMADMIN, TestUtil.DEFAULT_PASSWORD, attrs);
    caResp = adminSoapProv.invokeJaxb(caReq);
    assertNotNull("CreateAccountResponse for " + DOMADMIN + " Admin", caResp);
    AddDistributionListMemberResponse adlmResp;
    adlmResp = adminSoapProv.invokeJaxb(new AddDistributionListMemberRequest(domAdminGroupId, Lists.newArrayList(DOMADMIN)));
    assertNotNull("AddDistributionListMemberResponse for " + DOMADMIN + " Admin", adlmResp);
    adminSoapProv.createAccount(TARGET_ACCT, TestUtil.DEFAULT_PASSWORD, null);
    SoapProvisioning domAdminSoapProv = getSoapProvisioning(DOMADMIN, TestUtil.DEFAULT_PASSWORD);
    CreateDistributionListResponse cdlResp;
    cdlResp = domAdminSoapProv.invokeJaxb(new CreateDistributionListRequest(TARGET_DL));
    assertNotNull("CreateDistributionListResponse for " + TARGET_DL + " simple as domAdmin", cdlResp);
    cdlResp = adminSoapProv.invokeJaxb(new CreateDistributionListRequest(DIFF_DL));
    assertNotNull("CreateDistributionListResponse for " + TARGET_DL + " simple as domAdmin", cdlResp);
    failToGrantRight(domAdminSoapProv, TargetType.dl, TARGET_DL, TARGET_ACCT, RightConsts.RT_sendToDistList, "permission denied: insufficient right to grant 'sendToDistList' right");
    grantRight(adminSoapProv, TargetType.domain, ADMINISTERED_DOMAIN, GranteeType.grp, DOMADMINGROUP, RightConsts.RT_adminConsoleDLACLTabRights);
    grantRight(domAdminSoapProv, TargetType.dl, TARGET_DL, TARGET_ACCT, RightConsts.RT_sendToDistList);
    /* Check that doesn't allow it for a dl in a different domain */
    failToGrantRight(domAdminSoapProv, TargetType.dl, DIFF_DL, TARGET_ACCT, RightConsts.RT_sendToDistList, "permission denied: insufficient right to grant 'sendToDistList' right");
}
Also used : CreateAccountResponse(com.zimbra.soap.admin.message.CreateAccountResponse) CreateAccountRequest(com.zimbra.soap.admin.message.CreateAccountRequest) AddDistributionListMemberResponse(com.zimbra.soap.admin.message.AddDistributionListMemberResponse) AddDistributionListMemberRequest(com.zimbra.soap.admin.message.AddDistributionListMemberRequest) CreateDistributionListRequest(com.zimbra.soap.admin.message.CreateDistributionListRequest) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) CreateDistributionListResponse(com.zimbra.soap.admin.message.CreateDistributionListResponse) Attr(com.zimbra.soap.admin.type.Attr) Test(org.junit.Test)

Aggregations

CreateAccountRequest (com.zimbra.soap.admin.message.CreateAccountRequest)7 Test (org.junit.Test)5 CreateAccountResponse (com.zimbra.soap.admin.message.CreateAccountResponse)3 Attr (com.zimbra.soap.admin.type.Attr)3 ZAuthToken (com.zimbra.common.auth.ZAuthToken)2 ServiceException (com.zimbra.common.service.ServiceException)2 Element (com.zimbra.common.soap.Element)2 SoapTransport (com.zimbra.common.soap.SoapTransport)2 AuthToken (com.zimbra.cs.account.AuthToken)2 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)2 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)2 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 Account (com.zimbra.cs.account.Account)1 Provisioning (com.zimbra.cs.account.Provisioning)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 AddAccountAliasRequest (com.zimbra.soap.admin.message.AddAccountAliasRequest)1 AddAccountAliasResponse (com.zimbra.soap.admin.message.AddAccountAliasResponse)1 AddDistributionListMemberRequest (com.zimbra.soap.admin.message.AddDistributionListMemberRequest)1