package com.admanager;

import com.unboundid.ldap.sdk.BindResult;
import com.unboundid.ldap.sdk.GSSAPIBindRequest;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;

public class SASLGSSAPIBind {
    public static void main(String[] args) throws Exception {
        String server = "admserver.tlct.com.cn";
        int port = 389;
        String username = "adadministrator@tlct.com.cn"; // 或 "TLCT\\adadministrator"
        String password = "your_password";

        // 1. 配置Kerberos
        System.setProperty("java.security.krb5.conf", "/path/to/krb5.conf");
        System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
//
//        // 2. 创建GSSAPI绑定请求
//        GSSAPIBindRequest bindRequest = new GSSAPIBindRequest(username, password, "ldap/" + server, null, null, true, true);
//
//        // 3. 尝试绑定
//        try (LDAPConnection connection = new LDAPConnection(server, port)) {
//            BindResult bindResult = connection.bind(bindRequest);
//            System.out.println("SASL GSSAPI绑定成功");
//
//            // 执行操作...
//        } catch (LDAPException e) {
//            System.err.println("SASL绑定失败: " + e.getMessage());
//            System.err.println("返回码: " + e.getResultCode());
//        }
    }
}
