Search in sources :

Example 41 with AccountServiceException

use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.

the class TestLdapProvExternalLdapAuth method zimbraAuthNonSSHA.

@Test
public void zimbraAuthNonSSHA() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    String PASSWORD = InMemoryLdapServer.Password.genNonSSHAPassword("not-ssha-blah");
    // modify userPassword via modifyAccount, not changePassword
    Map<String, Object> acctAttrs = new HashMap<String, Object>();
    acctAttrs.put(Provisioning.A_userPassword, PASSWORD);
    prov.modifyAttrs(acct, acctAttrs);
    // good password
    prov.authAccount(acct, PASSWORD, AuthContext.Protocol.test);
    // bad password
    boolean caughtException = false;
    try {
        prov.authAccount(acct, PASSWORD + "not", AuthContext.Protocol.test);
    } catch (AccountServiceException e) {
        if (AccountServiceException.AUTH_FAILED.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    provUtil.deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) AccountServiceException(com.zimbra.cs.account.AccountServiceException) HashMap(java.util.HashMap) ProvTest(com.zimbra.qa.unittest.prov.ProvTest)

Example 42 with AccountServiceException

use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.

the class TestLdapProvDistributionList method createDistributionListAlreadyExists.

@Test
public void createDistributionListAlreadyExists() throws Exception {
    String DL_NAME_LOCALPART = Names.makeDLNameLocalPart(genGroupNameLocalPart());
    DistributionList dl = createDistributionList(DL_NAME_LOCALPART);
    boolean caughtException = false;
    try {
        prov.createDistributionList(dl.getName(), new HashMap<String, Object>());
    } catch (AccountServiceException e) {
        if (AccountServiceException.DISTRIBUTION_LIST_EXISTS.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    deleteDistributionList(dl);
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) DistributionList(com.zimbra.cs.account.DistributionList)

Example 43 with AccountServiceException

use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.

the class TestProvAttr method testDurationAttr.

@Test
public void testDurationAttr() throws Exception {
    Server server = getServer();
    String attrName = Provisioning.A_zimbraHsmAge;
    String strValue;
    long msValue;
    long secValue;
    Map<String, Object> attrs = new HashMap<String, Object>();
    // nnnnn([hmsd]|ms)
    // d (day)
    attrs.put(attrName, "1d");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1d", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(Constants.MILLIS_PER_DAY, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(Constants.SECONDS_PER_DAY, secValue);
    // h (hour)
    attrs.put(attrName, "1h");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1h", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(Constants.MILLIS_PER_HOUR, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(Constants.SECONDS_PER_HOUR, secValue);
    // m (minute)
    attrs.put(attrName, "1m");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1m", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(Constants.MILLIS_PER_MINUTE, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(Constants.SECONDS_PER_MINUTE, secValue);
    // s (second)
    attrs.put(attrName, "1s");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1s", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(Constants.MILLIS_PER_SECOND, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(1, secValue);
    // default (== s)
    attrs.put(attrName, "1");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(Constants.MILLIS_PER_SECOND, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(1, secValue);
    // ms (milli second)
    attrs.put(attrName, "1ms");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1ms", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(1, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(0, secValue);
    attrs.put(attrName, "500ms");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("500ms", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(500, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(1, secValue);
    attrs.put(attrName, "1000ms");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1000ms", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(1000, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(1, secValue);
    attrs.put(attrName, "1001ms");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1001ms", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(1001, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(1, secValue);
    attrs.put(attrName, "999ms");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("999ms", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(999, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(1, secValue);
    attrs.put(attrName, "0ms");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("0ms", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(0, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(0, secValue);
    // invalid unit
    boolean good = false;
    attrs.put(attrName, "1y");
    try {
        prov.modifyAttrs(server, attrs);
    } catch (AccountServiceException e) {
        if (AccountServiceException.INVALID_ATTR_VALUE.equals(e.getCode()))
            good = true;
    }
    assertTrue(good);
    good = false;
    attrs.put(attrName, "1mm");
    try {
        prov.modifyAttrs(server, attrs);
    } catch (AccountServiceException e) {
        if (AccountServiceException.INVALID_ATTR_VALUE.equals(e.getCode()))
            good = true;
    }
    assertTrue(good);
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) Server(com.zimbra.cs.account.Server) HashMap(java.util.HashMap)

Example 44 with AccountServiceException

use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.

the class TestLdapProvZimlet method createZimletAlreadyExists.

@Test
public void createZimletAlreadyExists() throws Exception {
    String ZIMLET_NAME = Names.makeZimletName(genZimletName());
    Zimlet zimlet = createZimlet(ZIMLET_NAME);
    boolean caughtException = false;
    try {
        Map<String, Object> attrs = new HashMap<String, Object>();
        attrs.put(Provisioning.A_zimbraZimletVersion, "1.0");
        zimlet = prov.createZimlet(ZIMLET_NAME, attrs);
    } catch (AccountServiceException e) {
        if (AccountServiceException.ZIMLET_EXISTS.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    deleteZimlet(zimlet);
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) Zimlet(com.zimbra.cs.account.Zimlet) HashMap(java.util.HashMap)

Aggregations

AccountServiceException (com.zimbra.cs.account.AccountServiceException)44 ServiceException (com.zimbra.common.service.ServiceException)22 LdapException (com.zimbra.cs.ldap.LdapException)20 LdapEntryAlreadyExistException (com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException)20 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)20 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)19 Account (com.zimbra.cs.account.Account)14 ZMutableEntry (com.zimbra.cs.ldap.ZMutableEntry)14 CallbackContext (com.zimbra.cs.account.callback.CallbackContext)13 Date (java.util.Date)13 Domain (com.zimbra.cs.account.Domain)10 HashMap (java.util.HashMap)10 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)8 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)5 Cos (com.zimbra.cs.account.Cos)4 Test (org.junit.Test)4 DistributionList (com.zimbra.cs.account.DistributionList)3 GuestAccount (com.zimbra.cs.account.GuestAccount)3 Server (com.zimbra.cs.account.Server)3 Signature (com.zimbra.cs.account.Signature)3