> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Atoti Limits Java integration

> How to connect an Atoti Server instance to a running Atoti Limits server using the Java auto-configuration module, including the compatibility matrix, setup steps, and troubleshooting guidance

## Overview

The Atoti Limits Java auto-configuration module connects an Atoti Server instance (the “Connected Server”) to a running Atoti Limits server. It uses [Spring Auto-configuration](https://docs.spring.io/spring-boot/reference/using/auto-configuration.html) to bootstrap the required services and send a connection request to Atoti Limits.

This module enables Atoti Limits to manage limits on data served by Atoti Server. Once connected, Atoti Limits can evaluate limits against the measures and hierarchies exposed by the Connected Server.

> [!NOTE]
>
> Atoti Limits does not require the connected server to be an ActiveViam Business Solution, it
> can be any instance of Atoti Server.

The auto-configuration resides in the `limits-auto-config-*` modules. These modules are responsible for bootstrapping the Connected Server with any services required by Atoti Limits and for sending a connection request to Atoti Limits with required information.

## Compatibility matrix

This table lists the versions of Atoti Server compatible with each Atoti Limits
version. If you are using a solution, please check the
underlying version of Atoti Server to see if your version of the solution is compatible.

| Atoti Limits version | Atoti Server version |
| - | - |
| 6.2.2+ | 6.1.x, 6.2.x |
| 6.2.0-6.2.1 | 6.0.x, 6.0.x-sb3, 6.1.x, 6.2.x |
| 6.1.25+ | 6.1.x, 6.2.x |
| 6.1.20-6.1.24 | 6.0.x, 6.0.x-sb3, 6.1.x, 6.2.x |
| 4.2 | 6.0.x, 6.0.x-sb3, 6.1.x |
| 4.1 | 6.0.x, 6.0.x-sb3, 6.1.x |

## Prerequisites

The connected Atoti server must meet the requirements in [What do you need before you connect?](../connect#what-do-you-need-before-you-connect).

## How does the connection process work?

The Connected Server initiates the connection, and Atoti Limits then connects back to it:

1. When the Connected Server starts, it checks that Atoti Limits is available and sends it a connection
   request containing the details Atoti Limits needs to connect.
2. Atoti Limits connects to the Connected Server and starts managing its limits.

> [!NOTE]
>
> You can start the two servers in either order.

Atoti Limits keeps managing every Connected Server it is connected to for as long as it runs.

## How to integrate a Connected Server with Atoti Limits

Follow these steps to integrate a Connected Server with Atoti Limits.

### Step 1: Import the auto-configuration dependency in the Connected Server

The `limits-auto-config-*` Maven dependency must be added to the Connected Server project. The correct artifact depends on the version of Atoti Server in use.

Add the following dependency to the project `pom.xml` file:

```xml theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
<dependency>
  <groupId>com.activeviam.modules.limits</groupId>
  <artifactId>limits-auto-config-{VERSION}</artifactId>
  <version>{ATOTI-LIMITS-MODULE-VERSION}</version>
</dependency>
```

The following table lists each artifact and its compatible Java versions:

| Atoti Server version | Auto-config artifact | Compatible Java versions |
| - | - | - |
| 6.1.X | limits-auto-config-61 | 21 |
| 6.2.X | limits-auto-config-62 | 25 |

### Step 2: Configure the auto-configuration properties in the Connected Server

The auto-configuration module requires a set of properties to establish the connection. Configure these properties in the `application.yml` file on the **Connected Server**.

The full list of properties is available in the [Auto-configuration properties section](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/reference/properties/config-properties/limits-integration-common.md).

> [!NOTE]
>
> Not all properties are required, but they are all listed in the event that your Connected Server is
> unable to derive the properties automatically.

### How to secure the auto-configuration REST endpoints

The auto-configuration module adds several REST endpoints to the Connected Server, for example to receive
connection requests and limit change events from Atoti Limits. Spring Security requires a filter chain for
them. Either the application declares one itself, or it lets the auto-configuration module register one.

Setting `limits.autoconfiguration.security.enabled` to `true` on the **Connected Server** registers a dedicated
Spring Security filter chain for these endpoints, built with the Connected Server's
`MachineToMachineSecurityDsl` like the Atoti Server ones. It handles JWT and HTTP Basic authentication, CORS
and CSRF the same way. Every request to these endpoints must be authenticated; no particular role is required.
`OPTIONS` requests (CORS preflight) are always permitted.

This property is `false` by default, so an application that does not set it keeps its existing security
configuration unchanged.

```yaml theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
limits:
  autoconfiguration:
    security:
      enabled: true
```

> [!NOTE]
>
> This chain requires a `MachineToMachineSecurityDsl` bean, which the Atoti Server Spring Boot starter
> (`atoti-server-starter`, Atoti Server 6.1 and later) provides. It is skipped on Connected Servers where that
> class is not on the classpath.

The chain covers the following endpoints:

| Endpoint | Purpose |
| - | - |
| `/limits/autoconfig/**` | Connection management and connection status |
| `/activeviam/limits/rest/v2/**` | Limit retrieval for the KPI drawer and the MDX data export used by Atoti Limits to evaluate limits |
| `/activeviam/inter-server-event-listener/rest/v1/**` | Limit change events pushed by Atoti Limits |
| `/services/rest/v1/levelPath/**` | Parent-child level path resolution used by Atoti Limits |

The Atoti Limits service principal, set by `limits.autoconfiguration.service-principal`, authenticates the
calls Atoti Limits makes to the Connected Server. UI users authenticate their own calls to the KPI drawer
endpoint.

### Step 3: Configure the inter-server-event-service properties in Atoti Limits

The Atoti Limits server needs to know where to find the Connected Server. Set the following configuration properties in the `application.yml` file on the **Atoti Limits server**.

```yaml theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
activeviam:
  apps:
    inter-server-event-service:
      issuer:
        target-servers:
          - name: <Connected Server>
            url: <Connected Server URL>
```

where:

* `<Connected Server>` is the name of the Connected Server and should be the same as the value (defined or auto-configured) of `limits.autoconfiguration.server-name` in the connected server.
* `<Connected Server URL>` is the URL of the Connected Server and should be the same as the value (defined or auto-configured) of `limits.autoconfiguration.atoti-base-url` in the connected server.

### Step 4: Start the servers

The order in which the servers start does not matter.

#### Start the Limits server

Start the Limits server using the [installation instructions](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/dev/install/install-and-run.md#how-to-install-the-starter-project).
Limits will wait for a connection from the Atoti Server.

#### Start the Connected Server

Start the Connected Server as normal. This should trigger a connection request.

## Troubleshooting

If the connection is unsuccessful, enable `debug` logging for further investigation.

> [!TIP]
>
> If KPIs are missing from the UI although they exist in the content server, set `contentServer.context-values.ignore`
> to `false`.
