我一直在我的程序中使用自定义密钥库,方法是指定javax.net.ssl.keyStore,javax.net.ssl.keyStorePassword,javax.net.ssl.trustStore,javax.net.ssl.trustStorePassword.我的信任库包含自签名证书.现在我想发一些https请求(比如说https://google.com)并使用默认的jre系统trusstore,其中包含有关不同CA的信息.要发出http请求,我使用OkHttp库.它的客户端有一个指定SslSocketFactory的选项,但为了得到它,我需要为默认的jre truststore 初始化SSLContext.我怎样才能做到这一点?
更新:我使用的代码是
KeyStore keyStore = KeyStore.getInstance("JKS");
// load default jvm keystore
keyStore.load(new FileInputStream(
System.getProperties()
.getProperty("java.home") + File.separator
+ "lib" + File.separator + "security" + File.separator
+ "cacerts"), "changeit".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, tmf.getTrustManagers(), new SecureRandom());
Run Code Online (Sandbox Code Playgroud) 我正在编写正在返回json并使用Spring MVC的restful Web服务.我正在使用Spring 3.x. 现在我想添加一个登录方法,它将检索用户名和密码并返回访问令牌,以便客户端可以进一步使用该令牌来调用其他方法.我认为这个标记应该有一个有限的生命周期.有这样做的好样本吗?我根本需要弹簧安全吗?再次,一个很好的样本将非常感激.
我想使用Jackson 2.x反序列化一段JSON.
json看起来像这样:
{
"response":[
230,
{
"id":1627,
"from_id":4534,
"attachments":[
{
"type":"audio",
"audio":{
"aid":25918,
"owner_id":20000,
}
},
{
"type":"link",
"link":{
"url":"http://lenta.ru",
"title":"bla"
}
}
]
}
...
]
}
Run Code Online (Sandbox Code Playgroud)
所以我想使用Polymorphic Type Handling将附件反序列化为附件列表.我跟随Mixins关注POJO:
public class Post {
private final String id;
private List<? extends Attachment> attachments;
// ...
}
@JsonIgnoreProperties(ignoreUnknown = true)
public class PostMixin {
@JsonProperty("id")
String id;
@JsonProperty("attachments")
List<? extends Attachment> attachments;
// ...
}
public abstract class Attachment {
public static enum AttachmentType {
AUDIO, LINK
}
private …Run Code Online (Sandbox Code Playgroud) 我发现了几篇关于如何使用jdb http://www.rhcedan.com/2010/06/22/killing-a-java-thread/或在SO上杀死Java线程的说明。这可行。现在,我想使用Intellij-IDEA调试器杀死线程。有可能吗?