Search in sources :

Example 11 with Identity

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

the class TestLdapProvIdentity method modifyIdentity.

@Test
public void modifyIdentity() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    String IDENTITYE_NAME = Names.makeIdentityName(genIdentityName());
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    Identity identity = createIdentity(acct, IDENTITYE_NAME);
    Map<String, Object> attrs = new HashMap<String, Object>();
    String MODIFIED_ATTR_NAME = Provisioning.A_zimbraPrefFromDisplay;
    String MODIFIED_ATTR_VALUE = "modifyIdentity";
    attrs.put(MODIFIED_ATTR_NAME, MODIFIED_ATTR_VALUE);
    prov.modifyIdentity(acct, identity.getName(), attrs);
    acct = getFresh(acct);
    identity = prov.get(acct, Key.IdentityBy.name, IDENTITYE_NAME);
    assertEquals(MODIFIED_ATTR_VALUE, identity.getAttr(MODIFIED_ATTR_NAME));
    deleteIdentity(acct, identity);
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) Identity(com.zimbra.cs.account.Identity) Test(org.junit.Test)

Example 12 with Identity

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

the class TestLdapProvIdentity method createIdentityAlreadyExists.

@Test
public void createIdentityAlreadyExists() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    String IDENTITY_NAME = Names.makeIdentityName(genIdentityName());
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    Identity identity = createIdentity(acct, IDENTITY_NAME);
    boolean caughtException = false;
    try {
        createIdentityRaw(acct, IDENTITY_NAME);
    } catch (AccountServiceException e) {
        if (AccountServiceException.IDENTITY_EXISTS.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    deleteIdentity(acct, identity);
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) AccountServiceException(com.zimbra.cs.account.AccountServiceException) Identity(com.zimbra.cs.account.Identity) Test(org.junit.Test)

Example 13 with Identity

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

the class TestLdapProvIdentity method renameIdentity.

@Test
public void renameIdentity() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    String IDENTITYE_NAME = Names.makeIdentityName(genIdentityName());
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    Identity identity = createIdentity(acct, IDENTITYE_NAME);
    Map<String, Object> attrs = new HashMap<String, Object>();
    // modifying zimbraPrefIdentityName will rename the identity and trigger a LDAP moddn
    String MODIFIED_ATTR_NAME = Provisioning.A_zimbraPrefIdentityName;
    String NEW_IDENTITY_NAME = genIdentityName("new");
    String MODIFIED_ATTR_VALUE = NEW_IDENTITY_NAME;
    attrs.put(MODIFIED_ATTR_NAME, MODIFIED_ATTR_VALUE);
    prov.modifyIdentity(acct, identity.getName(), attrs);
    acct = getFresh(acct);
    identity = prov.get(acct, Key.IdentityBy.name, NEW_IDENTITY_NAME);
    assertEquals(MODIFIED_ATTR_VALUE, identity.getAttr(MODIFIED_ATTR_NAME));
    deleteIdentity(acct, identity);
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) Identity(com.zimbra.cs.account.Identity) Test(org.junit.Test)

Example 14 with Identity

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

the class TestLdapProvIdentity method getIdentity.

@Test
public void getIdentity() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    String IDENTITYE_NAME = Names.makeIdentityName(genIdentityName());
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    Identity identity = createIdentity(acct, IDENTITYE_NAME);
    String identityId = identity.getId();
    acct = getFresh(acct);
    identity = prov.get(acct, Key.IdentityBy.id, identityId);
    assertNotNull(identity);
    acct = getFresh(acct);
    identity = prov.get(acct, Key.IdentityBy.name, IDENTITYE_NAME);
    assertNotNull(identity);
    deleteIdentity(acct, identity);
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) Identity(com.zimbra.cs.account.Identity) Test(org.junit.Test)

Example 15 with Identity

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

the class DeleteIdentity method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);
    if (!canModifyOptions(zsc, account))
        throw ServiceException.PERM_DENIED("can not modify options");
    Provisioning prov = Provisioning.getInstance();
    Element eIdentity = request.getElement(AccountConstants.E_IDENTITY);
    // identity can be specified by name or by ID
    Identity ident = null;
    String idStr = eIdentity.getAttribute(AccountConstants.A_ID, null);
    if (idStr != null) {
        ident = prov.get(account, Key.IdentityBy.id, idStr);
    } else {
        idStr = eIdentity.getAttribute(AccountConstants.A_NAME);
        ident = prov.get(account, Key.IdentityBy.name, idStr);
    }
    if (ident != null)
        Provisioning.getInstance().deleteIdentity(account, ident.getName());
    else
        throw AccountServiceException.NO_SUCH_IDENTITY(idStr);
    Element response = zsc.createElement(AccountConstants.DELETE_IDENTITY_RESPONSE);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Identity(com.zimbra.cs.account.Identity) Provisioning(com.zimbra.cs.account.Provisioning)

Aggregations

Identity (com.zimbra.cs.account.Identity)29 Account (com.zimbra.cs.account.Account)17 Test (org.junit.Test)7 ServiceException (com.zimbra.common.service.ServiceException)5 AccountServiceException (com.zimbra.cs.account.AccountServiceException)5 ArrayList (java.util.ArrayList)5 Element (com.zimbra.common.soap.Element)4 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)4 LdapIdentity (com.zimbra.cs.account.ldap.entry.LdapIdentity)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 HashMap (java.util.HashMap)4 Provisioning (com.zimbra.cs.account.Provisioning)3 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)3 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)2 Signature (com.zimbra.cs.account.Signature)2 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)2 Date (java.util.Date)2 Locale (java.util.Locale)2 Address (javax.mail.Address)2 InternetAddress (javax.mail.internet.InternetAddress)2