JNI使用LogonUser调用身份验证用户?

时间:2009-06-15 16:20:33

标签: c++ windows authentication java-native-interface

C ++ noob在这里想知道如何通过Java servlet验证Windows用户。

这是我用我们的用户名域名和密码从我的java servlet接收JNI调用的代码:

#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h> 

#include "Validate.h"    

JNIEXPORT jstring JNICALL Java_Validate_takeInfo(JNIEnv *env, jobject obj, jstring domain, jstring id, jstring idca, jstring password) 
{
    const char *nt_domain;
    const char *nt_id;
    const char *nt_idca;
    const char *nt_password;

    nt_domain = env->GetStringUTFChars(domain, NULL);
    nt_id = env->GetStringUTFChars(id, NULL);
    nt_idca= env->GetStringUTFChars(idca, NULL);
    nt_password = env->GetStringUTFChars(password, NULL);

    handle hToken = 0;
    char *otherString;
    otherString = LogonUser(nt_id, nt_domain, nt_password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &hToken );

    jstring newString = env->NewStringUTF((const char*)otherString);
    return newString;
}

我在尝试编译时遇到这些错误:

D:\JNI\Validate.cpp(21) : error C2065: 'handle' : undeclared identifier
D:\JNI\Validate.cpp(21) : error C2146: syntax error : missing ';' before
ier 'hToken'
D:\JNI\Validate.cpp(21) : error C2065: 'hToken' : undeclared identifier
D:\JNI\Validate.cpp(24) : error C2065: 'LOGON32_LOGON_NETWORK' : undeclar
tifier
D:\JNI\Validate.cpp(24) : error C2065: 'LOGON32_PROVIDER_DEFAULT' : undec
dentifier
D:\JNI\Validate.cpp(24) : error C3861: 'LogonUser': identifier not found

我假设我不包括我需要的东西。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您的编译器找不到LogonUser表示您缺少Windows标头。包括windows.h

此外,通用窗口句柄类型拼写为HANDLE,全部为大写。

有关详细信息,请参阅the LogonUser docs

相关问题