gpt4 book ai didi

java - Spnego keytab 测试给出了 java 安全异常

转载 作者:行者123 更新时间:2023-12-03 05:52:19 26 4
gpt4 key购买 nike

我无法运行以下程序:

import java.net.URL;

import net.sourceforge.spnego.SpnegoHttpURLConnection;

public class HelloKeytab {

public static void main(final String[] args) throws Exception {
System.setProperty("java.security.krb5.conf", "krb5.conf");
System.setProperty("sun.security.krb5.debug", "true");
System.setProperty("java.security.auth.login.config", "login.conf");

SpnegoHttpURLConnection spnego = null;

try {
spnego = new SpnegoHttpURLConnection("spnego-client");
spnego.connect(new URL("http://as1.test.local/hello_spnego.jsp"));

System.out.println("HTTP Status Code: "
+ spnego.getResponseCode());

System.out.println("HTTP Status Message: "
+ spnego.getResponseMessage());

} finally {
if (null != spnego) {
spnego.disconnect();
}
}
}
}

我安装了 JDK7 并以管理员身份设置了 JAVA_HOME 环境变量。我正在 Windows XP 计算机上作为常规域用户进行编译和运行。

我将 spnego-r7.jarHelloKeytab.java 放在同一目录中,并使用以下命令进行编译:

javac -cp .;spnego-r7.jar HelloKeytab.java 

成功创建了该类。

当我运行程序时:

java -cp .;spengo-r7.jar HelloKeytab

我收到以下错误:

Exception in thread "main" java.lang.SecurityException: Configuration Error:
Line 2: expected [controlFlag]
at com.sun.security.auth.login.ConfigFile.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at javax.security.auth.login.Configuration$3.run(Unknown Source)
at javax.security.auth.login.Configuration$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.Configuration.getConfiguration(Unknown Sour
ce)
at javax.security.auth.login.LoginContext$1.run(Unknown Source)
at javax.security.auth.login.LoginContext$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.LoginContext.init(Unknown Source)
at javax.security.auth.login.LoginContext.<init>(Unknown Source)
at net.sourceforge.spnego.SpnegoHttpURLConnection.<init>(SpnegoHttpURLCo
nnection.java:206)
at HelloKeytab.main(HelloKeytab.java:15)
Caused by: java.io.IOException: Configuration Error:
Line 2: expected [controlFlag]
at com.sun.security.auth.login.ConfigFile.match(Unknown Source)
at com.sun.security.auth.login.ConfigFile.parseLoginEntry(Unknown Source
)
at com.sun.security.auth.login.ConfigFile.readConfig(Unknown Source)
at com.sun.security.auth.login.ConfigFile.init(Unknown Source)
at com.sun.security.auth.login.ConfigFile.init(Unknown Source)
... 17 more

spnego-r7.jar 可以在这里找到:http://sourceforge.net/projects/spnego/files/

我收到此错误是怎么回事?

最佳答案

我的login.conf 中有错误。

spnego-client {
com.sun.security.auth.module.Krb5LoginModule required;
storeKey=true
useKeyTab=true
keyTab="file:///C:/sys-spn.keytab"
principal=sys-spn;
};

required后面的分号不应该出现!

关于java - Spnego keytab 测试给出了 java 安全异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18775660/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com