public char[] getPassword() { return RequestId.makeDefensiveCopy(password); }
private static boolean notifyProvider(final RawLoan loan, final ConfirmationProvider zonkoid, final String username, final char... secret) { final RequestId id = new RequestId(username, secret); return zonkoid.requestConfirmation(id, loan.getId(), 200); }
private static HttpEntity getFormData(final RequestId requestId, final int loanId, final int amount) throws UnsupportedEncodingException { final List<NameValuePair> nvps = Arrays.asList( new BasicNameValuePair("clientApp", CLIENT_APP), new BasicNameValuePair("username", requestId.getUserId()), new BasicNameValuePair("loanId", String.valueOf(loanId)), new BasicNameValuePair("preferredAmount", String.valueOf(amount)) ); return new UrlEncodedFormEntity(nvps); }
@Test void nullUsername() { assertThatThrownBy(() -> new RequestId(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test void emptyPassword() { final String username = "user"; final RequestId r = new RequestId(username); final SoftAssertions softly = new SoftAssertions(); softly.assertThat(r.getUserId()).isSameAs(username); softly.assertThat(r.getPassword()).isEmpty(); softly.assertAll(); }
@Test void passwordDefensivelyCopied() { final char[] password = "pass".toCharArray(); final RequestId r = new RequestId("user", password); final SoftAssertions softly = new SoftAssertions(); softly.assertThat(r.getPassword()) .containsExactly(password) .isNotSameAs(password); softly.assertAll(); }
static String getAuthenticationString(final RequestId requestId, final int loanId) { final String auth = new StringJoiner("|") .add(String.valueOf(requestId.getPassword())) .add(CLIENT_APP) .add(requestId.getUserId()) .add(String.valueOf(loanId)) .toString(); try { return md5(auth); } catch (final NoSuchAlgorithmException ex) { throw new IllegalStateException("Your Java Runtime Environment does not support MD5!", ex); } }
static Optional<ConfirmationProvider> load(final String providerId, final Iterable<ConfirmationProviderService> loader) { ConfirmationProviderLoader.LOGGER.debug("Looking up confirmation provider '{}'.", providerId); return StreamUtil.toStream(loader) .peek(cp -> ConfirmationProviderLoader.LOGGER.trace("Evaluating confirmation provider '{}' with '{}'.", providerId, cp.getClass())) .map(cp -> cp.find(providerId)) .flatMap(o -> o.map(Stream::of).orElse(Stream.empty())) .findFirst(); }
private static boolean notifyProvider(final RawLoan loan, final ConfirmationProvider zonkoid, final String username, final char... secret) { final RequestId id = new RequestId(username, secret); return zonkoid.requestConfirmation(id, loan.getId(), 200); }
static String getAuthenticationString(final RequestId requestId, final int loanId) { final String auth = new StringJoiner("|") .add(String.valueOf(requestId.getPassword())) .add(CLIENT_APP) .add(requestId.getUserId()) .add(String.valueOf(loanId)) .toString(); try { return md5(auth); } catch (final NoSuchAlgorithmException ex) { throw new IllegalStateException("Your Java Runtime Environment does not support MD5!", ex); } }
private static HttpEntity getFormData(final RequestId requestId, final int loanId, final int amount) throws UnsupportedEncodingException { final List<NameValuePair> nvps = Arrays.asList( new BasicNameValuePair("clientApp", CLIENT_APP), new BasicNameValuePair("username", requestId.getUserId()), new BasicNameValuePair("loanId", String.valueOf(loanId)), new BasicNameValuePair("preferredAmount", String.valueOf(amount)) ); return new UrlEncodedFormEntity(nvps); }
public char[] getPassword() { return RequestId.makeDefensiveCopy(password); }
public RequestId(final String userId, final char... password) { if (userId == null) { throw new IllegalArgumentException("Username must not be null."); } this.userId = userId; this.password = RequestId.makeDefensiveCopy(password); }
public RequestId(final String userId, final char... password) { if (userId == null) { throw new IllegalArgumentException("Username must not be null."); } this.userId = userId; this.password = RequestId.makeDefensiveCopy(password); }
public static Investor build(final Tenant auth, final ConfirmationProvider provider, final char... password) { final InvestOperation o = auth.getSessionInfo().isDryRun() ? DRY_RUN : recommendedLoan -> invest(auth, recommendedLoan); if (provider == null) { return new Investor(o); } else { final RequestId r = new RequestId(auth.getSessionInfo().getUsername(), password); return new Investor(r, provider, o); } }
public static Investor build(final Tenant auth, final ConfirmationProvider provider, final char... password) { final InvestOperation o = auth.getSessionInfo().isDryRun() ? DRY_RUN : recommendedLoan -> invest(auth, recommendedLoan); if (provider == null) { return new Investor(o); } else { final RequestId r = new RequestId(auth.getSessionInfo().getUsername(), password); return new Investor(r, provider, o); } }
private boolean execute(final int code) { this.mockServerResponse(code); final RequestId id = new RequestId("user@somewhere.cz", "apitest".toCharArray()); final ZonkoidConfirmationProvider zcp = new ZonkoidConfirmationProvider(serverUrl); final boolean result = zcp.requestConfirmation(id , 1, 200); this.verifyClientRequest(); return result; }