Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

ams-spring-boot-shopping: `/products` always returns 403

オープン
#99 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@NiklasHerrmann21 がすでに取り組んでいます。

2026年9月23日 から。

  • #117 @NiklasHerrmann21 による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java, spring-boot

調査の方向性

ams-spring-boot-shopping/src/main/java/com/sap/cloud/security/ams/samples/config/SecurityConfiguration.java の SecurityConfiguration#filterChain から始めます。有効な IAS トークンを使用してリクエストを再現し、その後、AMS 認可が実行される前にリソースサーバーが Jwt をどのように変換するかを調べます。AMS principal が確立され、GET /products と GET /privileges が 403 ではなく期待される認可済みレスポンスを返せば完了です。

索引モデルが issue の本文から書いたものです。

説明

Summary

In ams-spring-boot-shopping, calling GET /products (and GET /privileges) with a valid IAS token is rejected with HTTP 403, even though the app is bound, token is valid, policies are pushed.

Steps to reproduce

  1. Deploy the sample as single-tenant IAS app on CF. Bind the app to a IAS app, create app2app trust, create client credentials for the consumer app.
  2. Obtain a valid IAS token for the consumer app. Make sure to hit the right dependency. Should look like [1]
  3. curl -H "Authorization: Bearer <token>" https://<app>/products

Expected: 200 with the product list (the GetProducts API maps to internal.GetProducts → shopping.ReadProducts → GRANT read ON products).
Actual: 403.

Root cause

The request is authenticated but no AMS principal is ever established, so the AMS authorization check runs against empty authorizations and denies.

SecurityConfiguration#filterChain wires the resource server with:

https://github.com/SAP-samples/ams-samples-java/blob/10e80968de39c73cafe70f83fc30ced2b0c72b31/ams-spring-boot-shopping/src/main/java/com/sap/cloud/security/ams/samples/config/SecurityConfiguration.java#L62

With the default converter, Spring produces a plain org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken whose principal is a plain org.springframework.security.oauth2.jwt.Jwt, not a SAP com.sap.cloud.security.spring.token.authentication.AuthenticationToken.

The cloud-security JavaSecurityContextHolderStrategy only copies the SAP Token into com.sap.cloud.security.token.SecurityContext when the Spring Authentication's principal is a SAP Token. Because it isn't, SecurityContext.getToken() stays null, so com.sap.cloud.security.ams.api.Principal.fromSecurityContext() returns null, and SciAuthorizationsProvider short-circuits to empty authorizations. Every @CheckPrivilege then evaluates granted=false → 403. Logs here [2].

Direction for a fix

The app needs a jwtAuthenticationConverter that turns the validated IAS Jwt into a SAP AuthenticationToken, so the AMS principal is established. Worked for me afterwards.

[1]

{
  "ias_apis": [
    "GetProducts"
  ],
  "sub": "consumer",
  "aud": "ams-secured-app",
  "app_tid": "app-tid",
  "sap_id_type": "app",
  "azp": "consumer",
  "iss": "https://iasid.ondemand.com",
  "azpacr": "1",
  "exp": 1787302610,
  "iat": 1787299010,
  "jti": "096f3ac5-adf2-4516-845b-dd295afbfab0"
}

[2]

IasJwtDecoder            : The token of service IAS was successfully validated.
BearerTokenAuthenticationFilter : Set SecurityContextHolder to JwtAuthenticationToken
    [Principal=org.springframework.security.oauth2.jwt.Jwt@..., Granted Authorities=[]]
SciAuthorizationsProvider : No principal provided. Using empty authorizations.
...
horizationManagerBeforeMethodInterceptor : Failed to authorize ... ProductsService.getProducts()
    ... result AuthorizationDecision [granted=false]
主要言語
Java
スター
0
フォーク
0
平均マージ
4時間 34分
マージ済み PR(30日)
10

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

SAP-samples/ams-samples-java のほかの issue

SAP-samples/ams-samples-java の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。