有没有办法让java的keytool在SAN中使用通配符生成自签名证书(主题备用名称)?我正在使用此命令生成密钥库:
keytool -genkey -alias tomcat -storetype JKS -keyalg RSA -keysize 2048 -ext san=dns:*.example.com -keystore "path/to/my/keystore.jks" -validity 3650
Run Code Online (Sandbox Code Playgroud)
但我明白了 IOException: DNSName components must begin with a letter
显然,问题出*.example.com
在SAN中,但我没有看到为example.com
子域生成自签名证书的其他方法.
根据这个,应该是可以的.我的语法错误,keytool中的错误,或者我误解了什么?
顺便说一下,我正在使用JDK 1.8 update 60中的keytool
编辑我设法example.com
通过指定生成所有子域的自签名证书CN=*.example.com
,并将SAN留空.尽管如此,我将Omikron的答案视为已被接受(因为它是一个真正的答案,而不是绕过限制).
假设我在Java中有Foo.class:
public class Foo {
public int id;
public String data;
}
Run Code Online (Sandbox Code Playgroud)
而且我在JavaScript中有Foo"class":
function Foo(id, data) {
this.id = id;
this.data = data;
}
Run Code Online (Sandbox Code Playgroud)
另外,假设我有Java控制器,它返回Foo.class的实例作为对REST请求的响应.在我的JavaScript(AngularJS)代码中,请求发送为:
$http.get(url + 'bar/get-foo/')
.success(function (response) {
var foo = new Foo(response.id, response.data);
logger.info("SUCCESS: /get-foo");
})
.error(function (error_message) {
logger.error(error_message)
});
Run Code Online (Sandbox Code Playgroud)
它有效.但有没有办法避免将每个属性从响应传递到Foo构造函数(某种期望Foo对象,或将其转换为Foo对象)?
我试过用Object.create(Foo, response)
但是得到了TypeError: Property description must be an object: true
当然,总是有可能将JavaScript端Foo构造函数重构为:
function Foo(foo) {
this.id = foo.id;
this.data = foo.data;
}
Run Code Online (Sandbox Code Playgroud)
但是,这需要重构大部分代码库.
谢谢你的时间.我很感激!
PS:对于那些想知道为什么我需要这个的人:对于像Foo这样的小类来说这不是问题,但是一些响应是更大类(具有十几个字段)的实例,这些不在我的控制之下.
编辑:我接受Chichozell的答案只是因为它需要的工作量最少.Robin和jonnyknowsbest的答案也有效,(并且适用于纯JavaScript,不像Chichozell的答案,这是AngularJS特有的).没有试过Laurentiu L.的答案,但看起来它也应该有效.无论如何这是一个解决方案(不是解决方案):
.success(function (response) {
var foo …
Run Code Online (Sandbox Code Playgroud) 我知道这种异常有很多问题,而且我确实找到了解决方案,但我的问题是不同项目中的相同代码不会抛出异常,而这个却抛出异常。这两个项目都具有相同版本的 Java 和其他库。
基本上我有一个小函数,它从目录中检索文件列表,按时间戳对它们进行排序,然后返回绝对文件名列表:
public static List<String> getFiles(String dir) {
List<String> fileList = new ArrayList<String>();
File[] files = new File(dir).listFiles();
// Sort files by the date of their creation (last modification)
Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
for (File f : files) {
fileList.add(f.getAbsolutePath());
}
return fileList;
}
Run Code Online (Sandbox Code Playgroud)
基本上,在其中一个项目中,此代码按预期执行,而在其他项目中,它会抛出IllegalArgumentException: Comparison method violates its general contract!
我知道TimSort
从 1.7 开始这是 Java 中的默认排序,解决方案之一是使用强制使用旧版的属性MergeSort
。我没有走那条路...相反,我“缓存”文件及其时间戳,如下所示:
public static List<String> getFiles(String dir) {
List<String> fileList = new ArrayList<String>();
File[] files = new File(dir).listFiles();
FileLastModifiedPair[] …
Run Code Online (Sandbox Code Playgroud) 假设我有两个列表:fooList
和barList
.另外,假设我有两个线程:第一个迭代fooList,如果满足某些条件(条件为真),它会从fooList中删除元素并将其添加到barList.第二个迭代barList,如果某个其他条件为true,则从barList中删除元素,并将其添加到fooList.
我处理它的方式是:
private static Object sharedLock = new Object();
Thread t1 = new Thread() {
public void run() {
synchronized (sharedLock) {
for (Iterator<String> iterator = fooList.iterator(); iterator.hasNext();) {
String fooElement = iterator.next();
if (condition == true) {
iterator.remove();
barList.add(fooElement);
}
}
}
}
};
Thread t2 = new Thread() {
public void run() {
synchronized (sharedLock) {
for (Iterator<String> iterator = barList.iterator(); iterator.hasNext();) {
String barElement = iterator.next();
if (otherCondition == true) {
iterator.remove();
fooList.add(barElement); …
Run Code Online (Sandbox Code Playgroud) java ×4
angularjs ×1
casting ×1
certificate ×1
comparator ×1
file ×1
iterator ×1
javascript ×1
keytool ×1
list ×1
self-signed ×1
sorting ×1