# Floating Server V2

## Authentication Methods

### login

{% code title="Signature" %}

```java
public LoginResponse login(LoginRequest payload) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* payload (LoginRequest): Login credentials containing username and password

**Returns:** LoginResponse - Authentication response containing token and user information

**Throws:**

* LicenseSpringException - If authentication fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Logs in a user with the provided credentials and returns an authentication token. Only available with Floating Server v2 API.

## Configuration Methods

### changePassword

{% code title="Signature" %}

```java
public ChangePasswordResponse changePassword(ChangePasswordRequest payload) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* payload (ChangePasswordRequest): Contains username, old password, and new password

**Returns:** ChangePasswordResponse - Response indicating success or failure of password change

**Throws:**

* LicenseSpringException - If password change fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Changes the password for the specified user. Only available with Floating Server v2 API.

## License Management Methods

### getLicenses

{% code title="Signature" %}

```java
public List<LicenseData> getLicenses() throws LicenseSpringException
```

{% endcode %}

**Returns:** List\<LicenseData> - List of all licenses for the product (empty list if none found)

**Throws:**

* LicenseSpringException - If the request fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Fetches all licenses associated with the product specified in ProxyConfiguration. Only available with Floating Server v2 API.

### getLicenseById

{% code title="Signature" %}

```java
public LicenseData getLicenseById(Long id) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* id (Long): The license identifier

**Returns:** LicenseData - Complete license object with details

**Throws:**

* LicenseSpringException - If the request fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Retrieves comprehensive license details by ID. Only available with Floating Server v2 API.

### addLicenseV2

{% code title="Signature" %}

```java
public AddLicenseResponse addLicenseV2(AddLicenseParams params) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* params (AddLicenseParams): License activation parameters containing the license key

**Returns:** AddLicenseResponse - Activation result details

**Throws:**

* LicenseSpringException - If activation fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Activates a product license using the license key. The product is taken from ProxyConfiguration. Only available with Floating Server v2 API.

### removeLicenseById

{% code title="Signature" %}

```java
public RemoveLicenseResponse removeLicenseById(Long id) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* id (Long): The license identifier to remove

**Returns:** RemoveLicenseResponse - Response message indicating success

**Throws:**

* LicenseSpringException - If removal fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Removes the specified license from the floating server. Only available with Floating Server v2 API.

### borrowLicenseV2

{% code title="Signature" %}

```java
public BorrowLicenseResponse borrowLicenseV2(Long licenseId, BorrowLicenseParams payload) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* licenseId (Long): The license identifier
* payload (BorrowLicenseParams): Borrow parameters containing username and borrowedUntil timestamp

**Returns:** BorrowLicenseResponse - Borrow operation result

**Throws:**

* LicenseSpringException - If borrowing fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Borrows a license slot for offline usage. The borrowedUntil timestamp is converted to UTC and formatted as ISO offset date-time. Only available with Floating Server v2 API.

## User Management Methods

### addUser

{% code title="Signature" %}

```java
public AddUserResponse addUser(AddUserRequest payload) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* payload (AddUserRequest): User details to add

**Returns:** AddUserResponse - Response containing added user information

**Throws:**

* LicenseSpringException - If user addition fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Creates a new user on the floating server. Only available with Floating Server v2 API.

### removeUser

{% code title="Signature" %}

```java
public RemoveUserResponse removeUser(RemoveUserRequest payload) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* payload (RemoveUserRequest): User details to remove

**Returns:** RemoveUserResponse - Response confirming user removal

**Throws:**

* LicenseSpringException - If user removal fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Deletes a user from the floating server. Only available with Floating Server v2 API.

### registerUserToLicenseV2

{% code title="Signature" %}

```java
public LicenseData registerUserToLicenseV2(Long licenseId, RegisterUserToLicenseRequest payload) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* licenseId (Long): The license identifier
* payload (RegisterUserToLicenseRequest): User registration details

**Returns:** LicenseData - Updated license data after user registration

**Throws:**

* LicenseSpringException - If registration fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Registers a user to the specified license with allowed registrations. Only available with Floating Server v2 API.

### unregisterUserFromLicenseV2

{% code title="Signature" %}

```java
public void unregisterUserFromLicenseV2(Long licenseId, UnregisterUserFromLicenseRequest payload) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* licenseId (Long): The license identifier
* payload (UnregisterUserFromLicenseRequest): User unregistration details

**Throws:**

* LicenseSpringException - If unregistration fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Unregisters a user from the specified license, freeing up a user slot. Only available with Floating Server v2 API.

## Feature Management Methods

### registerFeatureForUserV2

{% code title="Signature" %}

```java
public RegisterFeatureForUserResponse registerFeatureForUserV2(Long licenseId, RegisterFeatureForUserRequest payload) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* licenseId (Long): The license identifier
* payload (RegisterFeatureForUserRequest): Feature registration details containing user and feature code

**Returns:** RegisterFeatureForUserResponse - Registration result

**Throws:**

* LicenseSpringException - If registration fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Registers a feature allocation for a user under the specified license. Only available with Floating Server v2 API.

### unregisterFeatureForUserV2

{% code title="Signature" %}

```java
public void unregisterFeatureForUserV2(Long licenseId, UnregisterFeatureForUserRequest payload) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* licenseId (Long): The license identifier
* payload (UnregisterFeatureForUserRequest): Feature unregistration details containing user and feature code

**Throws:**

* LicenseSpringException - If release fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Releases a feature allocation for a user, freeing up the feature slot. Only available with Floating Server v2 API.

## Consumption Tracking Methods

### addConsumptionToLicenseV2

{% code title="Signature" %}

```java
public AddConsumptionToLicenseResponse addConsumptionToLicenseV2(Long licenseId, AddConsumptionToLicenseRequest payload) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* licenseId (Long): The license identifier
* payload (AddConsumptionToLicenseRequest): Consumption details to record

**Returns:** AddConsumptionToLicenseResponse - Consumption recording result

**Throws:**

* LicenseSpringException - If consumption recording fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Records consumption usage against the specified license. Only available with Floating Server v2 API.

### addConsumptionToFeatureV2

{% code title="Signature" %}

```java
public AddConsumptionToFeatureResponse addConsumptionToFeatureV2(Long licenseId, AddConsumptionToFeatureRequest payload) throws LicenseSpringException
```

{% endcode %}

**Parameters:**

* licenseId (Long): The license identifier
* payload (AddConsumptionToFeatureRequest): Feature consumption details to record

**Returns:** AddConsumptionToFeatureResponse - Feature consumption recording result

**Throws:**

* LicenseSpringException - If consumption recording fails
* UnsupportedOperationException - If using Floating Server v1 API

**Description:** Records consumption usage against a specific feature within the license. Only available with Floating Server v2 API.

## Getting Started

{% stepper %}
{% step %}

### Configure Proxy and Product

{% code title="ProxyConfiguration.java" %}

```java
ProxyConfiguration proxyConfiguration =
        ProxyConfiguration.builder()
            .host("localhost")
            .port(8080)
            .proxyUser("admin")
            .proxyPass("admin")
            .product("<productCode>")
            .proxyCertPath("proxyCertFromProvisionedInstance")
            .build();
```

{% endcode %}
{% endstep %}

{% step %}

### Initialize Service

{% code title="InitService.java" %}

```java
ProxyFloatingService service = new ProxyFloatingService(proxyConfiguration);
```

{% endcode %}
{% endstep %}

{% step %}

### Add a New User

Default user created is admin/admin.

{% code title="AddUser.java" %}

```java
AddUserRequest addUserReq =
        AddUserRequest.builder()
            .email("<email>")
            .username("<username>")
            .password("<password>")
            .role("admin")
            .build();

service.addUser(addUserReq);
```

{% endcode %}
{% endstep %}

{% step %}

### Retrieve Licenses

{% code title="GetLicenses.java" %}

```java
List<LicenseData> licenses = service.getLicenses();

// Pick license out of available ones
LicenseData license = licenses.get(0);

Long licenseId = license.getId();
```

{% endcode %}
{% endstep %}

{% step %}

### Register User to License

{% code title="RegisterUser.java" %}

```java
RegisterUserToLicenseRequest req =
        RegisterUserToLicenseRequest.builder()
            .email("<email>")
            .username("<username>")
            .build();

service.registerUserToLicenseV2(licenseId, req);
```

{% endcode %}
{% endstep %}
{% endstepper %}

{% hint style="info" %}
Note: All methods documented here are only available when using Floating Server v2 API. The service automatically detects API version on initialization.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.licensespring.com/sdks/java-sdk/floating-server-v2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
