使用 Apache 捕获 302 并返回 401

JLe*_*ich 5 apache ajax http shibboleth angularjs

我们目前有一个保护特定路径的 shibboleth 实现。然而,因为这个路径实际上是一个 HTTP 请求(由一个使用 $http 的 AngularJS 应用程序创建),shibboleth 会尝试将此请求“重定向”到身份提供者,但浏览器只是将其解释为无效请求。它以 status=-1 并且没有关联的标题/数据返回给 AngularJS。

我想拦截这个 302 并返回一个 401,并且最好能够编辑响应标头。有没有办法使用 Apache 或 Shibboleth 来做到这一点?

相关板块:

# Proxy all requests to WebLogic
<Location "/api">
    SetHandler weblogic-handler
    WLSRequest On
    WebLogicHost services.endpoint.com
    WebLogicPort 9002
</Location>

# For requests marked as protected, apply shibboleth
# If this block gets triggered, Shibboleth attempts redirect
# which does not work with our architecture
<Location "/api/protected">
     AuthType Shibboleth
     ShibRequireSession On
     ShibApplicationId default
     ShibExportAssertion On
     Require Shibboleth
</Location>
Run Code Online (Sandbox Code Playgroud)

它是如何在 AngularJS 中使用的:

//API call to unprotected endpoint
$http.get('http://hosted.on.apache.com/api/getData');

//API call to protected endpoint - Shibboleth triggered
$http.get('http://hosted.on.apache.com/api/protected/getSecureData');
Run Code Online (Sandbox Code Playgroud)

rek*_*nuc 0

我不熟悉 Sibboleth,但正如人们在评论中指出的那样,这可以通过反向代理轻松完成。

请参阅此答案中建议的解决方案作为参考:

Apache - 反向代理和 HTTP 302 状态消息