private Zendesk(AsyncHttpClient client, String url, String username, String password) { this.logger = LoggerFactory.getLogger(Zendesk.class); this.closeClient = client == null; this.oauthToken = null; this.client = client == null ? new DefaultAsyncHttpClient() : client; this.url = url.endsWith("/") ? url + "api/v2" : url + "/api/v2"; if (username != null) { this.realm = new Realm.Builder(username, password) .setScheme(Realm.AuthScheme.BASIC) .setUsePreemptiveAuth(true) .build(); } else { if (password != null) { throw new IllegalStateException("Cannot specify token or password without specifying username"); } this.realm = null; } this.mapper = createMapper(); }
private void addAuth(BoundRequestBuilder requestBuilder) { if (credentials != null && credentials.getLogin() != null) { String password = Optional.ofNullable(credentials.getPassword()).orElse(""); Realm realm = new Realm.Builder(credentials.getLogin(), password).setUsePreemptiveAuth(true) .setScheme(Realm.AuthScheme.BASIC).build(); requestBuilder.setRealm(realm); } }
private synchronized AsyncHttpClient getAsyncHttpClient(Message message) { if (ahcclient == null) { DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder(); AuthorizationPolicy ap = getEffectiveAuthPolicy(message); if (ap != null && (!StringUtils.isEmpty(ap.getAuthorizationType()) || !StringUtils.isEmpty(ap.getUserName()))) { Realm.Builder rb = new Realm.Builder(ap.getUserName(), ap.getPassword()); if (ap.getAuthorizationType() == null) { rb.setScheme(AuthScheme.BASIC); } else { rb.setScheme(AuthScheme.valueOf(ap.getAuthorizationType().toUpperCase())); } rb.setUsePreemptiveAuth(true); builder.setRealm(rb.build()); } AsyncHttpClientConfig config = builder.build(); ahcclient = new DefaultAsyncHttpClient(config); } return ahcclient; }
private synchronized AsyncHttpClient getAsyncHttpClient(Message message) { if (ahcclient == null) { DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder(); AuthorizationPolicy ap = getEffectiveAuthPolicy(message); if (ap != null && (!StringUtils.isEmpty(ap.getAuthorizationType()) || !StringUtils.isEmpty(ap.getUserName()))) { Realm.Builder rb = new Realm.Builder(ap.getUserName(), ap.getPassword()); if (ap.getAuthorizationType() == null) { rb.setScheme(AuthScheme.BASIC); } else { rb.setScheme(AuthScheme.valueOf(ap.getAuthorizationType().toUpperCase())); } rb.setUsePreemptiveAuth(true); builder.setRealm(rb.build()); } AsyncHttpClientConfig config = builder.build(); ahcclient = new DefaultAsyncHttpClient(config); } return ahcclient; }
Realm auth(String username, String password, WSAuthScheme scheme) { Realm.AuthScheme authScheme = Realm.AuthScheme.valueOf(scheme.name()); return (new Realm.Builder(username, password)) .setScheme(authScheme) .setUsePreemptiveAuth(true) .build(); } }
public static Realm.Builder realm(Realm prototype) { return new Realm.Builder(prototype.getPrincipal(), prototype.getPassword()) .setRealmName(prototype.getRealmName()) .setAlgorithm(prototype.getAlgorithm()) .setNc(prototype.getNc()) .setNonce(prototype.getNonce()) .setCharset(prototype.getCharset()) .setOpaque(prototype.getOpaque()) .setQop(prototype.getQop()) .setScheme(prototype.getScheme()) .setUri(prototype.getUri()) .setUsePreemptiveAuth(prototype.isUsePreemptiveAuth()) .setNtlmDomain(prototype.getNtlmDomain()) .setNtlmHost(prototype.getNtlmHost()) .setUseAbsoluteURI(prototype.isUseAbsoluteURI()) .setOmitQuery(prototype.isOmitQuery()) .setServicePrincipalName(prototype.getServicePrincipalName()) .setUseCanonicalHostname(prototype.isUseCanonicalHostname()) .setCustomLoginConfig(prototype.getCustomLoginConfig()) .setLoginContextName(prototype.getLoginContextName()); }
public static Realm.Builder realm(AuthScheme scheme, String principal, String password) { return new Realm.Builder(principal, password) .setScheme(scheme); }