@Override public GetObjectResponse<String> getObject(GetObjectRequest request) { GetObjectResponse<String> response = catalog.getObject(request); if(!response.isOK() || skipLicenses) return response; if (response.getObject()==null) { request.getObject().getId(), response.getObject().getTags()); secResult.getError().getCode() + ", " + secResult.getError().getMssg()); response=new GetObjectResponse<String>(); response.setError(secResult.getError()); return response; return response; } else { response=new GetObjectResponse<String>(); response.setError(new YaddaError(SecurityConstants.ERROR_AUTH, "Permission not granted to retrieve resource id='"+request.getObject().getId()+"'!")); return response;
@Override public GetObjectResponse<String> getObject(GetObjectRequest request) { GetObjectResponse<String> resp = new GetObjectResponse<String>(); try { CatalogObject<String> co = null; YaddaObjectID oid = request.getObject(); // we check history too if the request is for a specific version and metadata only if (request.isOnlyMetadata()) { CatalogObjectMeta meta; if (oid.getVersion() == null) meta = curdao.findMeta(oid.getId()); else meta = histdao.findMeta(oid); if (meta != null) co = new CatalogObject<String>(meta); } else { if (oid.getVersion() == null) co = curdao.findObject(oid.getId()); else co = curdao.findObject(oid); } resp.setObject(co); } catch (Exception e) { log.error("Exception caught", e); resp.setError(new YaddaError(ERROR_CODE, "exception caught", e)); } return resp; }
/** * Adds public licence tag to catalog ID object. * @throws Exception */ @Override public void afterPropertiesSet() throws Exception { GetObjectRequest req = new GetObjectRequest(); YaddaObjectID yaddaId = new YaddaObjectID(ICatalog.ID_CATALOG_META); req.setObject(yaddaId); req.setOnlyMetadata(true); GetObjectResponse<String> objectResp = catalog.getObject(req); if (objectResp.isOK()) { if(skipLicenses) { return; } for (String tag : objectResp.getObject().getTags()) { if (tag.equals(SecurityConstants.TAG_PUBLIC_LICENSE)) { return; } } ExecuteRequest request = new ExecuteRequest(); EditorOperation operation = new TagOperation(yaddaId, new String[]{SecurityConstants.TAG_PUBLIC_LICENSE}, null); request.setOperation(operation); service.execute(request); } else { throw new EditorException("Unable to get catalog identifier object, reason: " + objectResp.getError().getMssg(), objectResp.getError().getException()); } }
/** * Returns catalog object either from cached context or by using catalog instance. * @param extId * @param context * @return CatalogObject */ protected CatalogObject<String> getCatalogObject( LicenseEvaluatorContext<CatalogObject<String>> context) { if (context==null) { return null; } if (context.getStoredObjectContent()!=null) { return context.getStoredObjectContent(); } else if (context.getStoredObjectId()!=null) { getLogger().warn("no catalog object found in context, " + "using embedded catalog instance"); GetObjectRequest goReq = new GetObjectRequest(); goReq.setObject(new YaddaObjectID((String)context.getStoredObjectId())); GetObjectResponse<String> goResponse = catalog.getObject(goReq); if (goResponse!=null && goResponse.isOK()) { context.setStoredObjectContent(goResponse.getObject()); return goResponse.getObject(); } else { return null; } } else { return null; } }
@Override public GetPartResponse<String> getPart(GetPartRequest request) { GetObjectRequest oReq = new GetObjectRequest(); oReq.setObject(request.getObject()); SAMLObject[] samlObjects = securityRequestHandler.extract(request); securityRequestHandler.attach(oReq, samlObjects); GetObjectResponse<String> oResp = this.getObject(oReq); if(!oResp.isOK()) { GetPartResponse<String> resp = new GetPartResponse<String>(); resp.setError(oResp.getError()); return resp; } else { return catalog.getPart(request); } }