You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -132,16 +132,25 @@ using XSUAA-based authorization (scopes, role collections).
132
132
133
133
#### How Token Exchange Works
134
134
135
-
When a JWT bearer token arrives:
136
-
137
-
1. The library identifies whether the token was issued by IAS or XSUAA
138
-
2. The token is validated using the appropriate validator
139
-
3. If the token is from IAS and exchange is enabled, an XSUAA token is obtained via OAuth2 JWT bearer flow
140
-
4. The XSUAA token contains the user's roles/scopes as defined in XSUAA
141
-
5. Authorization proceeds using familiar XSUAA token attributes
135
+
```
136
+
1. Request arrives with Authorization: Bearer <token>
137
+
2. Library identifies issuer (IAS vs XSUAA) from token claims
138
+
3. Token validated against appropriate identity service
139
+
4. [IF IAS token + exchange enabled]
140
+
├─ Obtain strong IAS ID token (if access token provided)
141
+
├─ Call XSUAA /oauth/token endpoint with JWT bearer grant
142
+
└─ Store exchanged XSUAA token in SecurityContext
143
+
5. [IF exchange disabled OR XSUAA token]
144
+
└─ Use validated token directly
145
+
6. The XSUAA token contains the user's roles/scopes as defined in XSUAA
146
+
7. Authorization proceeds using familiar XSUAA token attributes
147
+
```
142
148
143
149
If the incoming token is already an XSUAA token, no exchange occurs—it's validated and used directly.
144
150
151
+
**Failure Handling**: If token exchange fails (network issues, misconfiguration), authentication fails with 401
152
+
Unauthorized. No silent fallback occurs since IAS access tokens typically lack scopes needed for authorization.
153
+
145
154
#### Token Exchange Modes
146
155
147
156
The [`TokenExchangeMode`](java-security/src/main/java/com/sap/cloud/security/token/TokenExchangeMode.java)enum controls
@@ -168,230 +177,38 @@ The Initial token is still available via the [`SecurityContext.getInitialToken()
168
177
2. IAS service binding must include `xsuaa-cross-consumption: true` parameter
169
178
3. Ensure XSUAA trusts the IAS identity provider
170
179
171
-
#### Token Exchange Flow Summary
172
-
173
-
```
174
-
1. Request arrives with Authorization: Bearer <token>
175
-
2. Library identifies issuer (IAS vs XSUAA) from token claims
176
-
3. Token validated against appropriate identity service
177
-
4. [IF IAS token + exchange enabled]
178
-
├─ Obtain strong IAS ID token (if access token provided)
179
-
├─ Call XSUAA /oauth/token endpoint with JWT bearer grant
180
-
└─ Store exchanged XSUAA token in SecurityContext
181
-
5. [IF exchange disabled OR XSUAA token]
182
-
└─ Use validated token directly
183
-
6. Request proceeds with authenticated security context
184
-
```
185
-
186
-
**Failure Handling**: If token exchange fails (network issues, misconfiguration), authentication fails with 401
187
-
Unauthorized. No silent fallback occurs since IAS access tokens typically lack scopes needed for authorization.
188
-
189
180
#### 2.4.1 Jakarta Example: Using [`HybridTokenAuthenticator`](java-security/src/main/java/com/sap/cloud/security/servlet/HybridTokenAuthenticator.java)
190
181
191
182
For Jakarta EE applications, use [
192
183
`HybridTokenAuthenticator`](java-security/src/main/java/com/sap/cloud/security/servlet/HybridTokenAuthenticator.java) in
For more information, see the [HybridTokenAuthenticator Javadoc](java-security/README.md#hybridtokenauthenticator-usage).
248
187
249
188
#### 2.4.2 Spring Boot Example: Using [`HybridJwtDecoder`](spring-security/src/main/java/com/sap/cloud/security/spring/token/authentication/HybridJwtDecoder.java)
|`Token exchange failed` exception | Missing XSUAA binding or invalid configuration | Verify both IAS and XSUAA service bindings exist |
384
-
| Exchange returns 400 | IAS binding missing `xsuaa-cross-consumption` | Add parameter to IAS service binding |
385
-
| Exchanged token has no scopes | Role mappings not configured in XSUAA | Configure role collections in XSUAA |
386
-
| Memory leak warnings | `SecurityContext` not cleared after request | Call `SecurityContext.clear()` in finally block |
387
-
388
-
**Enable Debug Logging**:
389
-
390
-
```yaml
391
-
logging:
392
-
level:
393
-
com.sap.cloud.security: DEBUG
394
-
```
211
+
| Exchange returns 401 | IAS binding missing `xsuaa-cross-consumption`| Add parameter to IAS service binding |
395
212
396
213
## Installation
397
214
The SAP Cloud Security Services Integration is published to maven central: https://search.maven.org/search?q=com.sap.cloud.security and is available as a Maven dependency. Add the following BOM to your dependency management in your `pom.xml`:
@@ -79,11 +80,12 @@ Since it requires the Tomcat 10 runtime, it needs to be deployed using the [SAP
79
80
## Usage
80
81
### `TokenAuthenticator` usage
81
82
The [`TokenAuthenticator`](/java-api/src/main/java/com/sap/cloud/security/servlet/TokenAuthenticator.java) makes it easy to integrate token based authentication into your java application.
82
-
The library provides 2 default implementations of `TokenAuthenticator` interface:
83
+
The library provides 3 default implementations of `TokenAuthenticator` interface:
83
84
-[XsuaaTokenAuthenticator](src/main/java/com/sap/cloud/security/servlet/XsuaaTokenAuthenticator.java) for Xsuaa Access token validation
84
85
-[IasTokenAuthenticator](src/main/java/com/sap/cloud/security/servlet/IasTokenAuthenticator.java) for Identity OIDC token validation.
86
+
-[HybridTokenAuthenticator](src/main/java/com/sap/cloud/security/servlet/HybridTokenAuthenticator.java) for Identity OIDC token validation with Xsuaa token exchange in hybrid environments.
85
87
86
-
`XsuaaTokenAuthenticator` and `IasTokenAuthenticator` takes care of
88
+
`XsuaaTokenAuthenticator`, `HybridTokenAuthenticator` and `IasTokenAuthenticator` takes care of
87
89
*`OAuth2ServiceConfiguration` loading
88
90
*`org.apache.http.HttpClient` initialization (it's required for signature validation)
89
91
* Jwt Validator setup with help of [`JwtValidatorBuilder`](src/main/java/com/sap/cloud/security/token/validation/validators/JwtValidatorBuilder.java)
@@ -132,6 +134,50 @@ public class XsuaaSecurityFilter implements Filter {
132
134
}
133
135
```
134
136
137
+
#### `HybridTokenAuthenticator` usage
138
+
139
+
The `HybridTokenAuthenticator` is designed for hybrid scenarios where an application needs to validate tokens issued by the Identity service (IAS) and exchange them for tokens issued by the XSUAA service. This is particularly useful when integrating applications that rely on both services for authentication and authorization.
0 commit comments