0

私のアプリでは、外部の署名者がドキュメントに署名できるようになっています。—従業員ではない署名者。私のアプリは、彼らのために CoSign デジタル証明書を作成します。次に、ドキュメントに署名すると、ユーザーはシステムから削除されます。アプリでユーザーをプログラムで作成/削除したい。

SAPI User Management API の C# の例はありますか?

4

1 に答える 1

0

ユーザー情報を取得する方法の C# の例を次に示します。

namespace UMSample
{
    class Program
    {
        private const string ADMIN_USER = "AdminUser";
        private const string ADMIN_PASS = "AdminPass";

        static public int AddUser(string uid)
        {
            SAPIUM sapium = new SAPIUMClass();
            SAPICrypt sapicrypt = new SAPICrypt();
            int rc;

            if ((rc = sapicrypt.Init()) != 0) return 1;
            if ((rc = sapium.Init()) != 0) return 1;

            UMSESHandle hSes = null;
            // Handle Acquire
            if ((rc = sapium.HandleAcquire(out hSes)) != 0) return 1;

            // Logon as Administrator
            if ((rc = sapium.Logon(hSes, ADMIN_USER, "", ADMIN_PASS)) != 0)
            {
                sapium.HandleRelease(hSes);
                return 1;
            }

            string UserCN = uid + " Test User";
            string UserEmail = uid+"@demo.com";
            string Pwd = "12345678";

            if ((rc = sapium.UserAdd(
                hSes,
                uid,
                UserCN,
                UserEmail,
                Pwd,
                1)) != 0)
            {
                sapium.Logoff(hSes);
                sapium.HandleRelease(hSes);
                return 1;
            }

            /*----------------------------------*/
            // An example of how to get user info
            UserHandle uh;
            string s1, s2, s3, s4;
            int c1, c2, c3, mask = 0, updtime = 0;
            SAPI_UM_ENUM_USER_CERT_STATUS_TYPE certsts;
            SAPI_UM_ENUM_USER_LOGIN_STATUS loginstat;
            SAPI_UM_ENUM_USER_TYPE kind = SAPI_UM_ENUM_USER_TYPE.SAPI_UM_USER_TYPE_NONE;
            SAPI_UM_ENUM_USER_ENROLLMENT_STATUS enroll = SAPI_UM_ENUM_USER_ENROLLMENT_STATUS.SAPI_UM_NONE_USER_ENROLLMENT_STATUS;
            SAPI_UM_ENUM_USER_ENROLLMENT_REASON enrReason;
            SAPI_UM_ENUM_PENDING_REQUEST_STATUS_TYPE certrqsts;

            rc = sapium.UserGetByLoginName(hSes, uid, out uh);
            rc = sapium.UserInfoGetEx(hSes, uh, out s1, out s2, out s3, ref kind, ref mask, ref updtime, out s4,
                out enroll, out enrReason, out loginstat, out c1, out c2, out c3, out certsts, out certrqsts);
            /*----------------------------------*/

            sapium.Logoff(hSes);
            sapium.HandleRelease(hSes);

            return 0;
        }


        static public int DelUser(string uid)
        {
            SAPIUM sapium = new SAPIUMClass();
            int rc;

            if ((rc = sapium.Init()) != 0) return 1;

            UMSESHandle hSes = null;
            if ((rc = sapium.HandleAcquire(out hSes)) != 0) return 1;

            if ((rc = sapium.Logon(hSes, ADMIN_USER, "", ADMIN_PASS)) != 0)
            {
                sapium.HandleRelease(hSes);
                return 1;
            }

            if ((rc = sapium.UserDelete(hSes, uid)) != 0)
            {
                sapium.Logoff(hSes);
                sapium.HandleRelease(hSes);
                return 1;
            }

            sapium.Logoff(hSes);
            sapium.HandleRelease(hSes);

            return 0;
        }

        static void Main(string[] args)
        {
            int rc;

            for (int i = 0; i < 10; i++)
            {
                string uid = "Test" + i;
                rc = AddUser(uid);
                if (rc != 0) {
                    Console.WriteLine ("Error adding user: " + uid);
                    return;
                }

                rc = DelUser(uid);                
                if (rc != 0) {
                    Console.WriteLine ("Error deleting user: " + uid);
                    return;
                }
                Console.WriteLine("After handling user: " + uid);
            }

            Console.WriteLine("Press <Enter> to end");
            Console.ReadKey();
        }
    }
}
于 2013-09-16T07:04:49.940 に答える