ABRA Flexi normally authenticates users against its internal user database. However, authentication can also be performed against external systems, such as LDAP. A Java interface is available for this purpose — code written against it runs as part of the server and handles authentication on behalf of ABRA Flexi.
🚨 This interface is experimental and cannot be used in the cloud — it requires your own server installation, with your library added to its classpath. If you want to deploy this feature, please contact our support team beforehand.
The cz.winstrom.auth.Auth Interface
Everything is based on the cz.winstrom.auth.Auth interface:
package cz.winstrom.auth;
import cz.winstrom.vo.UserInfo;
import java.sql.Connection;
/**
*
* Základní rozhraní pro ověřování uživatelů proti jiným službám.
* Její nastavení se provede pomocí nastavení flexibee-server.xml:
*
* <entry key="authClass">cz.winstrom.auth.AuthSimple</entry>
*
* Jako parametr je zde název třídy, kterou je nutné dostat do CLASSPATH serveru.
*
* V tuto chvíli umí aplikace pouze ověření plain heslem.
*
* Kvůli změnám v tomto rozhraní doporučujeme, aby implementátoři dědily
* od abstraktní třídy "AuthBase".
*
* @author fers
*/
public interface Auth {
/**
* Autorizuj uživatele dle jména a hesla.
*
* @param connection napojení do databáze centralServer
* @param userInfo informace o uživateli z centralServer.csuzivatel.
* Pokud je null, žádný takový uživatel neexistuje v hlavní databázi
* uživatelů ABRA Flexi. Při úspěšné autorizaci bude vytvořen.
* @param username jméno uživatele
* @param password heslo uživatele
* @return true pokud bylo heslo zadáno správně.
*/
boolean authenticate(Connection connection, UserInfo userInfo, String username, String password);
/**
* Pokud se povede autorizace, ale uživatel neexistuje v databázi
* centralServer.csuzivatel, bude založen. Autorizační systém může ovlivnit
* informace o založeném uživateli tím, že vyplní třídu UserInfo.
*
* ID se nesmí měnit (má hodnotu -1) i heslo doporučujeme nevyplňovat,
* protože ověření proběhne vždy vůči autorizačnímu systému.
*
* Obvykle se vyplňují pouze přístupová práva (založení firmy, smazání firmy, ...)
*
* @param connection napojení do databáze centralServer
* @param userInfo informace o uživateli, které by měly být vráceny
* (může být vrácena i jiná instance, ale musí být správně vyplněna)
* @return informace o uživateli, které budou uloženy do databáze.
* Obvykle se vrací upravený parametr userInfo.
*/
public UserInfo getUserInfo(Connection connection, UserInfo userInfo);
...
}
⚠️ For a direct implementation, always extend the cz.winstrom.auth.AuthBase or cz.winstrom.auth.AuthBaseV2 class. This allows us to modify the interface while maintaining backward compatibility, and it can also provide default implementations of some methods for you.
Custom Implementation
The implementation of an authorization class itself may look like this:
public class AuthSimple extends AuthBase {
@Override
public boolean authenticate(Connection connection, UserInfo userInfo, String username, String password) {
// jednoduché ověření: jméno a heslo se rovnají
return username.equalsIgnoreCase(password);
}
@Override
public UserInfo getUserInfo(Connection connection, UserInfo userInfo) {
userInfo.setCreateCompany(true); // novému uživateli povolíme založení firmy
return userInfo;
}
}
Two-Factor Authentication
ABRA Flexi supports security through two-factor authentication. This functionality is available in the newer cz.winstrom.auth.AuthBaseV2 class. The following example assumes that you leave verification of the 2FA code to the default implementation in Flexi:
public class OTPAuth extends AuthBaseV2 {
@Override
public boolean authenticate(UserAuthenticationFacade facade, String password, String otp) throws WSNotAuthorizedException, WSBlockedException {
String username = facade.getUsername();
return username.equals("admin") && password.equals("admin") && facade.verifyOtp(otp);
}
@Override
public boolean isTwoPhaseAuthEnabled(UserAuthenticationFacade facade, String username) {
final UserInfo userInfo = facade.getUserInfo();
return userInfo.isTwoPhaseAuthEnabled();
}
}
Server Configuration
The class that the server uses for authentication is specified by the authClass option in the flexibee-server.xml file (where to find it):
<entry key="authClass">cz.winstrom.auth.AuthSimple</entry>
Any additional files must be added to the classpath. On Linux, you do this by uncommenting and populating the CLASSPATH variable in the /etc/default/flexibee file:
CLASSPATH="cesta/ke/knihovne-1.0.jar:cesta/k/auth.jar"
