Rest-Android安全技术选择
Iam与android客户端一起构建Webservice(使用J2EE)。现在我面临着选择哪种安全技术?并将其与我的Rest服务集成。 我抓取了google,并建议使用Oauth2.0,使用TLS和api密钥进行基本身份验证。 在我使用HttpClient的android应用程序中,我不知道集成这些解决方案是否需要对我的代码进行重大更改。在这个场合,任何人都可以给我一个关于前两个的很好的描述,并建议最好的教程和例子Rest-Android安全技术选择,android,security,rest,jakarta-ee,oauth,Android,Security,Rest,Jakarta Ee,Oauth,Iam与android客户端一起构建Webservice(使用J2EE)。现在我面临着选择哪种安全技术?并将其与我的Rest服务集成。 我抓取了google,并建议使用Oauth2.0,使用TLS和api密钥进行基本身份验证。 在我使用HttpClient的android应用程序中,我不知道集成这些解决方案是否需要对我的代码进行重大更改。在这个场合,任何人都可以给我一个关于前两个的很好的描述,并建议最好的教程和例子 public class DataLoader { DefaultHttpCli
public class DataLoader {
DefaultHttpClient sslClient;
private boolean silent;
public class CustomX509TrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
@Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType)
throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
public class CustomSSLSocketFactory extends SSLSocketFactory {
SSLContext sslContext = SSLContext.getInstance("TLS");
public CustomSSLSocketFactory(KeyStore truststore)
throws NoSuchAlgorithmException, KeyManagementException,
KeyStoreException, UnrecoverableKeyException {
super(truststore);
TrustManager tm = new CustomX509TrustManager();
sslContext.init(null, new TrustManager[] { tm }, null);
}
public CustomSSLSocketFactory(SSLContext context)
throws KeyManagementException, NoSuchAlgorithmException,
KeyStoreException, UnrecoverableKeyException {
super(null);
sslContext = context;
}
@Override
public Socket createSocket(Socket socket, String host, int port,
boolean autoClose) throws IOException, UnknownHostException {
return sslContext.getSocketFactory().createSocket(socket, host,
port, autoClose);
}
@Override
public Socket createSocket() throws IOException {
return sslContext.getSocketFactory().createSocket();
}
}
public HttpResponse execute(HttpUriRequest request) {
if (!(silent)) {
Log.i("Performing request", "Performing request");
for (Header header : request.getAllHeaders())
Log.i("Performing request",
"Performing request "
+ new StringBuilder()
.append("Request header: ")
.append(header.getName()).append(" - ")
.append(header.getValue()).toString());
}
HttpResponse response = null;
try {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[] { new CustomX509TrustManager() },
new SecureRandom());
HttpClient client = new DefaultHttpClient();
SSLSocketFactory ssf = new CustomSSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = client.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 443));
sslClient = new DefaultHttpClient(ccm, client.getParams());
response = sslClient.execute(request);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
}
有人能给我一个关于前两个的很好的描述,并建议最好的教程和例子吗?
谷歌在这方面非常有用,对于3个最好的例子来说,哪一个是最好的?嘿,我的朋友,请使用这门课。它将帮助您克服所有安全问题,感谢您上面的代码暗示iam在Rest服务器上使用TLS/SSL证书。正确的?如何在glassfish 4.0上启用ssl over Rest?如何获得证书以用于您的类?您已经开发了一个servlet。对吗?它只是一个网页。如果您想要启用SSL的网页,则必须在安装该证书后购买SSL证书。如果您没有该证书,请使用上述代码。上述代码适用于所有安全问题。如果您满意,请进行投票。谢谢。我没有使用servlet Iam通过http使用jersey框架构建Rest服务,但我不知道如何将https与之集成,或者使用oauth功能来实现安全性。我不再需要aouth,因为它使用第三方服务器进行身份验证。因此,如何在Rest服务端启用ssl/TLS您必须从verisign和thawte等公司购买ssl/TSL证书。谢谢