io.femo.http.Authentication Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http-jdk7 Show documentation
Show all versions of http-jdk7 Show documentation
An easy to use HTTP API, that supports synchronous and asynchronous execution of HTTP request.
On android only asynchronous driver is supported.
This library has been backported to jdk 7 to retain compatibility with android!
The newest version!
package io.femo.http;
import io.femo.http.auth.DefaultBasicStrategy;
import io.femo.http.auth.DefaultDigestStrategy;
import io.femo.support.jdk7.Supplier;
import org.jetbrains.annotations.Contract;
/**
* Created by felix on 6/21/16.
*/
public abstract class Authentication implements Driver {
public abstract boolean isInitialized();
public abstract boolean matches(HttpRequest request);
public abstract boolean supportsMulti();
public abstract boolean supportsDirect();
public abstract void init(HttpResponse response);
public abstract String strategy();
public abstract void authenticate(HttpRequest request);
public boolean supports(HttpResponse response) {
String authenticate = response.header("WWW-Authenticate").value();
return authenticate.startsWith(strategy());
}
@Contract("_, _ -> !null")
public static Authentication basic(Supplier username, Supplier password) {
return new DefaultBasicStrategy(username, password);
}
@Contract("_, _ -> !null")
static Authentication basic(String username, String password) {
return new DefaultBasicStrategy(username, password);
}
@Contract("_, _ -> !null")
static Authentication digest(String username, String password) {
return new DefaultDigestStrategy(username, password);
}
@Contract("_, _ -> !null")
static Authentication digest(Supplier username, Supplier password) {
return new DefaultDigestStrategy(username, password);
}
}