CreateWithDatabaseAccessToken

This static method creates a new end-user security context using a database access token only.

Declaration

// C#
public static OracleEndUserSecurityContext CreateWithDatabaseAccessToken(string databaseAccessToken)

Parameters

Return Value

A new OracleEndUserSecurityContext initialized with the database token provided.

Exceptions

ArgumentException - Thrown if the databaseAccessToken is null or empty.

ODP.NET may throw additional exceptions while parsing the token or verifying that it has not expired.

Remarks

Use this method when an application can supply a database access token but does not have an end-user token nor name.

This method verifies that the database access token is present and unexpired before creating the security context.

Applications can use the returned context or derive a new immutable context with data roles or application context attributes by calling CreateWithNewDataRoles or CreateWithNewAttributes.

Sample Code

The following sample creates a security context with an existing database access token value and applies it to an open connection.

// C#
using Oracle.ManagedDataAccess.Client;
string connectionString = "<CONNECTION STRING>";
string databaseAccessToken = GetDatabaseAccessToken();
using (OracleConnection connection = new OracleConnection(connectionString))
{
  connection.Open();
  OracleEndUserSecurityContext securityContext =
    OracleEndUserSecurityContext.CreateWithDatabaseAccessToken(databaseAccessToken);
  connection.SetEndUserSecurityContext(securityContext);
  using (OracleCommand command = connection.CreateCommand())
  {
    command.CommandText = "select count(*) from employees";
    object result = command.ExecuteScalar();
  }
}

The following sample creates a security context with an existing database access token, new data roles, and new application context attributes without an end user identity.

// C#
using Oracle.ManagedDataAccess.Client;
string databaseAccessToken = GetDatabaseAccessToken();
OracleEndUserSecurityContext securityContext =
  OracleEndUserSecurityContext
    .CreateWithDatabaseAccessToken(databaseAccessToken)
    .CreateWithNewDataRoles("SALES_READ", "REPORT_VIEWER")
    .CreateWithNewAttributes("HR.APPCTX", "{ \"department\": \"SALES\" }");

See Also: