Security and Authorization with the .NET Client

Tip
The source code for this tutorial is available on GitHub.

This tutorial demonstrates how Infinispan cache authorization works by creating a cache that requires a specific role and attempting to access it.

Prerequisites

  • A running Infinispan server with authorization enabled (default).

  • .NET 10 or later.

Running the Example

dotnet run --project security

Code Walkthrough

Creating a Secured Cache

Create a cache with role-based authorization. Only users with the deployer role can access this cache.

const string securedConfig = """
    <distributed-cache name="secured">
        <security>
            <authorization roles="deployer"/>
        </security>
    </distributed-cache>
    """;
await admin.GetOrCreateCache("secured", securedConfig);

Demonstrating Authorization

The admin user can write to a normal cache but not to the secured cache, because admin does not have the deployer role.

Expected Output

Normal cache: put succeeded.
Secured cache: put failed as expected: ...