【问题标题】:Display a document without authentification显示未经身份验证的文档
【发布时间】:2017-05-31 11:49:40
【问题描述】:

我目前正在开发一个 java/jee 应用程序,使用 alfresco 作为 ged 和 spring 作为框架。我想在导航器中显示一个文件而不需要身份验证。那么我该怎么做。顺便说一下,我有 2 个模块我的项目:前端和后端通过休息调用进行通信。从后端我尝试传递对象的字节数组,但不幸的是我将它作为字符串接收,所以我无法使用它。所以有什么建议可以解决这个问题?

   public Map<String, Object> getCourrierDetails(String idCourrier) throws Exception {
        Map<String, Object> courriersDetails = runtimeService.getVariables(idCourrier);
courriersDetails.put("idCourrier", idCourrier);
        DocumentDaoImpl dao=new DocumentDaoImpl();

        Document docCmis = (Document) dao.getDocument("workspace://SpacesStore/73871a36-9a6c-42c6-b3e3-7d68362fe9c0");

        byte[] myByteArray = readContent(docCmis.getContentStream().getStream());


        ByteArrayResource resource = new ByteArrayResource(myByteArray) {
            @Override
            public String getFilename() {
                return docCmis.getContentStreamFileName();
            }
        };
        System.out.println(resource.getFilename());
        //courriersDetails.put("resources", myByteArray);
        System.out.println(courriersDetails.get("resources")+" rrrr");
        //courriersDetails.put("contentStream",docCmis.getContentStream().getStream());
        return courriersDetails;
    }

【问题讨论】:

  • 据我所知,您只能显示 PDF 文档,您将使用 InputStream 进行工作

标签: javascript java alfresco cmis opencmis


【解决方案1】:

假设您的前端和后端是自定义的,并且您的后端与 Alfresco 通信,您需要做的就是编写一个驻留在后端的代理。

代理可以使用可以访问内容的预配置“服务帐户”与 Alfresco 建立会话。这样,使用您的自定义 web 应用程序的人不会使用他们自己的凭据从 Alfresco 获取对象。而是使用服务帐户,网络应用将其流式传输给请求者。

例如,在我的一个项目中,我有一个 AssetService,它使用 CMIS 从给定 ID 的内容中获取 InputStream:

public InputStream download(String assetId) {
    CmisObject obj = session.getObject(assetId);
    Document doc = null;
    if (obj.getBaseTypeId().equals(BaseTypeId.CMIS_DOCUMENT)) {
        doc = (Document) obj;
    }
    return doc.getContentStream().getStream();
}

然后,我的 Controller 只是要求资产服务获取有关它的一些信息,以便轻松设置一些有用的标头,然后它从资产服务获取输入流并返回:

@RequestMapping(value = "/api/asset/{assetId:.+}/download/{name}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> downloadAsset(
        @PathVariable("assetId") String assetId,
        @PathVariable("name") String name) {

    // get the asset so we can get some info about it
    Asset asset = assetService.getAsset(assetId);

    // set the http headers (mimetype and length at a minimum)
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.parseMediaType(asset.getMimetype()));
    httpHeaders.setContentLength(asset.getLength());

    // get the content stream
    InputStream inputStream = assetService.download(assetId);
    InputStreamResource inputStreamResource = new InputStreamResource(inputStream);

    return new ResponseEntity<InputStreamResource>(inputStreamResource, httpHeaders, HttpStatus.OK);
}

此示例在 Spring Boot 应用程序中使用 Spring MVC,但如果您愿意,当然您可以使用普通的旧 servlet 执行类似的操作。

【讨论】:

  • 当您在户外创建文档时,是否可以在不经过身份验证的情况下获取它,这是否意味着每个人都可以访问该文档?!?
  • 不,除非您执行我上面建议的操作,否则无法在没有身份验证的情况下获取它,这实际上是在 Alfresco 前面放置一个代理并代表用户获取文档。如果一个人可以猜到一个节点引用,他们就可以在 repo 中获取“服务帐户”有权访问的任何文档。
  • 感谢@jeffPotts 的回答和时间
【解决方案2】:

一种选择是编写您自己的网络脚本并将其设置为允许访客访问。

http://docs.alfresco.com/4.1/concepts/ws-authenticating.html

还有一个选项可以完全禁用权限检查,不过我从未尝试过。

https://community.alfresco.com/thread/175381-disabling-permission-checking

【讨论】:

    猜你喜欢
    • 2021-05-24
    • 1970-01-01
    • 2021-06-23
    • 2019-09-25
    • 2015-10-12
    • 1970-01-01
    • 2019-06-14
    • 2023-03-10
    • 2019-06-02
    相关资源
    最近更新 更多