From: Patrick Schmitz Date: Tue, 6 Mar 2012 01:08:30 +0000 (-0800) Subject: CSPACE-4875 Filled out the kw search support, returning list of items by serviceGroup... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=5b6f64e3e9040c8ea0a6810cb3a76629c5189e10;p=tmp%2Fjakarta-migration.git CSPACE-4875 Filled out the kw search support, returning list of items by serviceGroup. Also supports the meta-group "common". Added security filter to this and to the refObjs call so only searches in services the current user has rights to. --- diff --git a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml index 382565066..296bffd47 100644 --- a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml +++ b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml @@ -68,7 +68,8 @@ but provides tools like keyword search across many types of services. --> - + default-domain + org.collectionspace.services.servicegroup.nuxeo.ServiceGroupDocumentModelHandler diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java index eae2b3da6..bdbead40a 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java @@ -157,5 +157,19 @@ public class ServiceBindingUtils { "getMappedFieldInDoc: Problem fetching: "+propName+" logicalfieldName: "+logicalFieldName+" docModel: "+docModel, ce); } } + + private static ArrayList commonServiceTypes = null; + + public static ArrayList getCommonServiceTypes() { + if(commonServiceTypes == null) { + commonServiceTypes = new ArrayList(); + commonServiceTypes.add(SERVICE_TYPE_AUTHORITY); + commonServiceTypes.add(SERVICE_TYPE_OBJECT); + commonServiceTypes.add(SERVICE_TYPE_PROCEDURE); + } + return commonServiceTypes; + } + + } diff --git a/services/common/src/main/java/org/collectionspace/services/common/security/SecurityUtils.java b/services/common/src/main/java/org/collectionspace/services/common/security/SecurityUtils.java index 92ff4be67..76156efad 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/security/SecurityUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/security/SecurityUtils.java @@ -23,11 +23,18 @@ package org.collectionspace.services.common.security; import java.security.MessageDigest; +import java.util.ArrayList; import java.util.List; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.util.StringTokenizer; +import org.collectionspace.services.authorization.AuthZ; +import org.collectionspace.services.authorization.CSpaceResource; +import org.collectionspace.services.authorization.URIResourceImpl; +import org.collectionspace.services.common.service.ServiceBindingType; +import org.collectionspace.services.common.service.ServiceObjectType; + import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; @@ -188,6 +195,21 @@ public class SecurityUtils { return result; } + public static List getReadableServiceBindingsForCurrentUser( + List serviceBindings) { + ArrayList readableList = + new ArrayList(serviceBindings.size()); + AuthZ authZ = AuthZ.get(); + for(ServiceBindingType binding:serviceBindings) { + String resourceName = binding.getName().toLowerCase(); + CSpaceResource res = new URIResourceImpl(resourceName, "GET"); + if (authZ.isAccessAllowed(res) == true) { + readableList.add(binding); + } + } + return readableList; + } + /** * Checks if is entity is action as a proxy for all sub-resources. * diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java index b0272b0a8..92a016006 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java @@ -58,6 +58,7 @@ import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.repository.RepositoryClient; import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; +import org.collectionspace.services.common.security.SecurityUtils; import org.collectionspace.services.common.service.ServiceBindingType; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.nuxeo.util.NuxeoUtils; @@ -329,6 +330,8 @@ public class RefNameServiceUtils { logger.error("RefNameServiceUtils.getAuthorityRefDocs: No services bindings found, cannot proceed!"); return null; } + // Filter the list for current user rights + servicebindings = SecurityUtils.getReadableServiceBindingsForCurrentUser(servicebindings); // Need to escape the quotes in the refName // TODO What if they are already escaped? diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java index 91ae0a9b2..8d13e45c7 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java @@ -69,6 +69,9 @@ public abstract class DocHandlerBase extends RemoteDocumentModelHandlerImpl extends RemoteDocumentModelHandlerImpl resultsFields = getListItemsArray(); int nFields = resultsFields.size()+NUM_STANDARD_LIST_RESULT_FIELDS; String fields[] = new String[nFields]; - fields[0] = "csid"; - fields[1] = "uri"; - fields[2] = "updatedAt"; + fields[0] = STANDARD_LIST_CSID_FIELD; + fields[1] = STANDARD_LIST_URI_FIELD; + fields[2] = STANDARD_LIST_UPDATED_AT_FIELD; for(int i=NUM_STANDARD_LIST_RESULT_FIELDS;i extends RemoteDocumentModelHandlerImpl getServiceContextFactory() { - return RemoteServiceContextFactory.get(); + return MultipartServiceContextFactory.get(); } + //======================= GET without specifier: List ===================================== + @GET + public AbstractCommonList getList(@Context UriInfo ui) { + try { + CommonList commonList = new CommonList(); + AbstractCommonList list = (AbstractCommonList)commonList; + ServiceContext ctx = createServiceContext(); + String commonSchema = ctx.getCommonPartLabel(); + ArrayList svcGroups = new ArrayList(); + svcGroups.add("procedure"); + svcGroups.add("object"); + svcGroups.add("authority"); + // Fetch the list of groups from the tenant-bindings config, and prepare a list item + // for each one. + // We always declare this a full list, of the size that we are returning. + // Not quite in the spirit of what paging means, but tells callers not to ask for more. + list.setPageNum(0); + list.setPageSize(svcGroups.size()); + list.setItemsInPage(svcGroups.size()); + list.setTotalItems(svcGroups.size()); + String fields[] = new String[2]; + fields[0] = ServiceGroupListItemJAXBSchema.NAME; + fields[1] = ServiceGroupListItemJAXBSchema.URI; + commonList.setFieldsReturned(fields); + HashMap item = new HashMap(); + for(String groupName:svcGroups){ + item.put(ServiceGroupListItemJAXBSchema.NAME, groupName); + String uri = "/" + getServiceName().toLowerCase() + "/" + groupName; + item.put(ServiceGroupListItemJAXBSchema.URI, uri); + commonList.addItem(item); + item.clear(); + } + return list; + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.LIST_FAILED); + } + + } + + //======================= GET ==================================================== // NOTE that csid is not a good name for the specifier, but if we name it anything else, // our AuthZ gets confused!!! @@ -115,7 +168,14 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl { TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader(); // We need to get all the procedures, authorities, and objects. - List servicebindings = tReader.getServiceBindingsByType(ctx.getTenantId(), groupname); + ArrayList groupsList = null; + if("common".equalsIgnoreCase(groupname)) { + groupsList = ServiceBindingUtils.getCommonServiceTypes(); + } else { + groupsList = new ArrayList(); + groupsList.add(groupname); + } + List servicebindings = tReader.getServiceBindingsByType(ctx.getTenantId(), groupsList); if (servicebindings == null || servicebindings.isEmpty()) { // 404 if there are no mappings. Response response = Response.status(Response.Status.NOT_FOUND).entity( @@ -151,44 +211,33 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl { } - //======================= GET without specifier: List ===================================== @GET - public AbstractCommonList getList(@Context UriInfo ui) { + @Path("{csid}/items") + public AbstractCommonList getItems( + @Context UriInfo ui, + @PathParam("csid") String serviceGroupName) { + ensureCSID(serviceGroupName, ResourceBase.READ); + AbstractCommonList list = null; try { - CommonList commonList = new CommonList(); - AbstractCommonList list = (AbstractCommonList)commonList; + MultivaluedMap queryParams = ui.getQueryParameters(); + String keywords = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW); ServiceContext ctx = createServiceContext(); - String commonSchema = ctx.getCommonPartLabel(); - ArrayList svcGroups = new ArrayList(); - svcGroups.add("procedure"); - svcGroups.add("object"); - svcGroups.add("authority"); - // Fetch the list of groups from the tenant-bindings config, and prepare a list item - // for each one. - // We always declare this a full list, of the size that we are returning. - // Not quite in the spirit of what paging means, but tells callers not to ask for more. - list.setPageNum(0); - list.setPageSize(svcGroups.size()); - list.setItemsInPage(svcGroups.size()); - list.setTotalItems(svcGroups.size()); - String fields[] = new String[2]; - fields[0] = ServiceGroupListItemJAXBSchema.NAME; - fields[1] = ServiceGroupListItemJAXBSchema.URI; - commonList.setFieldsReturned(fields); - HashMap item = new HashMap(); - for(String groupName:svcGroups){ - item.put(ServiceGroupListItemJAXBSchema.NAME, groupName); - String uri = "/" + getServiceName().toLowerCase() + "/" + groupName; - item.put(ServiceGroupListItemJAXBSchema.URI, uri); - commonList.addItem(item); - item.clear(); + ServiceGroupDocumentModelHandler handler = (ServiceGroupDocumentModelHandler) + createDocumentHandler(ctx); + ArrayList groupsList = null; + if("common".equalsIgnoreCase(serviceGroupName)) { + groupsList = ServiceBindingUtils.getCommonServiceTypes(); + } else { + groupsList = new ArrayList(); + groupsList.add(serviceGroupName); } - return list; + list = handler.getItemsForGroup(ctx, groupsList, keywords); } catch (Exception e) { - throw bigReThrow(e, ServiceMessages.LIST_FAILED); + throw bigReThrow(e, ServiceMessages.READ_FAILED, serviceGroupName); } - + + return list; } - + }