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.cache.ClassificationSchemeCache.java
/** * This method is used to retrieve a ClassificationNode based on its path. * Note: if an invalid path is passed to this method, this method will * return null// w ww .j a va 2s . com * * @param path * A String containing the ClassificationNodeType path * @return A ClassificationNodeType instance that matches the path */ public ClassificationNodeType getClassificationNodeByPath(String path) throws RegistryException { ClassificationNodeType cn = null; ServerRequestContext context = null; try { Element elem = getPathToNodeCache().get(path); if (elem == null) { String likeOrEqual = "="; if (path.indexOf('%') != -1) { likeOrEqual = "LIKE"; } String tableName = "ClassificationNode"; String sqlQuery = "SELECT cn.* from ClassificationNode cn WHERE UPPER(cn.path) " + likeOrEqual + " ? ORDER BY cn.path ASC"; ArrayList<String> queryParams = new ArrayList<String>(); queryParams.add(path.toUpperCase()); context = new ServerRequestContext("ClassificationSchemeCache.getClassificationNodeByPath", null); List<?> results = executeQueryInternal(context, sqlQuery, queryParams, tableName); if (results.size() == 0) { return null; } cn = (ClassificationNodeType) results.get(0); elem = new Element(path, cn); getPathToNodeCache().put(elem); } else { cn = (ClassificationNodeType) elem.getValue(); } } catch (RegistryException re) { throw re; } catch (Throwable t) { throw new RegistryException(t); } finally { if (context != null) { context.rollback(); } } return cn; }
From source file:it.cnr.icar.eric.server.cms.CMSManagerImpl.java
/** * * Gets the Associations that have the specified assocType and have * as targetObject the ClassificationNode pointed to by objectType * or an ancestor of the ClassificationNode pointed to by * objectType./*from ww w. ja v a 2 s. com*/ * */ private List<IdentifiableType> getAssociations(ServerRequestContext context, String objectType, String assocType) throws RegistryException { List<IdentifiableType> associations = new ArrayList<IdentifiableType>(); try { RegistryObjectType ro = pm.getRegistryObject(context, objectType, "ClassificationNode"); ResponseOptionType ebResponseOptionType = bu.queryFac.createResponseOptionType(); ebResponseOptionType.setReturnType(ReturnType.LEAF_CLASS); ebResponseOptionType.setReturnComposedObjects(false); ArrayList<Object> objectRefs = new ArrayList<Object>(); if ((ro != null) && (ro instanceof ClassificationNodeType)) { ClassificationNodeType node = (ClassificationNodeType) ro; String query = "SELECT ass.* from Association ass " + " WHERE ass.targetObject = '" + node.getId() + "' AND ass.associationType = '" + assocType + "' "; objectRefs.clear(); associations = pm.executeSQLQuery(context, query, ebResponseOptionType, "Association", objectRefs); //TODO: Fix following design bug... //If there is a CatalogingService defined at //sub-class of XML (e.g. CPP) level then it will //not look at XML level even for a different type //of service such as FilteringService. //Base class lookup should be done if no service //is found for a specific type of CMS service. if (associations.size() == 0) { //Check if an Association exists for the parent node Object parent = node.getParent(); if ((parent != null)) { String parentId = bu.getObjectId(parent); associations = getAssociations(context, parentId, assocType); } } } } catch (JAXRException e) { throw new RegistryException(e); } return associations; }
From source file:it.cnr.icar.eric.server.repository.hibernate.HibernateRepositoryManager.java
protected void tryClose() throws RegistryException { try {/*from ww w . j a va2 s. co m*/ SessionContext sc = hu.getSessionContext(); if (reclaimUsedDBConnections) { try { sc.getSession().disconnect(); } catch (Throwable t) { String msg = ServerResourceBundle.getInstance().getString("message.FailedCloseDatabaseSession"); log.error(msg); log.error(t, t); } } sc.close(); } catch (HibernateException e) { String msg = ServerResourceBundle.getInstance().getString("message.FailedCloseDatabaseSession"); log.error(e, e); throw new RegistryException(ServerResourceBundle.getInstance().getString("message.seeLogsForDetails", new Object[] { msg })); } }
From source file:it.cnr.icar.eric.server.lcm.LifeCycleManagerImpl.java
/** Approves one or more previously submitted objects */ @SuppressWarnings({ "unused", "unchecked", "static-access" }) public RegistryResponseType approveObjects(RequestContext context) throws RegistryException { context = ServerRequestContext.convert(context); ApproveObjectsRequest req = (ApproveObjectsRequest) context.getCurrentRegistryRequest(); UserType user = context.getUser();//from w ww .j av a 2 s. co m String errorCodeContext = "LifeCycleManagerImpl.approveObjects"; String errorCode = "unknown"; RegistryResponseType ebRegistryResponseType = null; try { context = new ServerRequestContext("LifeCycleManagerImpl.approveObjects", req); ((ServerRequestContext) context).setUser(user); checkAuthorizedAll(((ServerRequestContext) context)); List<String> idList = new java.util.ArrayList<String>(); // Add explicitly specified oref params List<ObjectRefType> ebObjectRefTypeList = bu .getObjectRefTypeListFromObjectRefListType(req.getObjectRefList()); // Append those orefs specified via ad hoc query param ebObjectRefTypeList.addAll((List<ObjectRefType>) ((ServerRequestContext) context) .getObjectsRefTypeListFromQueryResults(req.getAdhocQuery())); Iterator<ObjectRefType> orefsIter = ebObjectRefTypeList.iterator(); while (orefsIter.hasNext()) { ObjectRefType ebObjectRefType = orefsIter.next(); idList.add(ebObjectRefType.getId()); } pm.updateStatus(((ServerRequestContext) context), idList, bu.CANONICAL_STATUS_TYPE_ID_Approved); ebRegistryResponseType = bu.rsFac.createRegistryResponseType(); ebRegistryResponseType.setStatus(BindingUtility.CANONICAL_RESPONSE_STATUS_TYPE_ID_Success); if (((ServerRequestContext) context).getErrorList().getRegistryError().size() > 0) { // warning exists ebRegistryResponseType.setRegistryErrorList(((ServerRequestContext) context).getErrorList()); } } catch (RegistryException e) { ((ServerRequestContext) context).rollback(); throw e; } catch (Exception e) { ((ServerRequestContext) context).rollback(); throw new RegistryException(e); } ((ServerRequestContext) context).commit(); return ebRegistryResponseType; }
From source file:it.cnr.icar.eric.server.repository.hibernate.HibernateRepositoryManager.java
protected void tryRollback(Transaction tx) throws RegistryException { if (tx != null) { try {/*from w w w. j a v a2 s . c o m*/ tx.rollback(); } catch (Exception e) { String msg = ServerResourceBundle.getInstance().getString("message.failedToRollbackTransaction"); log.error(e, e); throw new RegistryException(ServerResourceBundle.getInstance() .getString("message.seeLogsForDetails", new Object[] { msg })); } } }
From source file:it.cnr.icar.eric.server.common.ServerRequestContext.java
private void resolveObjectReferences() throws RegistryException { try {/*from ww w . jav a 2 s . com*/ //Get Set of ids for objects referenced from obj Set<Object> refInfos = this.referencedInfos; //Check that each ref is resolvable Iterator<Object> iter = refInfos.iterator(); Set<String> unresolvedRefIds = new HashSet<String>(); while (iter.hasNext()) { ReferenceInfo refInfo = (ReferenceInfo) iter.next(); String refId = refInfo.targetObject; // only check referenced id once per request if (getCheckedRefs().contains(refId)) { continue; } else { getCheckedRefs().add(refId); } @SuppressWarnings("unused") ObjectRefType ref = getObjectRefTypeMap().get(refId); //Remote references already resolved by creating local replica by now //First check if resolved within submittedIds if (!(getSubmittedObjectsMap().containsKey(refId))) { //ref not resolved within submitted objects //See if exists in the registry if (!(getIdToLidMap().keySet().contains(refId))) { unresolvedRefIds.add(refId); } } } if (unresolvedRefIds.size() > 0) { throw new RegistryException(ServerResourceBundle.getInstance() .getString("message.unresolvedReferences", new Object[] { unresolvedRefIds })); } } catch (JAXRException e) { throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.persistence.rdb.RegistryObjectDAO.java
@SuppressWarnings({ "rawtypes", "unchecked" }) protected void loadObject(Object obj, ResultSet rs) throws RegistryException { try {/* w w w . jav a 2 s .com*/ if (!(obj instanceof RegistryObjectType)) { throw new RegistryException(ServerResourceBundle.getInstance() .getString("message.RegistryobjectTypeExpected", new Object[] { obj })); } RegistryObjectType ebRegistryObjectType = (RegistryObjectType) obj; super.loadObject(ebRegistryObjectType, rs); ClassificationDAO classificationDAO = new ClassificationDAO(context); classificationDAO.setParent(ebRegistryObjectType); DescriptionDAO descriptionDAO = new DescriptionDAO(context); descriptionDAO.setParent(ebRegistryObjectType); ExternalIdentifierDAO externalIdentifierDAO = new ExternalIdentifierDAO(context); externalIdentifierDAO.setParent(ebRegistryObjectType); NameDAO nameDAO = new NameDAO(context); nameDAO.setParent(ebRegistryObjectType); String id = rs.getString("id"); String lid = rs.getString("lid"); if (lid != null) { // TODO:versioning: remove this check as persistent objects // should always have a lid ebRegistryObjectType.setLid(lid); } String objectType = rs.getString("objectType"); ebRegistryObjectType.setObjectType(objectType); InternationalStringType name = nameDAO.getNameByParent(id); ebRegistryObjectType.setName(name); InternationalStringType desc = descriptionDAO.getDescriptionByParent(id); ebRegistryObjectType.setDescription(desc); String status = rs.getString("status"); if (status.equals("null")) { // Ignore earlier corruption of the database, losing whatever // status was before that problem occurred status = BindingUtility.CANONICAL_STATUS_TYPE_ID_Submitted; // TODO: unfortunately, can't turn read operation into a // write... (best fix probably a SQL script) // updateStatus(ro, status); } ebRegistryObjectType.setStatus(status); // Now set VersionInfo VersionInfoType versionInfo = BindingUtility.getInstance().rimFac.createVersionInfoType(); String versionName = rs.getString("versionName"); if (versionName != null) { versionInfo.setVersionName(versionName); } String comment = rs.getString("comment_"); if (comment != null) { versionInfo.setComment(comment); } ebRegistryObjectType.setVersionInfo(versionInfo); boolean returnComposedObjects = context.getResponseOption().isReturnComposedObjects(); if (returnComposedObjects) { List classifications = classificationDAO.getByParent(); ebRegistryObjectType.getClassification().addAll(classifications); List extIds = externalIdentifierDAO.getByParent(); ebRegistryObjectType.getExternalIdentifier().addAll(extIds); } } catch (SQLException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.security.authorization.AuthorizationServiceImpl.java
/** * Check if subject is authorized to perform action on the resource * RegistryObject./*from ww w . ja va 2 s . c om*/ * * @param id * id of the resource being accessed. * @param subjects * A list of xacml subject Attributes representing the subject * making the request. * @param actions * A list of xacml action Attributes representing the action * being requested. * * @throws RegistryException */ @SuppressWarnings("deprecation") private void checkAuthorizationForResource(ServerRequestContext context, String id, Set<Subject> subjects, Set<Attribute> actions, Set<Attribute> environment) throws RegistryException { boolean isAdmin = context.isRegistryAdministrator(); RegistryObjectType ebRegistryObjectType = getRegistryObject(context, id, false); if (ebRegistryObjectType == null) { String msg = getExceptionMessage("message.error.authorization.ObjectNotFound", id, context.getUser(), getActionString(actions)); throw new AuthorizationException(msg); } // Only allow non RegistryAdministrator roles to READ Federation and // Registry types if (((ebRegistryObjectType instanceof FederationType) || (ebRegistryObjectType instanceof RegistryType)) && (!(isAdmin))) { String actionName = getActionAttributeValue(actions, ACTION_ATTRIBUTE_ID); if (!((actionName.equalsIgnoreCase("read")) || (actionName.equalsIgnoreCase("reference")))) { String msg = getExceptionMessage("message.error.authorization.allowedOnlyToAdmin.defineFederation", id, context.getUser(), getActionString(actions)); throw new UnauthorizedRequestException(id, context.getUser().getId(), getActionString(actions), msg); } } String ownerId = getRegistryObjectOwnerId(context, id); try { // Resource Attributes Attribute idResourceAttr = new Attribute(new URI(EvaluationCtx.RESOURCE_ID), new URI(AnyURIAttribute.identifier), null, null, new AnyURIAttribute(new URI(id))); Attribute resourceResourceAttr = new Attribute(new URI(RESOURCE_ATTRIBUTE_RESOURCE), new URI(ObjectAttribute.identifier), null, null, new ObjectAttribute(ebRegistryObjectType)); Attribute ownerResourceAttr = new Attribute(new URI(RESOURCE_ATTRIBUTE_OWNER), new URI(AnyURIAttribute.identifier), null, null, new AnyURIAttribute(new URI(ownerId))); Set<Attribute> resourceAttributes = new HashSet<Attribute>(); resourceAttributes.add(idResourceAttr); resourceAttributes.add(ownerResourceAttr); resourceAttributes.add(resourceResourceAttr); int decision = Result.DECISION_DENY; Status status = null; if (context.getConfirmationAssociations().containsKey(id)) { // Bypass auth check for confirm ass decision = Result.DECISION_PERMIT; } else { RequestCtx req = new RequestCtx(subjects, resourceAttributes, actions, environment); // PolicyDecisionPoint ResponseCtx resp = pdp.evaluate(req); Set<?> results = resp.getResults(); // Expecting only one Result Result result = (Result) results.iterator().next(); status = result.getStatus(); decision = result.getDecision(); } if (!(decision == Result.DECISION_PERMIT)) { String statusMsg = status.getMessage(); if (statusMsg == null) { statusMsg = ServerResourceBundle.getInstance().getString("message.NoInfoAvailable"); } String msg = getExceptionMessage("message.UnauthorizedRequestDenied", id, context.getUser(), getActionString(actions), statusMsg); throw new UnauthorizedRequestException(id, context.getUser().getId(), getActionString(actions), msg); } // The action is authorized for the resource. // However, some actions on a resource may result in other actions // on other resources // Check authorization for such special secondary actions next RegistryRequestType registryRequest = context.getCurrentRegistryRequest(); if ((registryRequest instanceof SubmitObjectsRequest) || (registryRequest instanceof UpdateObjectsRequest)) { // Check access control for all refrences from this object checkObjectReferencesInResource(context, id, subjects, environment); } } catch (URISyntaxException e) { throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.query.CompressContentQueryFilterPlugin.java
protected ExtrinsicObjectType getContainedExtrinsicObject(ExtrinsicObjectType targetEO, ServerRequestContext serverContext) throws RegistryException { ExtrinsicObjectType ebExtrinsicObjectType = null; @SuppressWarnings("unused") ArrayList<Object> eoList = new ArrayList<Object>(); ServerRequestContext context = null; try {// w w w . ja va 2 s. co m String queryId = CanonicalConstants.CANONICAL_QUERY_ArbitraryQuery; String assocType = "urn:oasis:names:tc:ebxml-regrep:AssociationType:Contains"; String id = targetEO.getId(); String queryString = "SELECT ass.* FROM Association ass WHERE targetObject = '" + id + "'" + " AND associationType = '" + assocType + "' ORDER BY sourceObject, targetObject, associationType"; HashMap<String, String> queryParamsMap = new HashMap<String, String>(); queryParamsMap.put("$query", queryString); context = new ServerRequestContext("CompressContentQueryFilterPlugin:getContainedExtrinsicObject", null); context.setUser(serverContext.getUser()); List<?> res = executeQuery(context, queryId, queryParamsMap); Iterator<?> containsItr = res.iterator(); // Check for most recent version while (containsItr.hasNext()) { AssociationType1 ebAssociationType1 = (AssociationType1) containsItr.next(); String sourceId = ebAssociationType1.getSourceObject(); @SuppressWarnings("unused") ExtrinsicObjectType nextEOT = null; try { ebExtrinsicObjectType = (ExtrinsicObjectType) ServerCache.getInstance() .getRegistryObject(serverContext, sourceId, "ExtrinsicObject"); } catch (ObjectNotFoundException oex) { String msg = ServerResourceBundle.getInstance().getString("message.registryObjectNotFound", new Object[] { id }); log.error(msg); } catch (Throwable t) { log.error(t); } } } catch (Throwable t) { throw new RegistryException(t); } finally { if (context != null) { context.rollback(); } } return ebExtrinsicObjectType; }
From source file:it.cnr.icar.eric.server.security.authentication.AuthenticationServiceImpl.java
/** * This method is used to remove a certificate from the server keystore. * This is called, for example, when a rim:User has been deleted and the * User's credentials need to be cleared from the server keystore * //from w w w . j a v a2s . co m * @param alias * A java.lang.String that contains the alias of the public key * credential */ public void deleteUserCertificate(String alias) throws RegistryException { KeyStore keyStore = getKeyStore(); java.io.FileOutputStream fos = null; try { String keystoreFile = getKeyStoreFileName(); synchronized (keyStoreWriteLock) { fos = new java.io.FileOutputStream(keystoreFile); keyStore.deleteEntry(alias); String keystorePass = getKeyStorePassword(); keyStore.store(fos, keystorePass.toCharArray()); fos.flush(); this.keyStore = null; } } catch (Throwable t) { throw new RegistryException(t); } finally { if (fos != null) { try { fos.close(); } catch (IOException io) { fos = null; } } } }