• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Company · Blog · Newsletter · Events · Partner Program

Downloads      Support      Security     Admin Login
Rublon

Rublon

Secure Remote Access

  • Product
    • Regulatory Compliance
    • Use Cases
    • Rublon Reviews
    • Authentication Basics
    • What is MFA?
    • Importance of MFA
    • User Experience
    • Authentication Methods
    • Rublon Authenticator
    • Remembered Devices
    • Logs
    • Single Sign-On
    • Access Policies
    • Directory Sync
  • Solutions
    • MFA for Remote Desktop
    • MFA for Remote Access Software
    • MFA for Windows Logon
    • MFA for Linux
    • MFA for Active Directory
    • MFA for LDAP
    • MFA for RADIUS
    • MFA for SAML
    • MFA for RemoteApp
    • MFA for Workgroup Accounts
    • MFA for Entra ID
  • Customers
  • Industries
    • Financial Services
    • Investment Funds
    • Retail
    • Technology
    • Healthcare
    • Legal
    • Education
    • Government
  • Pricing
  • Docs
Contact Sales Free Trial

Rublon Java SDK: Secure Java Apps with MFA

October 9, 2024 By Rublon Authors

Last updated on July 8, 2025

Overview

The Rublon Java SDK library is a client-side implementation of the Rublon API written in Java. It includes methods for connecting with the Rublon API and embedding the service’s GUI in an HTML-based environment. It forms a convenient Java coding language facade for Rublon API’s REST interface.

Use Cases

Rublon adds an extra layer of security by prompting the user to authenticate using an extra authentication method such as Mobile Push. Even if a malicious actor compromises the user’s password, the hacker would not be able to log in to the user’s account because the second secure factor will thwart them.

Rublon can add an extra layer of security in the following two use cases:

  1. When a user signs in to a system (after the user enters the correct password)
  2. When a user undergoes a security-sensitive transaction (such as changing the password or conducting a money transfer)

When a user signs in to a system, the second authentication factor should be initiated only after:

  • the user has successfully completed the first authentication factor (e.g., entered the correct password)
  • the username (and optionally, email address) have been gathered

Supported Authentication Methods

Authentication Method Supported Comments
Mobile Push ✔ N/A
WebAuthn/U2F Security Key ✔ N/A
Passcode ✔ N/A
SMS Passcode ✔ N/A
SMS Link ✔ N/A
Phone Call ✔ N/A
QR Code ✔ N/A
Email Link ✔ N/A
YubiKey OTP Security Key ✔ N/A

Before You Start

Before you start implementing the Rublon Java SDK library into your code, you must create an application in the Rublon Admin Console. We also recommend that you install the Rublon Authenticator mobile app.

Get the SDK

Download the Rublon Java SDK.

Create an Application in the Rublon Admin Console

  1. Sign up for the Rublon Admin Console. Here’s how.
  2. In the Rublon Admin Console, go to the Applications tab and click Add Application.
  3. Enter a name for your application and then set the type to Custom integration using Java SDK.
  4. Click Save to add the new Java SDK application in the Rublon Admin Console.
  5. Copy and save the values of System Token and Secret Key. You are going to need these values later.

Optional: Install Rublon Authenticator

For increased security of Multi-Factor Authentication (MFA), end-users are recommended to install the Rublon Authenticator mobile app.

Download the Rublon Authenticator for:

  • Android
  • iOS
  • HarmonyOS

After installing the mobile app, users can authenticate using the following authentication methods:

  • Mobile Push
  • Mobile Passcode
  • QR Code

In some cases, users may not want to install any additional apps on their phones. Also, some users own older phones that do not support modern mobile applications. These users can authenticate using one of the following authentication methods instead:

  • WebAuthn/U2F Security Keys
  • SMS Passcode
  • SMS Link
  • Email Link
  • WebAuthn/U2F Security Keys
  • YubiKey OTP

Configuration

Follow the steps below to configure Rublon Java SDK.

INFO: Initial Assumptions

Let’s assume there is a session handler class Session. It has access to an object that stores user data of the currently logged-in user. Also, let’s assume there is the HttpServer class which is a simple HTTP server instance.

Classes Session and HttpServer will be used in Java code examples later in this document.

INFO: Modifying the Library

The Rublon class implements a few public methods, which, when needed, can be overridden with inheritance.

We strongly discourage you from modifying any part of the library, as it usually leads to difficulties during library updates. If you need to change the flow or internal structure of the Rublon or RublonCallback classes, do not hesitate to subclass them according to your needs.

Initialize the Library

To initialize the Rublon JAVA SDK library, you need to instantiate a Rublon class object. Its constructor takes three arguments.

Rublon class constructor arguments:

NameTypeDescription
systemTokenStringThe System Token value you copied from the Rublon Admin Console.
secretKeyStringThe Secret Key value you copied from the Rublon Admin Console.
apiServerStringOptional.

Rublon API Server URI.

Default: https://core.rublon.net

Example Java Code

import com.rublon.sdk.twofactor.Rublon;

...

Rublon rublon = new Rublon(
	// system token:
	"A69FC450848B4B94A040416DC4421523",
	// secret key:
	"bLS6NDP7pGjg346S4IHqTHgQQjjSLw3CyApvz5iRjYzgIPN4e9EOi1cQJLrTlvLoHY8zeqg4ILrItYidKJ6JjEUZaA6pR1tZMwSZ"
);

Verify Configuration

The Rublon.checkApplication() method verifies the validity of the configuration. Your application should call this method every time you change or save the configuration. A configuration change can be, for example, changing the systemToken or secretKey.

Rublon.checkApplication() method arguments:

NameTypeDescription
appVerStringThe version of the current application.
paramsJSONObjectOptional.

Additional transaction parameters.

Rublon.checkApplication() may throw one of the following exceptions:

  • ApplicationNotFoundException – Invalid system token
  • InvalidSignatureException – Invalid Secret Key
  • UnsupportedVersionException – Incorrect version of the application

Perform Authentication

The Rublon.auth() method uses the username to check the user’s protection status and returns a URL address the user should be redirected to in their web browser. The method returns null if the user’s protection is not active.

Rublon.auth() method arguments:

NameTypeDescription
callbackUrlStringThe integrated system’s callback URL.
Rublon will redirect the user to this URL after successful authentication
usernameStringThe user’s unique ID, which allows the user to sign in.
Required.
userEmailJSONObjectThe user’s email address.

Optional.

The user’s email address. You only need to provide the email address if you want to use the Email Link authentication method.
paramsJSONObjectOptional.

Additional transaction parameters.

Example Java Code

/**
 * An example method used to log the user in (integrated system's method)
 */
void login(String login, String password) {

	if (loginPreListener()) {
		User user = authenticate(login, password);
		if (user != null) {

			// The user has been authenticated.
			Session.setUser(user);
			loginPostListener();
		}
	}
}


/**
 * Listener (hook) invoked after a successful first factor user authentication,
 * implemented for Rublon integration purposes.
 */
void loginPostListener() {

	Rublon rublon = new Rublon(
		// systemToken (please store in a config):
		"A69FC450848B4B94A040416DC4421523",
		// secretKey (please store in a safe config):
		"bLS6NDP7pGjg346S4IHqTHgQQjjSLw3CyApvz5iRjYzgIPN4e9EOi1cQJLrTlvLoHY8zeqg4ILrItYidKJ6JjEUZaA6pR1tZMwSZ"
	);

	try { // Initiate a Rublon authentication transaction

		String url = rublon.auth(
			"https://example.com/rublon_callback", // callback URL
			Session.getUser().getId(), // User Id
			Session.getUser().getEmail() // User email
		);

		if (url != null) { // User protection is active

			// Log the user out before checking the second factor:
			Session.setUser(null);
	
			// Redirect the user's web browser to Rublon servers
			// to verify the protection:
			HttpServer.sendHeader("Location", url);
		}

	} catch (RublonException e) {
		// An error occurred
		Session.setUser(null);
		HttpServer.setStatus(500);
		HttpServer.setResponse("There was an error, please try again later.");
	}

/* If we're here, the user's account is not protected by Rublon.
The user can be authenticated. */

}

Note: Make sure that your code checks that the user is not signed in. The user should be signed in only after successful Rublon authentication.

Finalize Authentication

After successful authentication, Rublon redirects the user to the callback URL. The callback flow continues and finalizes the authentication process.

Input Params

The callback URL will receive its input arguments in the URL address itself (query string).

Callback URL arguments:

NameTypeDescription
rublonStateStringAuthentication result: ok, error or cancel
rublonTokenStringAccess token (60 alphanumeric characters, upper- and lowercase), which allows verifying the authentication using a background Rublon API connection

Handle Authentication Result

After the callback is invoked, you need to create a RublonCallback subclass instance to properly finalize authentication. Since the RublonCallback class is abstract, you need to create a subclass that implements the methods you need. The implementation is up to you and depends on your requirements and unique system details.

RublonCallback class constructor method arguments:

NameTypeDescription
rublonRublonAn instance of the Rublon class.

Next, call the RublonCallback.call() method.

You should implement the following abstract methods in a subclass.

  • String getState() – returns the “rublonState” parameter from the HTTP GET request.
  • String getAccessToken() – returns the “rublonToken” parameter from the HTTP GET request.
  • void handleCancel() – called when the state parameter is not “ok” nor “error”.
  • void handleError() – called when the state parameter value is “error”.
  • void userAuthenticated(String appUserId) – handle the authenticated user with given user’s local ID.

Example Java Code

An example implementation of the RublonCallback class and usage in the callback:

class Callback extends RublonCallback {

	public String getState() {
		return HttpServer.getRequestHandler().getParam(PARAMETER_STATE);
	}

	public String getAccessToken() {
		return HttpServer.getRequestHandler().getParam(PARAMETER_ACCESS_TOKEN);
	}

	protected void handleCancel() {
		HttpServer.sendHeader("Location", "/login");
	}

	protected void handleError() {
		HttpServer.sendHeader("Location", "/login?msg=rublon-error");
	}

	protected void userAuthenticated(String appUserId) {
		Session.setUser(User.getById(appUserId));
		HttpServer.sendHeader("Location", "/dashboard");
	}
}

...

Rublon rublon = new Rublon(
	"A69FC450848B4B94A040416DC4421523",
	"bLS6NDP7pGjg346S4IHqTHgQQjjSLw3CyApvz5iRjYzgIPN4e9EOi1cQJLrTlvLoHY8zeqg4ILrItYidKJ6JjEUZaA6pR1tZMwSZ"
);

try {
	RublonCallback callback = new Callback(rublon);
	callback.call();
} catch (CallbackException e) {
	// Please handle this error in the better way:
	HttpServer.setStatus(500);
	HttpServer.setResponse("There was an error, please try again later. " + e.getMessage());
}

Troubleshooting

If you encounter any issues with your Rublon integration, please contact Rublon Support.

Filed Under: Documentation

Primary Sidebar

Contents

  • Overview
  • Use Cases
  • Supported Authentication Methods
  • Before You Start
    • Get the SDK
    • Create an Application in the Rublon Admin Console
    • Optional: Install Rublon Authenticator
  • Configuration
    • INFO: Initial Assumptions
    • INFO: Modifying the Library
    • Initialize the Library
      • Example Java Code
    • Verify Configuration
    • Perform Authentication
      • Example Java Code
    • Finalize Authentication
      • Input Params
      • Handle Authentication Result
      • Example Java Code
  • Troubleshooting
Try Rublon for Free
Start your 30-day Rublon Trial to secure your employees using multi-factor authentication.
No Credit Card Required


Footer

Product

  • Regulatory Compliance
  • Use Cases
  • Rublon Reviews
  • Authentication Basics
  • What is MFA?
  • Importance of MFA
  • User Experience
  • Authentication Methods
  • Rublon Authenticator
  • Remembered Devices
  • Logs
  • Single Sign-On
  • Access Policies
  • Directory Sync

Solutions

  • MFA for Remote Desktop
  • MFA for Windows Logon
  • MFA for Remote Access Software
  • MFA for Linux
  • MFA for Active Directory
  • MFA for LDAP
  • MFA for RADIUS
  • MFA for SAML
  • MFA for RemoteApp
  • MFA for Workgroup Accounts
  • MFA for Entra ID

Industries

  • Financial Services
  • Investment Funds
  • Retail
  • Technology
  • Healthcare
  • Legal
  • Education
  • Government

Documentation

  • 2FA for Windows & RDP
  • 2FA for RDS
  • 2FA for RD Gateway
  • 2FA for RD Web Access
  • 2FA for SSH
  • 2FA for OpenVPN
  • 2FA for SonicWall VPN
  • 2FA for Cisco VPN
  • 2FA for Office 365

Support

  • Knowledge Base
  • FAQ
  • System Status

About

  • About Us
  • Blog
  • Events
  • Co-funded by the European Union
  • Contact Us

  • Facebook
  • GitHub
  • LinkedIn
  • Twitter
  • YouTube

© 2025 Rublon · Imprint · Legal & Privacy · Security

  • English