我无法运行以下程序:

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;
};


所需的分号不应该在那里!

08-27 14:15