does anyone have an example of a custom `TokenVali...
# micronaut
r
does anyone have an example of a custom
TokenValidator
in kotlin? struggling a bit with
Type mismatch, Type inference failed
for
Flowable
and
Publisher
s
An example of your current code would be helpful.
r
sure hang on 🙂
so I have this
class BouncerAuthentication: Authentication
and
Copy code
@Singleton
@Requires(notEnv = [ Environment.TEST ])
@Replaces(JwtTokenValidator::class)
class BouncerTokenValidator(): TokenValidator {
    private val logger = KotlinLogging.logger {}

    override fun validateToken(token: String?): Publisher<Authentication> {
        return if (token != null) {
            try {
                Flowable.just(BouncerAuthentication())
            } catch (e: BouncerAccountFacadeException) {
                logger.error(e) { "Exception using authgateway" }
                Flowable.empty()
            }
        } else {
            logger.trace { "Token is missing" }
            Flowable.empty()
        }
    }
}
BouncerTokenValidator.kt: (24, 13): Type mismatch: inferred type is Flowable<BouncerAuthentication!> but Publisher<Authentication> was expected
BouncerTokenValidator.kt: (28, 26): Type inference failed: Not enough information to infer parameter T in fun <T : Any!> empty(): Flowable<T!>!
I get it to compile with a lot of verbosity, i.e. changing to
Flowable.empty<Authentication>()
s
It might be worth asking in the #general channel as it seems general enough.