use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class SetServerOffline method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
Element response = zsc.createElement(AdminConstants.SET_SERVER_OFFLINE_RESPONSE);
CuratorManager curator = CuratorManager.getInstance();
if (curator == null) {
return response;
}
Element d = request.getElement(AdminConstants.E_SERVER);
String method = d.getAttribute(AdminConstants.A_BY);
String name = d.getText();
if (name == null || name.equals(""))
throw ServiceException.INVALID_REQUEST("must specify a value for a server", null);
Server server = Provisioning.getInstance().get(Key.ServerBy.fromString(method), name);
try {
curator.unregisterService(server.getId());
} catch (Exception e) {
throw ServiceException.FAILURE("error while unregistering the server", e);
}
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class SearchAutoProvDirectory method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
String query = request.getAttribute(AdminConstants.E_QUERY, null);
String name = request.getAttribute(AdminConstants.E_NAME, null);
if ((query != null) && (name != null)) {
throw ServiceException.INVALID_REQUEST("only one of filter or name can be provided", null);
}
int maxResults = (int) request.getAttributeLong(AdminConstants.A_MAX_RESULTS, SearchDirectory.MAX_SEARCH_RESULTS);
int limit = (int) request.getAttributeLong(AdminConstants.A_LIMIT, Integer.MAX_VALUE);
if (limit == 0) {
limit = Integer.MAX_VALUE;
}
int offset = (int) request.getAttributeLong(AdminConstants.A_OFFSET, 0);
boolean refresh = request.getAttributeBool(AdminConstants.A_REFRESH, false);
String keyAttr = request.getAttribute(AdminConstants.A_KEYATTR);
String attrsStr = request.getAttribute(AdminConstants.A_ATTRS, null);
String[] returnAttrs = null;
if (attrsStr != null) {
Set<String> attrs = new HashSet<String>();
for (String attr : Splitter.on(',').trimResults().split(attrsStr)) {
attrs.add(attr);
}
if (!attrs.contains(keyAttr)) {
attrs.add(keyAttr);
}
returnAttrs = attrs.toArray(new String[attrs.size()]);
}
Element eDomain = request.getElement(AdminConstants.E_DOMAIN);
DomainBy domainBy = DomainBy.fromString(eDomain.getAttribute(AdminConstants.A_BY));
String domainValue = eDomain.getText();
Domain domain = prov.get(domainBy, domainValue);
if (domain == null) {
throw AccountServiceException.NO_SUCH_DOMAIN(domainValue);
}
checkRight(zsc, context, domain, Admin.R_autoProvisionAccount);
AdminSession session = (AdminSession) getSession(zsc, Session.Type.ADMIN);
List<Entry> entryList = null;
if (session != null) {
Cache.Params params = new Cache.Params(domain, query, name, keyAttr, returnAttrs, maxResults);
if (!refresh) {
entryList = Cache.getFromCache(session, params);
}
if (entryList == null) {
entryList = search(domain, query, name, keyAttr, returnAttrs, maxResults);
Cache.putInCache(session, params, entryList);
}
} else {
entryList = search(domain, query, name, keyAttr, returnAttrs, maxResults);
}
Element response = zsc.createElement(AdminConstants.SEARCH_AUTO_PROV_DIRECTORY_RESPONSE);
encodeEntries(response, entryList, keyAttr, offset, limit);
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class SearchCalendarResources method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
int limit = (int) request.getAttributeLong(AdminConstants.A_LIMIT, Integer.MAX_VALUE);
if (limit == 0)
limit = Integer.MAX_VALUE;
int offset = (int) request.getAttributeLong(AdminConstants.A_OFFSET, 0);
String domain = request.getAttribute(AdminConstants.A_DOMAIN, null);
boolean applyCos = request.getAttributeBool(AdminConstants.A_APPLY_COS, true);
String sortBy = request.getAttribute(AdminConstants.A_SORT_BY, null);
boolean sortAscending = request.getAttributeBool(AdminConstants.A_SORT_ASCENDING, true);
String attrsStr = request.getAttribute(AdminConstants.A_ATTRS, null);
String[] attrs = attrsStr == null ? null : attrsStr.split(",");
EntrySearchFilter filter = GalExtraSearchFilter.parseSearchFilter(request);
// Note: isDomainAdminOnly *always* returns false for pure ACL based AccessManager
if (isDomainAdminOnly(zsc)) {
if (domain == null) {
domain = getAuthTokenAccountDomain(zsc).getName();
} else {
checkDomainRight(zsc, domain, AdminRight.PR_ALWAYS_ALLOW);
}
}
Domain d = null;
if (domain != null) {
d = prov.get(Key.DomainBy.name, domain);
if (d == null)
throw AccountServiceException.NO_SUCH_DOMAIN(domain);
}
AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(zsc);
AdminAccessControl.SearchDirectoryRightChecker rightChecker = new AdminAccessControl.SearchDirectoryRightChecker(aac, prov, null);
// filter is not RFC 2254 escaped
// query is RFC 2254 escaped
String query = LdapEntrySearchFilter.toLdapCalendarResourcesFilter(filter);
SearchDirectoryOptions options = new SearchDirectoryOptions();
options.setDomain(d);
options.setTypes(SearchDirectoryOptions.ObjectType.resources);
options.setFilterString(FilterId.ADMIN_SEARCH, query);
options.setReturnAttrs(attrs);
options.setSortOpt(sortAscending ? SortOpt.SORT_ASCENDING : SortOpt.SORT_DESCENDING);
options.setSortAttr(sortBy);
options.setConvertIDNToAscii(true);
List<NamedEntry> resources;
int limitMax = offset + limit;
AdminSession session = (AdminSession) getSession(zsc, Session.Type.ADMIN);
if (session != null) {
resources = session.searchDirectory(options, offset, rightChecker);
} else {
resources = prov.searchDirectory(options);
resources = rightChecker.getAllowed(resources, limitMax);
}
Element response = zsc.createElement(AdminConstants.SEARCH_CALENDAR_RESOURCES_RESPONSE);
int numEntries;
for (numEntries = offset; numEntries < limitMax && numEntries < resources.size(); numEntries++) {
NamedEntry entry = resources.get(numEntries);
ToXML.encodeCalendarResource(response, (CalendarResource) entry, applyCos, null, aac.getAttrRightChecker(entry));
}
response.addAttribute(AdminConstants.A_MORE, numEntries < resources.size());
response.addAttribute(AdminConstants.A_SEARCH_TOTAL, resources.size());
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class SearchGal method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
String domainName = request.getAttribute(AdminConstants.A_DOMAIN);
Provisioning prov = Provisioning.getInstance();
Domain domain = prov.get(Key.DomainBy.name, domainName);
if (domain == null)
throw AccountServiceException.NO_SUCH_DOMAIN(domainName);
checkDomainRight(zsc, domain, Admin.R_accessGAL);
String name = request.getAttribute(AdminConstants.E_NAME, "");
int limit = (int) request.getAttributeLong(AdminConstants.A_LIMIT, 0);
String typeStr = request.getAttribute(AdminConstants.A_TYPE, GalSearchType.account.name());
GalSearchType type = GalSearchType.fromString(typeStr);
String galAcctId = request.getAttribute(AccountConstants.A_GAL_ACCOUNT_ID, null);
String token = request.getAttribute(AdminConstants.A_TOKEN, null);
GalSearchParams params = new GalSearchParams(domain, zsc);
if (token != null)
params.setToken(token);
params.setType(type);
params.setRequest(request);
params.setQuery(name);
params.setLimit(limit);
params.setResponseName(AdminConstants.SEARCH_GAL_RESPONSE);
if (galAcctId != null)
params.setGalSyncAccount(Provisioning.getInstance().getAccountById(galAcctId));
params.setResultCallback(new SearchGal.AdminGalCallback(params));
GalSearchControl gal = new GalSearchControl(params);
if (token != null)
gal.sync();
else
gal.search();
return params.getResultCallback().getResponse();
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class SetCurrentVolume method handle.
private SetCurrentVolumeResponse handle(SetCurrentVolumeRequest req, Map<String, Object> ctx) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(ctx);
checkRight(zsc, ctx, Provisioning.getInstance().getLocalServer(), Admin.R_manageVolume);
short volId = req.getId() > 0 ? req.getId() : Volume.ID_NONE;
VolumeManager.getInstance().setCurrentVolume(req.getType(), volId);
return new SetCurrentVolumeResponse();
}
Aggregations