1

我有一个允许匿名访问以及命名用户帐户的框架。我在某个 URL 上公开 OData 资源。当这样配置时,匿名用户可以看到部分资源,登录用户(通过基本身份验证)可以看到更多。

我面临的问题是某些 OData 客户端(如 Excel)最初会尝试匿名访问 OData 资源,即使您确实提供了凭据。只有当这失败时,他们才会使用提供的凭据。我的理解是,这是因为有很多登录方式,而有些客户总是先尝试最基本的选项。但这会阻止他们实际看到更多数据,因为他们从不使用提供的凭据,并且在资源允许匿名访问时也永远不会获得身份验证挑战。

有没有办法解决这个问题,允许匿名访问并在可能的情况下正确发送身份验证质询?当客户确实拥有凭据但最初没有提供它们时,是否可能会发送一些标头?

一些(scala)代码使这更加有形:

  val (username, password) = getAuthInfo(request)
  if (username != null && password != null) {
    val regularSession = integration.core.login(username, password)
    logger.debug(s"Login OK: User '$username' (Number of concurrent sessions: ${integration.core.getNumberConcurrentSessions}).")
    (IMxRuntimeResponse.OK, null, regularSession)
  } else if (integration.configuration.getEnableGuestLogin) {
    val guestSession = integration.core.initializeGuestSession
    logger.debug(s"Anonymous user '${guestSession.getUser.getName}' created " +
      "(Number of concurrent sessions: ${integration.core.getNumberConcurrentSessions}).")
    (IMxRuntimeResponse.OK, null, guestSession)
  } else {
    val responseMessage = "No basic authentication in header."
    logger.warn(s"Login failed: $responseMessage")
    (IMxRuntimeResponse.UNAUTHORIZED, responseMessage, null)
  }

周围的 try/catch 之外的其他地方:

if (httpStatusCode == IMxRuntimeResponse.UNAUTHORIZED)
      response.addHeader("WWW-Authenticate", "Basic")

如您所见,当允许匿名访问时,永远不会发送质询。

编辑:我们进行了调查,该请求的标头中似乎没有任何特别之处表明这是一个初始尝试,当发送身份验证质询时将导致另一个请求,而不仅仅是另一个匿名登录尝试。我们现在在这里不知如何进行。

4

0 回答 0