use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class ModifyIdentity method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);
Identity identity = null;
if (!canModifyOptions(zsc, account))
throw ServiceException.PERM_DENIED("can not modify options");
Provisioning prov = Provisioning.getInstance();
Element eIdentity = request.getElement(AccountConstants.E_IDENTITY);
Map<String, Object> attrs = AccountService.getAttrs(eIdentity, AccountConstants.A_NAME);
// remove anything that doesn't start with zimbraPref. ldap will also do additional checks
for (Iterator<String> it = attrs.keySet().iterator(); it.hasNext(); ) if (// if this changes, make sure we don't let them ever change objectclass
!it.next().toLowerCase().startsWith("zimbrapref"))
it.remove();
String key, id = eIdentity.getAttribute(AccountConstants.A_ID, null);
if (id != null) {
identity = prov.get(account, Key.IdentityBy.id, key = id);
} else {
identity = prov.get(account, Key.IdentityBy.name, key = eIdentity.getAttribute(AccountConstants.A_NAME));
}
if (identity == null) {
String[] childIds = account.getChildAccount();
for (String childId : childIds) {
Account childAccount = prov.get(AccountBy.id, childId, zsc.getAuthToken());
if (childAccount != null) {
Identity childIdentity;
if (id != null) {
childIdentity = prov.get(childAccount, Key.IdentityBy.id, key = id);
} else {
childIdentity = prov.get(childAccount, Key.IdentityBy.name, key = eIdentity.getAttribute(AccountConstants.A_NAME));
}
if (childIdentity != null) {
identity = childIdentity;
account = childAccount;
break;
}
}
}
}
if (identity == null)
throw AccountServiceException.NO_SUCH_IDENTITY(key);
prov.modifyIdentity(account, identity.getName(), attrs);
Element response = zsc.createElement(AccountConstants.MODIFY_IDENTITY_RESPONSE);
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class ModifyProperties method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);
if (!canModifyOptions(zsc, account)) {
throw ServiceException.PERM_DENIED("can not modify options");
}
ZimletUserProperties props = ZimletUserProperties.getProperties(account);
int numUserproperties = request.listElements(AccountConstants.E_PROPERTY).size();
if (numUserproperties > account.getLongAttr(Provisioning.A_zimbraZimletUserPropertiesMaxNumEntries, 150)) {
throw AccountServiceException.TOO_MANY_ZIMLETUSERPROPERTIES();
}
for (Element e : request.listElements(AccountConstants.E_PROPERTY)) {
props.setProperty(e.getAttribute(AccountConstants.A_ZIMLET), e.getAttribute(AccountConstants.A_NAME), e.getText());
}
props.saveProperties(account);
Element response = zsc.createElement(AccountConstants.MODIFY_PROPERTIES_RESPONSE);
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class ResetPassword method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
if (!checkPasswordSecurity(context)) {
throw ServiceException.INVALID_REQUEST("clear text password is not allowed", null);
}
Provisioning prov = Provisioning.getInstance();
ZimbraSoapContext zsc = getZimbraSoapContext(context);
ResetPasswordRequest req = JaxbUtil.elementToJaxb(request);
req.validateResetPasswordRequest();
AuthToken at = zsc.getAuthToken();
AuthProvider.validateAuthToken(prov, at, false);
Account acct = at.getAccount();
boolean locked = acct.getBooleanAttr(Provisioning.A_zimbraPasswordLocked, false);
if (locked) {
throw AccountServiceException.PASSWORD_LOCKED();
}
ResetPasswordUtil.validateFeatureResetPasswordStatus(acct);
String newPassword = req.getPassword();
checkPasswordStrength(prov, acct, newPassword);
// proxy if required
if (!Provisioning.onLocalServer(acct)) {
try {
return proxyRequest(request, context, acct.getId());
} catch (ServiceException e) {
// if something went wrong proxying the request, just execute it locally
if (ServiceException.PROXY_ERROR.equals(e.getCode())) {
ZimbraLog.account.warn("encountered proxy error", e);
} else {
// but if it's a real error, it's a real error
throw e;
}
}
}
setPasswordAndPurgeAuthTokens(prov, acct, newPassword);
Element response = zsc.createElement(AccountConstants.E_RESET_PASSWORD_RESPONSE);
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class SubscribeDistributionList method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
Account acct = getRequestedAccount(zsc);
if (!canAccessAccount(zsc, acct)) {
throw ServiceException.PERM_DENIED("can not access account");
}
Element response = zsc.createElement(AccountConstants.SUBSCRIBE_DISTRIBUTION_LIST_RESPONSE);
Group group = getGroupBasic(request, prov);
SubscribeDistributionListHandler handler = new SubscribeDistributionListHandler(group, request, response, prov, acct);
handler.handle();
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class GetAccountInfo method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Element a = request.getElement(AccountConstants.E_ACCOUNT);
String key = a.getAttribute(AccountConstants.A_BY);
String value = a.getText();
if (Strings.isNullOrEmpty(value)) {
throw ServiceException.INVALID_REQUEST("no text specified for the " + AccountConstants.E_ACCOUNT + " element", null);
}
Provisioning prov = Provisioning.getInstance();
Account account = prov.get(AccountBy.fromString(key), value, zsc.getAuthToken());
// prevent directory harvest attack, mask no such account as permission denied
if (account == null)
throw ServiceException.PERM_DENIED("can not access account");
Element response = zsc.createElement(AccountConstants.GET_ACCOUNT_INFO_RESPONSE);
response.addAttribute(AccountConstants.E_NAME, account.getName(), Element.Disposition.CONTENT);
response.addKeyValuePair(Provisioning.A_zimbraId, account.getId(), AccountConstants.E_ATTR, AccountConstants.A_NAME);
response.addKeyValuePair(Provisioning.A_zimbraMailHost, account.getAttr(Provisioning.A_zimbraMailHost), AccountConstants.E_ATTR, AccountConstants.A_NAME);
response.addKeyValuePair(Provisioning.A_displayName, account.getAttr(Provisioning.A_displayName), AccountConstants.E_ATTR, AccountConstants.A_NAME);
addUrls(response, account);
return response;
}
Aggregations