I want to create a very simple, low load application, and first time decide to use Quarkus framework.
May be it sounds strange, but I want to use Sqlite for database, and authentication by an ip address. App will run in secured LAN, users are only trusted peoples, others are blocked in firewall.
In database I have a table, which contains mapping users and theirs ip addresses.
After reading the docs, I understand that I need to implement my HttpAuthenticationMechanism, that takes user by ip address from that table, and if record in database exists, than return SecurityIdentity (like in io.quarkus.vertx.http.security.HeaderAuthenticator by header).
Problem is that Sqlite seems does not support reactive mode. I wrote this implementation:
class IpAddressAuthenticationMechanism : HttpAuthenticationMechanism {
@Inject
lateinit var entityManager: EntityManager
override fun authenticate(
exchange: RoutingContext?,
identityProviderManager: IdentityProviderManager?
): Uni<SecurityIdentity> {
val ip = exchange!!.request().remoteAddress().hostAddress()
val criteriaBuilder: CriteriaBuilder = entityManager.getCriteriaBuilder()
val criteriaQuery = criteriaBuilder.createQuery(UserAuth::class.java)
val root: Root<UserAuth> = criteriaQuery.from(UserAuth::class.java)
val data = criteriaQuery.select(root).where(criteriaBuilder.equal(root.get<String>("ip"), ip))
return Uni.createFrom().nullItem()
}
...
}
It not finished code, because it fails on val criteriaBuilder: CriteriaBuilder = entityManager.getCriteriaBuilder() with exception:
io.quarkus.runtime.BlockingOperationNotAllowedException: You have attempted to perform a blocking operation on a IO thread. This is not allowed, as blocking the IO thread will cause major performance issues with your application. If you want to perform blocking EntityManager operations make sure you are doing it from a worker thread.
at io.quarkus.hibernate.orm.runtime.session.TransactionScopedSession.checkBlocking(TransactionScopedSession.java:116)
at io.quarkus.hibernate.orm.runtime.session.TransactionScopedSession.getCriteriaBuilder(TransactionScopedSession.java:537)
at org.hibernate.engine.spi.SessionLazyDelegator.getCriteriaBuilder(SessionLazyDelegator.java:699)
at org.hibernate.engine.spi.SessionLazyDelegator.getCriteriaBuilder(SessionLazyDelegator.java:67)
at org.hibernate.Session_OpdLahisOZ9nWRPXMsEFQmQU03A_Synthetic_ClientProxy.getCriteriaBuilder(Unknown Source)
at org.myapp.services.IpAddressAuthenticationMechanism.authenticate(IpAddressAuthenticationMechanism.kt:33)
...
It is possible to query Sqlite database to get users in this place?