【问题标题】:Catch 302 with Apache and return 401 instead使用 Apache 捕获 302 并返回 401
【发布时间】:2016-11-03 06:04:06
【问题描述】:

我们目前有一个保护特定路径的 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>

如何在 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');

【问题讨论】:

  • 似乎您正在尝试使用 api 验证 login page 并且您正在尝试 hack a solution 使它们 speake 一起。我想最好的解决方案是通过apiREST 一样允许login,而不是这个现有的方案。我不熟悉shibboleth。但是你可能会更好地缺乏 Apache reverse proxy 来做这个可以破解的
  • 为了hack it,您可以查看stackoverflow.com/a/21074783/1211174。但更好的是检查shibboleth 是否具有基于api 的身份验证
  • 你想截取这个 302 还是全部?
  • shibboleth wiki 有一个启用对受保护资源的 AJAX 请求的示例,但一年前它已被标记为“以某种方式关闭”,请参阅 wiki.shibboleth.net/confluence/display/IDP30/…

标签: angularjs ajax apache http shibboleth


【解决方案1】:

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

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

Apache - Reverse Proxy and HTTP 302 status message

【讨论】:

  • 我希望将可用的 HTTP 代码冒泡到 UI,而不是处理请求本身(这会导致 OP 中列出的类似问题)
【解决方案2】:

好吧,我认为没有必要将 302 重定向到 404。 尝试将以下内容添加到您的 /api/protected 区域。

ShibRequestSetting requireSession 1

根据此处的文档,这是典型的受保护路径的样子。 https://docs.shib.ncsu.edu/docs/testing/index.html

<Location /api/protected>
  AuthType shibboleth
  ShibCompatWith24 On
  ShibRequestSetting requireSession 1
  require shib-session
</Location>

【讨论】:

  • 你能详细说明这是如何解决问题的吗?问题是当会话无效时,Angular 没有看到返回的 302。因此,这将有助于返回 401。这个指令会改变那个响应代码吗?
【解决方案3】:

这似乎是不可能的,因为 Shibboleth 发送的 302 重定向只是由 Apache 转发给调用者(因为它不是错误)。

不要与重定向作斗争,而是让单个端点受到 Shibboleth 的保护。如果成功,此端点会设置两个 cookie:

  1. 一个安全的、仅限 http 的会话 cookie,被所有其他端点用作登录令牌。
  2. 一个安全的超时 cookie,它会在会话结束时通知前端,以便能够与用户交流他们的会话即将结束,并在会话结束时停止任何 ajax 调用。

如果再次调用 /login 时仍然存在有效的 shibboleth 会话,则会重新发出会话 cookie。

在 Apache 中

<Location /login>
# Let Shibboleth handle the creation of a valid session
AuthType shibboleth
ShibRequireSession On
ShibUseHeaders On
require valid-user

# set session cookie
# set timeout cookie

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    • 2021-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多