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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations