### Question:
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); } } OtpAuthenticationProvider(OtpService otpService, NiFiProperties nifiProperties, Authorizer authorizer); @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> authentication);  }### Answer:
@Test public void testUiExtensionPath() throws Exception { final OtpAuthenticationRequestToken request = new OtpAuthenticationRequestToken(UI_EXTENSION_TOKEN, false, null); final NiFiAuthenticationToken result = (NiFiAuthenticationToken) otpAuthenticationProvider.authenticate(request); final NiFiUserDetails details = (NiFiUserDetails) result.getPrincipal(); assertEquals(UI_EXTENSION_AUTHENTICATED_USER, details.getUsername()); verify(otpService, times(1)).getAuthenticationFromUiExtensionToken(UI_EXTENSION_TOKEN); verify(otpService, never()).getAuthenticationFromDownloadToken(anyString()); }
@Test public void testDownload() throws Exception { final OtpAuthenticationRequestToken request = new OtpAuthenticationRequestToken(DOWNLOAD_TOKEN, true, null); final NiFiAuthenticationToken result = (NiFiAuthenticationToken) otpAuthenticationProvider.authenticate(request); final NiFiUserDetails details = (NiFiUserDetails) result.getPrincipal(); assertEquals(DOWNLOAD_AUTHENTICATED_USER, details.getUsername()); verify(otpService, never()).getAuthenticationFromUiExtensionToken(anyString()); verify(otpService, times(1)).getAuthenticationFromDownloadToken(DOWNLOAD_TOKEN); }