List of usage examples for javax.xml.registry RegistryException RegistryException
public RegistryException(Throwable cause)
JAXRException
object initialized with the given Throwable
object. From source file:it.cnr.icar.eric.server.lcm.LifeCycleManagerImpl.java
/** * Calculates the effective user to be used as the identity of the * requestor. Implements ability to re-assign user to a different user than * the caller if:// w ww. j av a 2 s. co m * * a) The actual caller is a RegistryAdministrator role, and b) The request * specifies the CANONICAL_SLOT_LCM_OWNER. * */ @SuppressWarnings("static-access") void calculateEffectiveUser(ServerRequestContext context) throws RegistryException { try { UserType caller = (context).getUser(); // See if CANONICAL_SLOT_LCM_OWNER defined on request HashMap<String, Object> slotsMap = bu.getSlotsFromRequest((context).getCurrentRegistryRequest()); String effectiveUserId = (String) slotsMap.get(bu.CANONICAL_SLOT_LCM_OWNER); if (effectiveUserId != null) { if (ac.hasRegistryAdministratorRole(caller)) { UserType effectiveUser = (UserType) pm.getRegistryObject((context), effectiveUserId, "User"); if (effectiveUser == null) { throw new RegistryException(ServerResourceBundle.getInstance() .getString("message.specifiedUserNotOwner", new Object[] { effectiveUserId })); } (context).setUser(effectiveUser); } else { throw new InvalidRequestException(ServerResourceBundle.getInstance() .getString("message.requestSlotInvalid", new Object[] { bu.CANONICAL_SLOT_LCM_OWNER })); } } } catch (javax.xml.bind.JAXBException e) { throw new RegistryException(e); } catch (InvalidRequestException e) { throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.query.CompressContentQueryFilterPlugin.java
protected Collection<ExtrinsicObjectType> getAllImportedEOs(ExtrinsicObjectType targetEO, ServerRequestContext serverContext, int depth) throws RegistryException { ArrayList<ExtrinsicObjectType> eoList = new ArrayList<ExtrinsicObjectType>(); try {//w ww. ja v a2s.c o m ReferenceResolver refResolver = new ReferenceResolverImpl(); // Support this parameter: urn:oasis:names:tc:ebxml-regrep:rs:depthParameter Collection<?> objRefs = refResolver.getReferencedObjects(serverContext, targetEO, depth); if (objRefs != null) { Iterator<?> objRefItr = objRefs.iterator(); while (objRefItr.hasNext()) { Object obj = objRefItr.next(); if (obj instanceof ExtrinsicObjectType) { ExtrinsicObjectType dependentEO = (ExtrinsicObjectType) obj; if (!eoList.contains(dependentEO)) { eoList.add(dependentEO); } } } } } catch (Throwable t) { throw new RegistryException(t); } return eoList; }
From source file:it.cnr.icar.eric.server.persistence.rdb.SQLPersistenceManagerImpl.java
private void sortRegistryObjects(List<IdentifiableType> registryObjects, List<AssociationType1> associations, List<AuditableEventType> auditableEvents, List<ClassificationType> classifications, List<ClassificationSchemeType> schemes, List<ClassificationNodeType> classificationNodes, List<ExternalIdentifierType> externalIds, List<ExternalLinkType> externalLinks, List<ExtrinsicObjectType> extrinsicObjects, List<FederationType> federations, List<ObjectRefType> objectRefs, List<OrganizationType> organizations, List<RegistryPackageType> packages, List<ServiceBindingType> serviceBindings, List<ServiceType> services, List<SpecificationLinkType> specificationLinks, List<AdhocQueryType> adhocQuerys, List<SubscriptionType> subscriptions, List<UserType> users, List<PersonType> persons, List<RegistryType> registrys) throws RegistryException { associations.clear();/*from w w w . j ava 2s .c om*/ auditableEvents.clear(); classifications.clear(); schemes.clear(); classificationNodes.clear(); externalIds.clear(); externalLinks.clear(); extrinsicObjects.clear(); federations.clear(); objectRefs.clear(); organizations.clear(); packages.clear(); serviceBindings.clear(); services.clear(); specificationLinks.clear(); adhocQuerys.clear(); subscriptions.clear(); users.clear(); persons.clear(); registrys.clear(); Iterator<IdentifiableType> objIter = registryObjects.iterator(); while (objIter.hasNext()) { // IdentifiableType obj = (IdentifiableType) objIter.next(); Object obj = objIter.next(); if (obj instanceof AssociationType1) { associations.add((AssociationType1) obj); } else if (obj instanceof AuditableEventType) { auditableEvents.add((AuditableEventType) obj); } else if (obj instanceof ClassificationType) { classifications.add((ClassificationType) obj); } else if (obj instanceof ClassificationSchemeType) { schemes.add((ClassificationSchemeType) obj); } else if (obj instanceof ClassificationNodeType) { classificationNodes.add((ClassificationNodeType) obj); } else if (obj instanceof ExternalIdentifierType) { externalIds.add((ExternalIdentifierType) obj); } else if (obj instanceof ExternalLinkType) { externalLinks.add((ExternalLinkType) obj); } else if (obj instanceof ExtrinsicObjectType) { extrinsicObjects.add((ExtrinsicObjectType) obj); } else if (obj instanceof FederationType) { federations.add((FederationType) obj); } else if (obj instanceof ObjectRefType) { objectRefs.add((ObjectRefType) obj); } else if (obj instanceof OrganizationType) { organizations.add((OrganizationType) obj); } else if (obj instanceof RegistryType) { registrys.add((RegistryType) obj); } else if (obj instanceof RegistryPackageType) { packages.add((RegistryPackageType) obj); } else if (obj instanceof ServiceBindingType) { serviceBindings.add((ServiceBindingType) obj); } else if (obj instanceof ServiceType) { services.add((ServiceType) obj); } else if (obj instanceof AdhocQueryType) { adhocQuerys.add((AdhocQueryType) obj); } else if (obj instanceof FilterQueryType) { adhocQuerys.add((AdhocQueryType) obj); } else if (obj instanceof SpecificationLinkType) { specificationLinks.add((SpecificationLinkType) obj); } else if (obj instanceof SubscriptionType) { subscriptions.add((SubscriptionType) obj); } else if (obj instanceof UserType) { users.add((UserType) obj); } else if (obj instanceof PersonType) { persons.add((PersonType) obj); } else if (obj instanceof RegistryType) { registrys.add((RegistryType) obj); } else { throw new RegistryException(CommonResourceBundle.getInstance() .getString("message.unexpectedObjectType", new Object[] { obj.getClass().getName(), "org.oasis.ebxml.registry.bindings.rim.IdentifiableType" })); } } }
From source file:it.cnr.icar.eric.server.interfaces.soap.RegistryBSTServlet.java
private RepositoryItem processIncomingAttachment(AttachmentPart ap) throws RegistryException { RepositoryItem ri = null;//from w ww . j a va 2s . c om try { //ContentId is the id of the repositoryItem String id = WSS4JSecurityUtilBST.convertContentIdToUUID(ap.getContentId()); if (log.isInfoEnabled()) { log.info(ServerResourceBundle.getInstance().getString("message.ProcessingAttachmentWithContentId", new Object[] { id })); } if (log.isDebugEnabled()) { log.debug("Processing attachment (RepositoryItem):\n" + ap.getContent().toString()); } DataHandler dh = ap.getDataHandler(); ri = new RepositoryItemImpl(id, dh); } catch (SOAPException e) { RegistryException toThrow = new RegistryException(e); toThrow.initCause(e); throw toThrow; } return ri; }
From source file:it.cnr.icar.eric.server.security.authorization.AuthorizationServiceImpl.java
/** * Check if user is authorized to perform specified request using V3 * specification.//from w ww . ja v a2 s .co m * <p> * Check if the specified User (requestor) is authorized to make this * request or not. The initial subject lists contains the object in the * request is a resource. The primary action is determined by the type of * request. In addition * * <ul> * <li> * <b><i>AdhocQueryRequest: </i></b> Process query as normal and then filter * out objects that should not be visible to the client.</li> * <li> * <b><i>ApproveObjectRequest: </i></b> Check if subject is authorized for * the approve action.</li> * <li> * <b><i>Deprecate/UndeprecateRequest: </i></b> Check if subject is * authorized for the deprecate/undeprecate action.</li> * <li> * <b><i>RemoveObjectRequest: </i></b> Check if subject is authorized for * the delete action.</li> * <li> * <b><i>SubmitObjectsRequest/UpdateObjectsRequest: </i></b> Check if * subject authorized for the create action. Check any referenced objects * and see if their policies allows reference action.</li> * </ul> * * @todo Do we need any new Attribute types by Extending AttributeValue * (have string URI etc.)?? * @todo Do we need any new functions?? * * @throws RegistryException */ @SuppressWarnings({ "static-access", "deprecation" }) public AuthorizationResult checkAuthorization(ServerRequestContext context) throws RegistryException { try { RegistryRequestType registryRequest = context.getCurrentRegistryRequest(); if (null == context.getUser()) { // Set context user as RegistryGuest built in context.setUser(ac.registryGuest); } String userId = context.getUser().getId(); AuthorizationResult authRes = new AuthorizationResult(userId); boolean isAdmin = context.isRegistryAdministrator(); if (isAdmin) { // Allow RegistryAdmin role all privileges return authRes; } Set<Subject> subjects = new HashSet<Subject>(); Set<Attribute> actions = new HashSet<Attribute>(); Set<Attribute> environment = new HashSet<Attribute>(); Attribute actionAttr = null; boolean readOnly = false; String action = bu.getActionFromRequest(registryRequest); actionAttr = new Attribute(new URI(ACTION_ATTRIBUTE_ID), new URI(StringAttribute.identifier), null, null, new StringAttribute(action)); // Determine the action attributes. if (registryRequest instanceof AdhocQueryRequest) { readOnly = true; } actions.add(actionAttr); // Init subject attributes HashSet<Attribute> userSubjectAttributes = new HashSet<Attribute>(); Attribute idSubjectAttr = new Attribute(new URI(SUBJECT_ATTRIBUTE_ID), new URI(AnyURIAttribute.identifier), null, null, new AnyURIAttribute(new URI(userId))); userSubjectAttributes.add(idSubjectAttr); Attribute userSubjectAttr = new Attribute(new URI(SUBJECT_ATTRIBUTE_USER), new URI(ObjectAttribute.identifier), null, null, new ObjectAttribute(context.getUser())); userSubjectAttributes.add(userSubjectAttr); Subject userSubject = new Subject(new URI(AttributeDesignator.SUBJECT_CATEGORY_DEFAULT), userSubjectAttributes); subjects.add(userSubject); // Pass RequestContext as an environment attribute Attribute requestEnvAttr = new Attribute(new URI(ENVIRONMENT_ATTRIBUTE_REQUEST_CONTEXT), new URI(ObjectAttribute.identifier), null, null, new ObjectAttribute(context)); environment.add(requestEnvAttr); // Iterate over each resource and see if action is authorized on the // resource by the subject ArrayList<String> ids = new ArrayList<String>(); if (registryRequest instanceof AdhocQueryRequest) { // For AdhocQueryRequest query is already done and result is in // queryResults. Now do access control check on queryResults. Iterator<?> iter = context.getQueryResults().iterator(); while (iter.hasNext()) { IdentifiableType ro = (IdentifiableType) iter.next(); ids.add(ro.getId()); } } else { ids.addAll(bu.getIdsFromRequest(registryRequest)); } // Optimization: Get ownersMap in a single query and cache it @SuppressWarnings("unused") HashMap<String, String> ownersMap = getOwnersMap(context, ids); Iterator<String> idsIter = ids.iterator(); while (idsIter.hasNext()) { String id = idsIter.next(); if (id != null) { if ((!readOnly) && (id.equals(idForDefaultACP))) { // Auth check for defaultACP is special and requires // that // it is submitted by RegistryAdministrator role. // Note this will be generalized when we have better // Role Based Access Control (RBAC) support if (!isAdmin) { String msg = getExceptionMessage( "message.error.authorization.allowedOnlyToAdmin.defineDefaultACP", id, context.getUser(), getActionString(actions)); throw new UnauthorizedRequestException(id, context.getUser().getId(), getActionString(actions), msg); } } else { try { checkAuthorizationForResource(context, id, subjects, actions, environment); authRes.addPermittedResource(id); } catch (UnauthorizedRequestException ure) { authRes.addDeniedResourceException(ure); } catch (RegistryException re) { if (re.getCause() instanceof UnauthorizedRequestException) { authRes.addDeniedResourceException((UnauthorizedRequestException) re.getCause()); } else { throw re; } } } } else { @SuppressWarnings("unused") int i = 0; } } log.debug("userId=" + userId + " is " + (authRes.getResult() == AuthorizationResult.PERMIT_NONE ? "not " : "") + "allowed to perform the requested operation."); return authRes; } catch (URISyntaxException e) { throw new RegistryException(e); } catch (AuthorizationException e) { throw e; } catch (JAXRException e) { throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.persistence.rdb.AbstractDAO.java
/** * Unmarshalls a "spilled over" RepositoryItem into a String * * @param spillOverId the id of the ExtrinsicObject associated with the RepositoryItem * used to unmarshal the "spilled over" content from. *///from w w w .ja v a 2 s .c o m public String unmarshallFromRepositoryItem(String spillOverId) throws RegistryException { String content = spillOverId; InputStream is = null; try { RepositoryItem ri = rm.getRepositoryItem(spillOverId); content = it.cnr.icar.eric.common.Utility.getInstance() .unmarshalInputStreamToString(ri.getDataHandler().getInputStream()); } catch (IOException e) { throw new RegistryException(e); } finally { if (is != null) { try { is.close(); } catch (Exception e) { log.error(e, e); } } } return content; }
From source file:it.cnr.icar.eric.server.interfaces.rest.URLHandler.java
/** * Writes XML RepositoryItems as a RepositoryItemList. Ignores any other * type of RepositoryItem.s//from w w w .j a v a 2s . co m */ void writeRepositoryItems(List<?> eos) throws IOException, RegistryException, ObjectNotFoundException { ServerRequestContext context = new ServerRequestContext("URLHandler.writeRepositoryItem", null); ServletOutputStream sout = response.getOutputStream(); boolean doCommit = false; try { RepositoryItemListType ebRepositoryItemListType = bu.lcmFac.createRepositoryItemListType(); Iterator<?> iter = eos.iterator(); while (iter.hasNext()) { ExtrinsicObjectType eo = (ExtrinsicObjectType) iter.next(); String id = eo.getId(); RepositoryItem ri = QueryManagerFactory.getInstance().getQueryManager().getRepositoryItem(context, id); if (ri == null) { throw new ObjectNotFoundException(id, ServerResourceBundle.getInstance().getString("message.repositoryItem")); } else { if (eo.getMimeType().equals("text/xml")) { DataHandler dataHandler = ri.getDataHandler(); InputStream fStream = dataHandler.getInputStream(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(fStream); Element rootElement = document.getDocumentElement(); ebRepositoryItemListType.getAny().add(rootElement); } } } // javax.xml.bind.Marshaller marshaller = // bu.lcmFac.createMarshaller(); javax.xml.bind.Marshaller marshaller = bu.getJAXBContext().createMarshaller(); marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); JAXBElement<RepositoryItemListType> ebRepositoryItemList = bu.lcmFac .createRepositoryItemList(ebRepositoryItemListType); marshaller.marshal(ebRepositoryItemList, sout); doCommit = true; } catch (JAXBException e) { throw new RegistryException(e); } catch (ParserConfigurationException e) { throw new RegistryException(e); } catch (SAXException e) { throw new RegistryException(e); } finally { if (sout != null) { sout.close(); sout = null; } try { closeContext(context, doCommit); } catch (Exception ex) { log.error(ex, ex); } } }
From source file:it.cnr.icar.eric.server.repository.hibernate.HibernateRepositoryManager.java
/** * Updates a RepositoryItem.//w w w . j av a 2 s . c om */ public void update(ServerRequestContext context, RepositoryItem item) throws RegistryException { Transaction tx = null; ExtrinsicObjectType eo = (ExtrinsicObjectType) context.getRegistryObject(item.getId(), "ExtrinsicObject"); String lid = eo.getLid(); String versionName = null; try { SessionContext sc = hu.getSessionContext(); Session s = sc.getSession(); tx = s.beginTransaction(); VersionInfoType contentVersionInfo = eo.getContentVersionInfo(); if (contentVersionInfo == null) { contentVersionInfo = bu.rimFac.createVersionInfoType(); eo.setContentVersionInfo(contentVersionInfo); } versionName = eo.getContentVersionInfo().getVersionName(); // if item does not exists, error String findByID = "from RepositoryItemBean as rib where rib.key.lid = ? AND rib.key.versionName = ? "; Object[] params = { lid, versionName }; Type[] types = { Hibernate.STRING, Hibernate.STRING }; List<?> results = s.find(findByID, params, types); if (results.isEmpty()) { throw new RepositoryItemNotFoundException(lid, versionName); } // Writing out the RepositoryItem itself byte contentBytes[] = readBytes(item.getDataHandler().getInputStream()); RepositoryItemBean bean = (RepositoryItemBean) results.get(0); RepositoryItemKey key = new RepositoryItemKey(lid, versionName); bean.setKey(key); if (needsOracleHack) { doOracleHackForUpdate(s, bean, contentBytes); // do not call save after this } else { if (isBlobSupported) { bean.setBlobContent(Hibernate.createBlob(contentBytes)); } else { bean.setBinaryContent(contentBytes); } } if (log.isDebugEnabled()) { String message = "Updating repository item:" + "lid='" + lid + "', " + "versionName='" + versionName + "', "; if (isBlobSupported) { message += "content size=" + bean.getBlobContent().length(); } else { message += "content size=" + bean.getBinaryContent().length; } log.debug(message); } if (!needsOracleHack) { s.update(bean); } tx.commit(); s.refresh(bean); } catch (RegistryException e) { tryRollback(tx); throw e; } catch (Exception e) { String msg = ServerResourceBundle.getInstance().getString("message.FailedToUpdateRepositoryItem", new Object[] { lid, versionName }); log.error(e, e); tryRollback(tx); throw new RegistryException(ServerResourceBundle.getInstance().getString("message.seeLogsForDetails", new Object[] { msg })); } finally { tryClose(); } }
From source file:it.cnr.icar.eric.server.common.ServerRequestContext.java
/** * Checks each object including composed objects. *///from w ww . j a v a2 s . com @SuppressWarnings("unchecked") public void checkObjects() throws RegistryException { try { //Process ObjectRefs and create local replicas of any remote ObjectRefs createReplicasOfRemoteObjectRefs(); //Get all submitted objects including composed objects that are part of the submission //so that they can be used to resolve references getSubmittedObjectsMap().putAll(getTopLevelRegistryObjectTypeMap()); Collection<IdentifiableType> composedObjects = bu .getComposedRegistryObjects(getTopLevelRegistryObjectTypeMap().values(), -1); getSubmittedObjectsMap().putAll(bu.getRegistryObjectTypeMap(composedObjects)); pm.updateIdToLidMap(this, getSubmittedObjectsMap().keySet(), "RegistryObject"); getNewSubmittedObjectIds(); //Check id of each object (top level or composed) Iterator<Object> iter = getSubmittedObjectsMap().values().iterator(); while (iter.hasNext()) { RegistryObjectType ro = (RegistryObjectType) iter.next(); //AuditableEvents are not allowed to be submitted by clients if (ro instanceof AuditableEventType) { throw new InvalidRequestException( ServerResourceBundle.getInstance().getString("message.auditableEventsNotAllowed")); } checkId(ro); } //Get RegistryObjects referenced by submittedObjects. this.getReferenceInfos(); //Append the references to the IdToLidMap iter = this.referencedInfos.iterator(); Set<String> referencedIds = new HashSet<String>(); while (iter.hasNext()) { ReferenceInfo refInfo = (ReferenceInfo) iter.next(); referencedIds.add(refInfo.targetObject); } pm.updateIdToLidMap(this, referencedIds, "RegistryObject"); //Iterate over idMap and replace keys in various structures that use id as key //that are based on temporary ids with their permanent id. Iterator<String> iter2 = getIdMap().keySet().iterator(); while (iter2.hasNext()) { String idOld = iter2.next(); String idNew = getIdMap().get(idOld); //replace in all RequestContext data structures Object obj = getTopLevelRegistryObjectTypeMap().remove(idOld); if (obj != null) { getTopLevelRegistryObjectTypeMap().put(idNew, (RegistryObjectType) obj); } obj = getSubmittedObjectsMap().remove(idOld); if (obj != null) { getSubmittedObjectsMap().put(idNew, obj); } if (getNewSubmittedObjectIds().remove(idOld)) { getNewSubmittedObjectIds().add(idNew); } RepositoryItem ri = (RepositoryItem) getRepositoryItemsMap().remove(idOld); if (ri != null) { ri.setId(idNew); getRepositoryItemsMap().put(idNew, ri); } } //Now replace any old versions of RegistryObjects with new versions Iterator<RegistryObjectType> iter3 = getNewROVersionMap().keySet().iterator(); while (iter3.hasNext()) { RegistryObjectType ebRegistryObjectTypeOld = iter3.next(); RegistryObjectType ebRegistryObjectTypeNew = getNewROVersionMap().get(ebRegistryObjectTypeOld); // replace in all data structures getSubmittedObjectsMap().remove(ebRegistryObjectTypeOld.getId()); getSubmittedObjectsMap().put(ebRegistryObjectTypeNew.getId(), ebRegistryObjectTypeNew); getTopLevelRegistryObjectTypeMap().remove(ebRegistryObjectTypeOld.getId()); getTopLevelRegistryObjectTypeMap().put(ebRegistryObjectTypeNew.getId(), ebRegistryObjectTypeNew); } //Now replace any old versions of RepositoryItems with new versions Iterator<RepositoryItem> iter4 = getNewRIVersionMap().keySet().iterator(); while (iter4.hasNext()) { RepositoryItem riOld = iter4.next(); RepositoryItem riNew = getNewRIVersionMap().get(riOld); //replace in all RequestContext data structures getRepositoryItemsMap().remove(riOld.getId()); getRepositoryItemsMap().put(riNew.getId(), riNew); } //resolve references from each object resolveObjectReferences(); } catch (JAXRException e) { throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.common.Utility.java
/** * Check if id is a proper UUID. If not make a proper UUID based * URN and add a mapping in idMap between old and new Id. The * parent attribute of ClassificationNode will be also fixed here * according to their hierarchy if the parent attributes are not * provided explicitly by the clients./*from w w w . j a v a 2s . c o m*/ * * @param ids The List holding all the UUIDs in the SubmitObjectsRequest * document * @throws UUIDNotUniqueException if any UUID is not unique within a * SubmitObjectsRequest */ @SuppressWarnings("unused") private void checkId(List<String> ids, HashMap<String, String> idMap, RegistryObjectType ro) throws RegistryException { try { String id = ro.getId(); // Check for uniqueness if ((ids != null) && ids.contains(id)) { throw new DuplicateIdException(id); } if (id != null) { ids.add(id); } if ((id == null) || !id.startsWith("urn:uuid:")) { // Generate UUID if the request does not provide ID for a RO // or it does not start with urn:uuid: it.cnr.icar.eric.common.UUID uuid = uf.newUUID(); String newId = "urn:uuid:" + uuid; ro.setId(newId); idMap.put(id, newId); } else { // id starts with "urn:uuid:" String uuidStr = id.substring(9); if (!uf.isValidUUID(uuidStr)) { // but invalid it.cnr.icar.eric.common.UUID uuid = uf.newUUID(); String newId = "urn:uuid:" + uuid; idMap.put(id, newId); } } //Now checkId for all composed objects Set<RegistryObjectType> composedObjects = BindingUtility.getInstance().getComposedRegistryObjects(ro, -1); Iterator<RegistryObjectType> iter = composedObjects.iterator(); while (iter.hasNext()) { RegistryObjectType obj = iter.next(); checkId(ids, idMap, ro); } } catch (JAXRException e) { throw new RegistryException(e); } }