@Test public void testToCredentials() throws Exception { final HttpCredential credential = new HttpCredential(); credential.setUsername(USERNAME); credential.setPassword(PASSWORD); final DnsHostMatcher matcher = new DnsHostMatcher(); matcher.setHost(HttpProxyTest.LOCALHOST); credential.setMatchers(Collections.singletonList(matcher)); AuthScope authscope = AuthScope.ANY; final Credentials object = credential.toCredentials(authscope); assertNotNull(object); assertEquals(USERNAME, object.getUserPrincipal().getName()); assertEquals(PASSWORD, object.getPassword()); authscope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME); assertNotNull(credential.toCredentials(authscope)); authscope = new AuthScope(AuthScope.ANY_HOST, HttpProxyTest.HTTPS_PROXY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME); assertNotNull(credential.toCredentials(authscope)); authscope = new AuthScope(AuthScope.ANY_HOST, 80, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME); assertNotNull(credential.toCredentials(authscope)); authscope = new AuthScope("google.com", AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME); assertNull(credential.toCredentials(authscope)); authscope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "http"); assertNotNull(credential.toCredentials(authscope)); }
@Nullable public final Credentials toCredentials(final AuthScope authscope) { try { if (!matches(MatchInfo.fromAuthScope(authscope))) { return null; } } catch (UnknownHostException | MalformedURLException | SocketException e) { throw new RuntimeException(e); } if (this.username == null) { return null; } final String passwordString; if (this.password != null) { passwordString = new String(this.password); } else { passwordString = null; } return new UsernamePasswordCredentials(this.username, passwordString); }
HttpCredential implements ConfigurationObject { @Nullable public final Credentials toCredentials(final AuthScope authscope) { try { if (!matches(MatchInfo.fromAuthScope(authscope))) { return null; } } catch (UnknownHostException | MalformedURLException | SocketException e) { throw new RuntimeException(e); } if (this.username == null) { return null; } final String passwordString; if (this.password != null) { passwordString = new String(this.password); } else { passwordString = null; } return new UsernamePasswordCredentials(this.username, passwordString); } }
HttpCredential implements ConfigurationObject { @Nullable public final Credentials toCredentials(final AuthScope authscope) { try { if (!matches(MatchInfo.fromAuthScope(authscope))) { return null; } } catch (UnknownHostException | MalformedURLException | SocketException e) { throw new RuntimeException(e); } if (this.username == null) { return null; } final String passwordString; if (this.password != null) { passwordString = new String(this.password); } else { passwordString = null; } return new UsernamePasswordCredentials(this.username, passwordString); }  }
HttpCredential implements ConfigurationObject { @Nullable public final Credentials toCredentials(final AuthScope authscope) { try { if (!matches(MatchInfo.fromAuthScope(authscope))) { return null; } } catch (UnknownHostException | MalformedURLException | SocketException e) { throw new RuntimeException(e); } if (this.username == null) { return null; } final String passwordString; if (this.password != null) { passwordString = new String(this.password); } else { passwordString = null; } return new UsernamePasswordCredentials(this.username, passwordString); }  void setMatchers(final List<? extends URIMatcher> matchers); void setUsername(final String username); void setPassword(final String password); @Override void validate(final List<Throwable> validationErrors, final Configuration configuration); boolean matches(final MatchInfo matchInfo); @Nullable final Credentials toCredentials(final AuthScope authscope); }
HttpCredential implements ConfigurationObject { @Nullable public final Credentials toCredentials(final AuthScope authscope) { try { if (!matches(MatchInfo.fromAuthScope(authscope))) { return null; } } catch (UnknownHostException | MalformedURLException | SocketException e) { throw new RuntimeException(e); } if (this.username == null) { return null; } final String passwordString; if (this.password != null) { passwordString = new String(this.password); } else { passwordString = null; } return new UsernamePasswordCredentials(this.username, passwordString); }  void setMatchers(final List<? extends URIMatcher> matchers); void setUsername(final String username); void setPassword(final String password); @Override void validate(final List<Throwable> validationErrors, final Configuration configuration); boolean matches(final MatchInfo matchInfo); @Nullable final Credentials toCredentials(final AuthScope authscope);  }