📄 basicauthentication.java
字号:
package com.maverick.http;
import com.maverick.crypto.encoders.Base64;
import java.io.*;
import java.util.Hashtable;
public class BasicAuthentication
extends HttpAuthenticator {
String realm;
public BasicAuthentication(String uri) {
super("Basic", uri);
}
public String getRealm() {
return realm;
}
public boolean isStateless() {
return true;
}
/**
* authenticate
*
* @param credentials ProxyCredentials
* @todo Implement this com.maverick.proxy.ProxyAuthenticator method
*/
public void authenticate(HttpRequest request, HttpMethod method){
String str = credentials.getUsername() + ":" + credentials.getPassword();
request.setHeaderField(authorizationHeader, "Basic " + new String(Base64.encode(str.getBytes())));
}
public int processResponse(HttpResponse response) {
return (hasCompleted = response.getStatus()>= 200 && response.getStatus() < 400) ? AUTHENTICATION_COMPLETED : AUTHENTICATION_FAILED;
}
public void setChallenge(String challenge) {
try {
Hashtable params = ParameterParser.extractParams(challenge);
this.realm = (String)params.get("realm");
} catch(IOException ex) {
this.realm = "";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -