9.2 Update Application Configuration with IAM Details
To enforce data access control using Oracle Deep Data Security (Deep Sec), the application must pass an end-user security context payload to the database with every SQL operation through an Oracle client driver.
This section describes how to configure an application to build and propagate this payload for all deployment scenarios where end users connect to the database through the application, regardless of whether those users are IAM-managed or maintained in the application's own user store.
Note:
You must configure the database server for TLS before configuring the application. The client-side trust store requires the server certificate to establish trust. For TLS configuration, see Configuring Transport Layer Security Encryption in Oracle AI Database Security Guide.9.2.1 Understand Authentication Flow and Prerequisites
Review the authentication concepts and gather the necessary credentials before modifying your application configuration.
Authentication flow
EndUserSecurityContext payload to the database,
you must register your application as a confidential client in an
IAM system. During runtime, the application must typically acquire
and manage two distinct tokens to build the security context
payload:
- End-user token: An OAuth 2.0 access token generated when the end user logs in through the browser. This token establishes the user's identity and role claims (app roles in Microsoft Entra ID or group memberships in OCI IAM).
- Database-access token: A token the application obtains to authorize itself to access the database resource. This is acquired through the on-behalf-of (OBO) flow or the client credentials flow.
The application passes these tokens as part of the
EndUserSecurityContext payload on the
database connection; the database-access token authorizes the
connection, and the end-user token supplies the user identity and
role claims used to enforce data security.
Required credentials
Before proceeding, ensure you have gathered the following values from your application's IAM registration:
- Client ID: The unique identifier assigned to your application.
- Client secret: The secret key generated for the application.
- Tenant ID (Entra ID) / Domain URL (OCI IAM): The identifier for your IAM instance.
- Database Scope: The scope required
to access the database resource (for example,
[DB_APP_ID_URI]/sessions:scope:connectin Entra ID or[primary_audience]DB_ACCESS_SCOPEin OCI IAM).
9.2.2 Configure Java Applications
The Oracle JDBC driver supports two approaches for propagating the end-user security context payload from your Java application to the database: API extension methods and a configuration-driven Service Provider Interface (SPI). API calls take precedence over provider-based configurations.
9.2.2.1 Use the API Extension Methods
If you want to supply the end-user security context payload directly in your application code, use the API extension methods.
oracle.jdbc.OracleConnection interface within your Java code to
manually set and clear the security context payload.
9.2.2.2 Use the Service Provider Interface
The Service Provider Interface (SPI) approach enables your Java application to supply the end-user security context payload without requiring modifications to your core application code.
Oracle JDBC defines a Java interface named
oracle.jdbc.spi.EndUserSecurityContextProvider. This interface
is designed to work as a standard service provider interface that is dynamically
loaded by Java's java.util.ServiceLoader class. This design allows
you to implement the interface by integrating with different Java security
technologies to provide a security context payload to Oracle JDBC.
By simply installing and configuring a provider implementation, you can enable your application to automatically propagate the security context payload to the database before each SQL operation. The SPI approach also allows you to integrate with different IAM-specific providers without changing how your application interacts with the JDBC driver.
To supply the security context payload using the SPI approach, perform the following tasks.
9.2.2.3 Example: Use the JDBC Spring Boot Provider (The SPI Approach)
The JDBC Spring Boot provider is an out-of-the-box (OOTB) security context payload provider for the Oracle JDBC driver. It automates the propagation of the end-user security context payload from Spring Security (OAuth 2.0) to the database through the JDBC connection. In most cases, no application code changes are necessary.
application.properties file. You must link the data
source to the OAuth registration using the
registrationId.
Note:
The OOTB JDBC Spring Boot provider may not support custom or non-standard authentication and authorization workflows. If the provider doesn’t meet your requirements, you can build a custom provider. See Advanced: Implement a Security Context Provider.9.2.3 Configure Python Applications
The python-oracledb driver supports two approaches for propagating the end-user security context payload from your Python application to the database: API extension methods and a configuration-driven Service Provider Interface (SPI). API calls take precedence over provider-based configurations.
9.2.3.1 Use the API Extension Methods
If you want to supply the end-user security context payload directly in your application code, use the API extension methods.
The python-oracledb driver extends the standard Python Database API with
the Connection methods to set and clear the end-user security
context payload. Currently, you can use this feature only in python-oracledb's Thin
mode.
To supply the security context payload using the python-oracledb driver, perform the following tasks.
Note:
If no end-user identity is present, the plug-in does not attach the end-user security context payload, and the application receives a least-privileged connection or session (standard behavior) and no error is thrown.9.2.3.2 Use the Service Provider Interface
The Service Provider Interface (SPI) approach enables your Python application to supply the end-user security context payload with no code changes to your SQL or Object Relational Mapping (ORM) layer.
The python-oracledb driver's end_user_sec_provider
plug-in acts as the SPI provider. By importing the plug-in and adding a
configuration block to your application's database settings, you can enable your
application to automatically propagate the security context payload on every
database operation. The plug-in supports both the
client_credentials and on_behalf_of (OBO)
authentication flows for Microsoft Entra ID, and the
client_credentials flow for OCI IAM.
To supply the security context payload using the SPI approach, perform the following tasks.
9.2.4 Configure .NET Applications
The ODP.NET driver supports Oracle Deep Data Security (Deep Sec) by propagating the end-user security context payload from your .NET application to the database.
9.2.5 Advanced: Implement a Security Context Provider
If your authentication and authorization workflow requires custom logic, or if there's no out-of-the-box (OOTB) security context provider available for your application framework, you can build your own provider.
A custom provider bridges your application's security context and the Oracle client driver, enabling automatic propagation of the end-user security context payload to the database without modifying your application code.
The instructions in this section are primarily for the Oracle JDBC driver and Java-based application frameworks. If you are using a different client driver (such as python-oracledb or ODP.NET), apply the same principles using the equivalent provider interface and registration mechanism in your driver. See the respective driver documentation for API details.
9.2.5.1 Understand the Security Context Payload
Before building a provider, understand the components of the end-user security context payload that the database expects. Every payload must include the following mandatory components and may include optional components.
- End-user identity (mandatory): The end user's name as asserted in the IAM access token. For end users managed locally, this is the name of the end user created in the database.
- Database access token (mandatory): Authorizes the
application’s connection to the database. Obtain this token from your IAM
system using one of the following flows:
- Client credentials flow: The application authenticates as itself.
- On-behalf-of (OBO) flow: The application exchanges the end-user’s token for a database-access token.
- Data roles (optional): A list of additional data roles that the application can enable for the end-user security context, beyond those mapped to application roles in IAM and those enabled by default for the application identity.
- Context attributes (optional): A dictionary of application-defined key-value pairs to include in the security context. Used when application logic or data grants rely on custom end-user context attributes.
9.2.5.2 Understand the Driver’s Provider Interface
To propagate the end-user security context payload, the Oracle JDBC driver
defines a Service Provider Interface (SPI) named
EndUserSecurityContextProvider. Your custom provider must implement
this interface and its getEndUserSecurityContext() method.
getEndUserSecurityContext() before every
database operation on the connection. Your implementation must return an
EndUserSecurityContext object containing the end-user identity,
database-access token, and any optional data roles or attributes. The driver
piggybacks this payload to the database on the next round-trip. If the method
returns null, the driver proceeds without attaching a security context payload.
Note:
For other client drivers, use the equivalent provider interface. For example, the python-oracledb driver'send_user_sec_provider plug-in uses a configuration-driven
mechanism with middleware hooks. See the respective driver documentation for the
specific interface contract.
9.2.5.3 Build the Security Context Provider
Your provider implementation must perform three tasks each time the driver
calls getEndUserSecurityContext(). The following steps describe these tasks
for a JDBC provider. Adapt the approach to your client driver as needed.
9.2.5.4 Register the Provider with the Driver
The JDBC driver discovers your provider through the standard Java
ServiceLoader mechanism.
9.2.5.5 Configure the Driver to Use Your Provider
Set the oracle.jdbc.provider.endUserSecurityContext
connection property to the name of your provider.
This name is the value returned by your provider’s getName() method.
Set this property in your connection pool’s data source configuration.
# Activate the custom provider
spring.datasource.hikari.data-source-properties.\
oracle.jdbc.provider.endUserSecurityContext = my-custom-provider
Properties props = new Properties();
props.setProperty(
"oracle.jdbc.provider.endUserSecurityContext",
"my-custom-provider"
);
dataSource.setDataSourceProperties(props);
9.2.5.6 Support Privilege Elevation (Optional)
Some application operations require temporary elevated privileges. For example, reading all employees’ salary data to generate a summary report. To support this, your provider can accept additional data roles injected at runtime for the duration of a specific code block.
- Application code temporarily adds data roles (with a distinguishing prefix) to the framework’s security context before the database call.
- The provider reads the prefixed roles from the security context
and includes them in the
EndUserSecurityContextpayload. - After the method returns, the application restores the original security context.
To implement this pattern in your framework, use the equivalent of a method
interceptor or decorator that wraps the target method, augments the security context
with additional data roles, invokes the method, and restores the original context in
a finally block.
For the Spring Boot reference implementation of this pattern (using
GrantedAuthority and the @RunWithDataRoles
annotation), see the Oracle JDBC Extensions source code on GitHub.
9.2.5.7 Note for Other Client Drivers
If your application uses python-oracledb or ODP.NET instead of JDBC, the same architectural pattern applies: implement a component that extracts the end-user identity, acquires the database-access token, constructs the security context payload, and hooks into the driver’s connection life cycle. The specific interfaces, registration mechanisms, and configuration properties differ by driver.
For the python-oracledb driver, see the python-oracledb documentation.
For the ODP.NET driver, see the Oracle Data Provider for .NET documentation.