@Test(expected = NullPointerException.class) public void noUsername() { final Request badRequest = new HttpRequest.Builder(Method.PUT, this.uri, Operation.WRITE) .withContext(Context.X_OG_PASSWORD, this.password).build(); this.basicAuth.authenticate(badRequest); }
@Override public AuthenticatedRequest authenticate(final Request request) { final String username = checkNotNull(request.getContext().get(Context.X_OG_USERNAME)); final String password = checkNotNull(request.getContext().get(Context.X_OG_PASSWORD)); final String credentials = username + ":" + password; final AuthenticatedHttpRequest authenticatedRequest = new AuthenticatedHttpRequest(request); authenticatedRequest.addHeader(HttpHeaders.AUTHORIZATION, "Basic " + BaseEncoding.base64().encode(credentials.getBytes(Charsets.UTF_8))); return authenticatedRequest; }
BasicAuth implements HttpAuth { @Override public AuthenticatedRequest authenticate(final Request request) { final String username = checkNotNull(request.getContext().get(Context.X_OG_USERNAME)); final String password = checkNotNull(request.getContext().get(Context.X_OG_PASSWORD)); final String credentials = username + ":" + password; final AuthenticatedHttpRequest authenticatedRequest = new AuthenticatedHttpRequest(request); authenticatedRequest.addHeader(HttpHeaders.AUTHORIZATION, "Basic " + BaseEncoding.base64().encode(credentials.getBytes(Charsets.UTF_8))); return authenticatedRequest; } }
BasicAuth implements HttpAuth { @Override public AuthenticatedRequest authenticate(final Request request) { final String username = checkNotNull(request.getContext().get(Context.X_OG_USERNAME)); final String password = checkNotNull(request.getContext().get(Context.X_OG_PASSWORD)); final String credentials = username + ":" + password; final AuthenticatedHttpRequest authenticatedRequest = new AuthenticatedHttpRequest(request); authenticatedRequest.addHeader(HttpHeaders.AUTHORIZATION, "Basic " + BaseEncoding.base64().encode(credentials.getBytes(Charsets.UTF_8))); return authenticatedRequest; } BasicAuth(); }
BasicAuth implements HttpAuth { @Override public AuthenticatedRequest authenticate(final Request request) { final String username = checkNotNull(request.getContext().get(Context.X_OG_USERNAME)); final String password = checkNotNull(request.getContext().get(Context.X_OG_PASSWORD)); final String credentials = username + ":" + password; final AuthenticatedHttpRequest authenticatedRequest = new AuthenticatedHttpRequest(request); authenticatedRequest.addHeader(HttpHeaders.AUTHORIZATION, "Basic " + BaseEncoding.base64().encode(credentials.getBytes(Charsets.UTF_8))); return authenticatedRequest; } BasicAuth(); @Override AuthenticatedRequest authenticate(final Request request); @Override String toString(); }
BasicAuth implements HttpAuth { @Override public AuthenticatedRequest authenticate(final Request request) { final String username = checkNotNull(request.getContext().get(Context.X_OG_USERNAME)); final String password = checkNotNull(request.getContext().get(Context.X_OG_PASSWORD)); final String credentials = username + ":" + password; final AuthenticatedHttpRequest authenticatedRequest = new AuthenticatedHttpRequest(request); authenticatedRequest.addHeader(HttpHeaders.AUTHORIZATION, "Basic " + BaseEncoding.base64().encode(credentials.getBytes(Charsets.UTF_8))); return authenticatedRequest; } BasicAuth(); @Override AuthenticatedRequest authenticate(final Request request); @Override String toString();  }