如何在CRXDE Lite / AEM中启用CORS

编程入门 行业动态 更新时间:2024-10-17 14:13:20
本文介绍了如何在CRXDE Lite / AEM中启用CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们使用CRX DE lite / Adob​​e EM作为我们的Angularjs SPA UI / frontend的后端。如何为这个后端技术设置CORS?我们可以访问此工具 http:// localhost:4502 / crx / de / index.jsp 更改设置。但我们不知道如何设置CORS启用。

We use CRX DE lite/Adobe EM as our backend for our Angularjs SPA UI/frontend. How can we set CORS for this backend technology? We have access to the tool localhost:4502/crx/de/index.jsp to change settings. But we are not sure how to set CORS enabled.

请咨询。

推荐答案

有两个OSGi服务值得关注(虽然我从来没有试图得到它们)

There are two OSGi services worth looking at (although I never tried to get them)

  • com.adobe.cq.social mons.cors.CORSAuthInfoPostProcessor
  • com.adobe.cq.socialmons.cors.CORSAuthenticationFilter

我所做的(首先)是创建一个实现 AuthenticationInfoPostProcessor 的服务。在此,我设置了以下标题:

What I wound up doing (at first) was creating a service that implemented AuthenticationInfoPostProcessor. There, I set the following headers:

  • 访问控制允许凭证
  • 控制 - 允许原因
  • 访问控制 - 允许方法

用于GET请求。但是当我们尝试POST时,我们碰到了浏览器发送的飞行前OPTIONS请求失败的问题,因为浏览器不是使用 login-token cookie 。

And everything was fine for GET requests. But when we tried POST, we ran into the issue that the browser was sending the pre-flight OPTIONS request which was failing because the browser was not doing it with login-token cookie.

然后我们尝试了一个 @SlingFiter ,但是落在正常的sling管道中,

Then we tried a @SlingFiter, however that falls in the normal sling pipeline, therefore it was after authentication was checked, so having no auth cookie, the pre-flight would always fail.

最后,我们实现了一个带有以下注释的过滤器:

Finally, we implemented a filter with the following annotations:

@Component(immediate = true) @Service(value = Filter.class) @Properties({ @Property(name = "pattern", value = "/.*"), @Property(name = Constants.SERVICE_RANKING, intValue = 1000) })

这里的关键是模式属性,它将过滤器注册为Apache Felix Whiteboard过滤器,不是Sling。 请参阅此处。因此,过滤器会为OPTIONS设置CORS头并返回,并为其他所有内容设置CORS头,并将请求传递给链中的下一个过滤器。

The key here was the pattern property, which registers the filter as an Apache Felix Whiteboard filter, not Sling. See here. So the filter will set CORS headers for OPTIONS and return, and set CORS headers for everything else, and pass the request to the next filter in the chain.

更多推荐

如何在CRXDE Lite / AEM中启用CORS

本文发布于:2023-11-24 20:42:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626748.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   CRXDE   Lite   AEM   CORS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!