@Test @WithMockUser(value = USERNAME, roles = ROLE_SU) void testGetAuthenticatorURI() { when(appSettings.getTitle()).thenReturn("MOLGENIS"); String uri = otpServiceImpl.getAuthenticatorURI("secretKey"); assertFalse(uri.isEmpty()); }
@Override public String getAuthenticatorURI(String secretKey) { String userName = SecurityUtils.getCurrentUsername(); String appName = appSettings.getTitle(); if (userName == null) { String errorMessage = "User is not available"; LOG.error(errorMessage); throw new IllegalStateException(errorMessage); } String normalizedBase32Key = secretKey.replace(" ", "").toUpperCase(); try { return String.format( "otpauth: URLEncoder.encode(appName + ":" + userName, "UTF-8").replace("+", "%20"), URLEncoder.encode(normalizedBase32Key, "UTF-8").replace("+", "%20"), URLEncoder.encode(appName, "UTF-8").replace("+", "%20")); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
OtpServiceImpl implements OtpService { @Override public String getAuthenticatorURI(String secretKey) { String userName = SecurityUtils.getCurrentUsername(); String appName = appSettings.getTitle(); if (userName == null) { String errorMessage = "User is not available"; LOG.error(errorMessage); throw new IllegalStateException(errorMessage); } String normalizedBase32Key = secretKey.replace(" ", "").toUpperCase(); try { return String.format( "otpauth: URLEncoder.encode(appName + ":" + userName, "UTF-8").replace("+", "%20"), URLEncoder.encode(normalizedBase32Key, "UTF-8").replace("+", "%20"), URLEncoder.encode(appName, "UTF-8").replace("+", "%20")); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } } }
OtpServiceImpl implements OtpService { @Override public String getAuthenticatorURI(String secretKey) { String userName = SecurityUtils.getCurrentUsername(); String appName = appSettings.getTitle(); if (userName == null) { String errorMessage = "User is not available"; LOG.error(errorMessage); throw new IllegalStateException(errorMessage); } String normalizedBase32Key = secretKey.replace(" ", "").toUpperCase(); try { return String.format( "otpauth: URLEncoder.encode(appName + ":" + userName, "UTF-8").replace("+", "%20"), URLEncoder.encode(normalizedBase32Key, "UTF-8").replace("+", "%20"), URLEncoder.encode(appName, "UTF-8").replace("+", "%20")); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } } OtpServiceImpl(AppSettings appSettings); }
OtpServiceImpl implements OtpService { @Override public String getAuthenticatorURI(String secretKey) { String userName = SecurityUtils.getCurrentUsername(); String appName = appSettings.getTitle(); if (userName == null) { String errorMessage = "User is not available"; LOG.error(errorMessage); throw new IllegalStateException(errorMessage); } String normalizedBase32Key = secretKey.replace(" ", "").toUpperCase(); try { return String.format( "otpauth: URLEncoder.encode(appName + ":" + userName, "UTF-8").replace("+", "%20"), URLEncoder.encode(normalizedBase32Key, "UTF-8").replace("+", "%20"), URLEncoder.encode(appName, "UTF-8").replace("+", "%20")); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } } OtpServiceImpl(AppSettings appSettings); @Override boolean tryVerificationCode(String verificationCode, String secretKey); @Override String getAuthenticatorURI(String secretKey); }
OtpServiceImpl implements OtpService { @Override public String getAuthenticatorURI(String secretKey) { String userName = SecurityUtils.getCurrentUsername(); String appName = appSettings.getTitle(); if (userName == null) { String errorMessage = "User is not available"; LOG.error(errorMessage); throw new IllegalStateException(errorMessage); } String normalizedBase32Key = secretKey.replace(" ", "").toUpperCase(); try { return String.format( "otpauth: URLEncoder.encode(appName + ":" + userName, "UTF-8").replace("+", "%20"), URLEncoder.encode(normalizedBase32Key, "UTF-8").replace("+", "%20"), URLEncoder.encode(appName, "UTF-8").replace("+", "%20")); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } } OtpServiceImpl(AppSettings appSettings); @Override boolean tryVerificationCode(String verificationCode, String secretKey); @Override String getAuthenticatorURI(String secretKey);  }