ams-spring-boot-shopping: `/products` always returns 403
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 72/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- java, spring-boot
- Bereich
- api, authentication, backend, security
Rechercherichtung
Beginne in ams-spring-boot-shopping/src/main/java/com/sap/cloud/security/ams/samples/config/SecurityConfiguration.java bei SecurityConfiguration#filterChain. Wiederhole die Anfrage mit einem gültigen IAS-Token und untersuche anschließend, wie der Resource Server das Jwt konvertiert, bevor die AMS-Autorisierung ausgeführt wird. Als erledigt gilt, dass der AMS-Principal etabliert ist und GET /products sowie GET /privileges die erwarteten autorisierten Antworten statt 403 zurückgeben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- 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.
- Obtain a valid IAS token for the consumer app. Make sure to hit the right dependency. Should look like [1]
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:
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]
- Vorherrschende Sprache
- Java
- Sterne
- 0
- Forks
- 0
- Ø Merge
- 4 Std. 34 Min.
- Gemergte PRs (30 T.)
- 10
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus SAP-samples/ams-samples-java
-
docs: Javalin sample README claims AMS authorization is an unimplemented TODO, but it is fully implementedEvtl. vergeben @finkmanAtSap hat das vor 22 Tagen übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
SAP-samples/ams-samples-java#98 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in SAP-samples/ams-samples-java
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
objectionary/lints#1556 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
wildfly/wildfly-launcher#99 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
apache/rocketmq#11427 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag