class OtpAuthenticationProvider extends NiFiAuthenticationProvider {

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        final OtpAuthenticationRequestToken request = (OtpAuthenticationRequestToken) authentication;

        try {
            final String otpPrincipal;
            if (request.isDownloadToken()) {
                otpPrincipal = otpService.getAuthenticationFromDownloadToken(request.getToken());
            } else {
                otpPrincipal = otpService.getAuthenticationFromUiExtensionToken(request.getToken());
            }
            final String mappedIdentity = mapIdentity(otpPrincipal);
            final NiFiUser user = new Builder().identity(mappedIdentity).groups(getUserGroups(mappedIdentity)).clientAddress(request.getClientAddress()).build();
            return new NiFiAuthenticationToken(new NiFiUserDetails(user));
        } catch (OtpAuthenticationException e) {
            throw new InvalidAuthenticationException(e.getMessage(), e);
        }
    }

    public  OtpAuthenticationProvider(OtpService otpService, NiFiProperties nifiProperties, Authorizer authorizer);

}