ABRA Flexi normally authenticates users against an internal user database. However, it is also possible to authenticate against external systems, such as LDAP. For this purpose, there is a Java interface — code written this way 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 beforehand.
The cz.winstrom.auth.Auth interface
The foundation of everything is 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 direct implementation, always inherit from the class cz.winstrom.auth.AuthBase or cz.winstrom.auth.AuthBaseV2. This allows us to change the interface while maintaining backward compatibility, and lets us pre-implement some methods for you.
Custom implementation
The implementation of the authorization class itself might 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 using two-factor authentication. This functionality is available in the newer cz.winstrom.auth.AuthBaseV2 class. The following example assumes that you leave 2FA password verification 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
Which class the server should use for authentication is determined by the authClass option in the flexibee-server.xml file (where to find it):
<entry key="authClass">cz.winstrom.auth.AuthSimple</entry>
Additional files must be added to the classpath. On Linux, you do this by uncommenting and filling in the CLASSPATH variable in the /etc/default/flexibee file:
CLASSPATH="cesta/ke/knihovne-1.0.jar:cesta/k/auth.jar"
