jrm*_*nts 11 android kerberos xml-rpc
我正在尝试创建一个使用现有Web服务的Android应用程序.但是,现有的Web服务使用Kerberos进行身份验证,我无法使用android-xmlrpc库来获取Android以对服务进行身份验证.如果有人对此有任何经验,请回复.
我对这种东西完全是新手,所以任何建议都将不胜感激!
谢谢,戴夫
这里的信息帮助我让我的 Android 应用程序与 kerberos 一起工作。这是我正在从事的项目的链接。它进行 kerberos 身份验证。这是相关代码:
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials(username, password);
DefaultHttpClient client = getHttpClient();
client.getCredentialsProvider().setCredentials(SERVER_AUTH_SCOPE, creds);
boolean authWorked = false;
try{
HttpGet get = new HttpGet(AUTH_URI);
HttpResponse resp = client.execute(get);
authWorked = hasValidCookie();
}
/*catch(AuthenticationException e){
Log.e("TAG", "Auth exceptions");
//TODO maybe do something?
}*/
catch(IOException e){
Log.e("TAG", "IOException exceptions");
//TODO maybe do something?
}
Run Code Online (Sandbox Code Playgroud)
方法如下getHttpClient():
public static DefaultHttpClient getHttpClient(){
if(httpClient == null){
httpClient = new DefaultHttpClient();
final HttpParams params = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, REGISTRATION_TIMEOUT);
ConnManagerParams.setTimeout(params, REGISTRATION_TIMEOUT);
}
return httpClient;
}
Run Code Online (Sandbox Code Playgroud)
这是hasValidCookie()
private static final String LOGIN_COOKIE_NAME = "CGISESSID";
private static boolean hasValidCookie(){
for(Cookie cookie: getHttpClient().getCookieStore().getCookies()){
if(cookie.getName().equals(LOGIN_COOKIE_NAME))
{
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)