{"id":8414,"date":"2018-06-18T09:00:59","date_gmt":"2018-06-18T00:00:59","guid":{"rendered":"https:\/\/www.agent-grow.com\/self20percent\/?p=8414"},"modified":"2018-06-14T22:05:49","modified_gmt":"2018-06-14T13:05:49","slug":"golang-ldap-auth","status":"publish","type":"post","link":"https:\/\/www.agent-grow.com\/self20percent\/2018\/06\/18\/golang-ldap-auth\/","title":{"rendered":"Go\u8a00\u8a9e\u3067 LDAP (AD) \u8a8d\u8a3c\u3057\u3066\u3084\u308d\u3046\u3084\u306a\u3044\u304b\uff01"},"content":{"rendered":"<h1>Go\u8a00\u8a9e\u3067 LDAP \u8a8d\u8a3c\u3057\u305f\u3044\uff01<\/h1>\n<p>\u7686\u3055\u3093\u3001 Go\u8a00\u8a9e\u66f8\u3044\u3066\u307e\u3059\u304b\uff01<br \/>\nGo\u8a00\u8a9e\u306f\u6700\u8fd1\u306f\u3084\u308a\u306e\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u306b\u3082\u5411\u3044\u3066\u3044\u308b\u611f\u304c\u3042\u308a\u307e\u3059\u3057\u3001<br \/>\n\u4e00\u6642\u306e\u71b1\u306f\u51b7\u3081\u3064\u3064\u3042\u308b\u3082\u306e\u306e\u3001\u306a\u304b\u306a\u304b\u4f7f\u3044\u52dd\u624b\u306f\u826f\u3044\u8a00\u8a9e\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3001 Go\u8a00\u8a9e\u3067 LDAP \u306e\u8a8d\u8a3c\u3092\u3057\u305f\u3044\uff01\u3068\u3044\u3046\u65b9\u5411\u3051\u306b<br \/>\nGo\u8a00\u8a9e\u3067 LDAP \u30b5\u30fc\u30d0\u30fc\u3068\u306e\u901a\u4fe1\u30fb\u8a8d\u8a3c\u3092\u884c\u3046\u65b9\u6cd5\u306b\u3064\u3044\u3066\u307f\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u5b9f\u969b\u306b\u4f7f\u3046 LDAP \u30b5\u30fc\u30d0\u30fc\u306f Microsoft \u306e Active Directory (\u4ee5\u4e0b AD) \u3067\u3059\u3002<\/p>\n<h1>\u30b3\u30fc\u30c9\u3001\u30c9\u30f3\uff01<\/h1>\n<p>\u4eca\u56de\u66f8\u3044\u305f\u30b3\u30fc\u30c9\u304c\u3053\u3061\u3089\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npackage main\n\nimport (\n    &amp;quot;fmt&amp;quot;\n    &amp;quot;os&amp;quot;\n    &amp;quot;log&amp;quot;\n    ldapConnect &amp;quot;gopkg.in\/ldap.v2&amp;quot;\n    &amp;quot;errors&amp;quot;\n)\n\ntype Ldap struct {\n    Host            string\n    BindDN          string\n    BindUser        string\n    BindPassword    string\n}\n\ntype LdapResult struct {\n    LoginName   string\n    Name        string\n    DN          string\n}\n\n\/\/ LDAP \u8a2d\u5b9a\u4f5c\u6210\nfunc CreateLdapConn(ldapHost string, ldapBaseDN string, ldapBindUser string, ldapBindPassword string) *Ldap {\n    return &amp;amp;Ldap{\n        Host: ldapHost,\n        BindDN: ldapBaseDN,\n        BindUser: ldapBindUser,\n        BindPassword: ldapBindPassword,\n    }\n}\n\n\/\/ LDAP \u8a8d\u8a3c\nfunc (ldap *Ldap) Login(username string, password string) (*LdapResult, error) {\n    \/\/ LDAP \u30b5\u30fc\u30d0\u30fc\u63a5\u7d9a\n    l, err := ldapConnect.Dial(&amp;quot;tcp&amp;quot;, fmt.Sprintf(&amp;quot;%s:%d&amp;quot;, ldap.Host, 389))\n    if err != nil {\n        log.Printf(&amp;quot;Cannot connect server.\\n%s&amp;quot;, err.Error())\n        return nil, err\n    }\n    defer l.Close()\n\n    \/\/ LDAP \u30d0\u30a4\u30f3\u30c9\u30e6\u30fc\u30b6\u30fc\u3067\u306e\u63a5\u7d9a\n    err = l.Bind(ldap.BindUser, ldap.BindPassword)\n\n    if err != nil {\n        log.Printf(&amp;quot;Cannot connect with bind user\\n%s&amp;quot;, err.Error())\n        return nil, err\n    }\n\n    \/\/ LDAP \u691c\u7d22\u8a2d\u5b9a\n    SearchRequest := ldapConnect.NewSearchRequest(\n        ldap.BindDN,\n        ldapConnect.ScopeWholeSubtree, ldapConnect.NeverDerefAliases, 0, 0, false,\n        fmt.Sprintf(&amp;quot;(sAMAccountName=%s)&amp;quot;, username),\n        &#x5B;]string{&amp;quot;dn&amp;quot;, &amp;quot;sAMAccountName&amp;quot;, &amp;quot;displayName&amp;quot;},\n        nil,\n    )\n\n    log.Printf(&amp;quot;Start search user: %s&amp;quot;, username)\n\n    \/\/ LDAP \u691c\u7d22\u5b9f\u884c\n    sr, err := l.Search(SearchRequest)\n    if err != nil {\n        log.Printf(&amp;quot;Search failed.\\n%s&amp;quot;, err.Error())\n        return nil, err\n    }\n\n    \/\/ \u691c\u7d22\u7d50\u679c\u6570\u78ba\u8a8d (1 \u4ef6\u306b\u7279\u5b9a\u3067\u304d\u306a\u3044\u5834\u5408\u306f\u5931\u6557)\n    if len(sr.Entries) == 0 {\n        log.Printf(&amp;quot;Not found user: %s&amp;quot;, username)\n        return nil, fmt.Errorf(&amp;quot;not found user: %s&amp;quot;, username)\n    } else if len(sr.Entries) &amp;gt; 1 {\n        log.Printf(&amp;quot;Too many found user: %s&amp;quot;, username)\n        return nil, fmt.Errorf(&amp;quot;too many found user: %s&amp;quot;, username)\n    }\n\n    entity := sr.Entries&#x5B;0]\n\n    \/\/ \u8a8d\u8a3c\u30e6\u30fc\u30b6\u30fc\u30d1\u30b9\u30ef\u30fc\u30c9\u6b63\u8aa4\u78ba\u8a8d\n    err = l.Bind(entity.DN, password)\n    if err != nil {\n        log.Printf(&amp;quot;Authorization failed user: %s&amp;quot;, username)\n        return nil, err\n    }\n\n    log.Printf(&amp;quot;Authorization success user: %s&amp;quot;, username)\n\n  \/\/ sAMAccountName, displayName, DN \u3092\u8fd4\u5374\n    return &amp;amp;LdapResult{\n        LoginName: entity.GetAttributeValue(&amp;quot;sAMAccountName&amp;quot;),\n        Name: entity.GetAttributeValue(&amp;quot;displayName&amp;quot;),\n        DN: entity.GetAttributeValue(&amp;quot;dn&amp;quot;),\n    }, nil\n}\n<\/pre>\n<p>\u30d1\u30c3\u3068\u898b\u3067\u306f\u5206\u91cf\u591a\u3081\u306b\u898b\u3048\u307e\u3059\u304c\u3001\u3084\u3063\u3066\u3044\u308b\u5185\u5bb9\u306f\u7c21\u5358\u3067\u3059\u3002<br \/>\n\u5185\u5bb9\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h1>\u5185\u5bb9\u89e3\u8aac\uff01<\/h1>\n<h2>\u5192\u982d\u90e8\u5206<\/h2>\n<h3>import \u7b49\u3005<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npackage main\n\nimport (\n    &amp;quot;fmt&amp;quot;\n    &amp;quot;os&amp;quot;\n    &amp;quot;log&amp;quot;\n    ldapConnect &amp;quot;gopkg.in\/ldap.v2&amp;quot;\n    &amp;quot;errors&amp;quot;\n)\n\ntype Ldap struct {\n    Host            string\n    BindDN          string\n    BindUser        string\n    BindPassword    string\n}\n\ntype LdapResult struct {\n    LoginName   string\n    Name        string\n    DN          string\n}\n<\/pre>\n<p>\u3053\u3053\u306f\u305d\u306e\u307e\u307e\u3067\u3059\u306d\u3002<br \/>\n\u4eca\u56de\u3001 LDAP \u30b5\u30fc\u30d0\u30fc\u3078\u306e\u63a5\u7d9a\u306b\u306f <a href=\"https:\/\/github.com\/go-ldap\/ldap\">https:\/\/github.com\/go-ldap\/ldap<\/a> \u3092\u4f7f\u7528\u3055\u305b\u3066\u3044\u305f\u3060\u3044\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u3053\u308c\u3092\u307b\u304b\u306e\u5fc5\u8981\u306a\u3082\u306e\u3068\u4e00\u7dd2\u306b import\u3002<\/p>\n<p>\u5f8c\u306f <code>Ldap<\/code> \u304c LDAP \u30b5\u30fc\u30d0\u30fc\u3078\u306e\u63a5\u7d9a\u60c5\u5831\u3092\u4fdd\u6301\u3059\u308b\u70ba\u306e\u69cb\u9020\u4f53\u3002<br \/>\n<code>LdapResult<\/code> \u304c LDAP \u30b5\u30fc\u30d0\u30fc\u3078\u306e\u554f\u5408\u305b\u7d50\u679c\u3092\u8fd4\u3059\u305f\u3081\u306e\u69cb\u9020\u4f53\u3067\u3059\u306d\u3002<\/p>\n<h2>CreateLdapConn func<\/h2>\n<h3>LDAP \u63a5\u7d9a\u60c5\u5831\u683c\u7d0d<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ LDAP \u8a2d\u5b9a\u4f5c\u6210\nfunc CreateLdapConn(ldapHost string, ldapBaseDN string, ldapBindUser string, ldapBindPassword string) *Ldap {\n    return &amp;amp;Ldap{\n        Host: ldapHost,\n        BindDN: ldapBaseDN,\n        BindUser: ldapBindUser,\n        BindPassword: ldapBindPassword,\n    }\n}\n<\/pre>\n<p>\u3053\u3053\u3082\u3001\u63a5\u7d9a\u60c5\u5831\u3092\u683c\u7d0d\u3057\u305f <code>Ldap<\/code> \u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3066\u30dd\u30a4\u30f3\u30bf\u8fd4\u3057\u3066\u308b\u3060\u3051\u3067\u3059\u306d\u3002<br \/>\n\u5b9f\u969b\u306b\u63a5\u7d9a\u3092\u884c\u3046\u969b\u306b\u306f\u3001\u3053\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u60c5\u5831\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>Login func<\/h2>\n<p>\u3053\u3053\u304b\u3089\u3001\u5b9f\u969b\u306b\u8a8d\u8a3c\u3092\u884c\u3046\u95a2\u6570\u306b\u5165\u3063\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u3053\u306e\u95a2\u6570\u306f Ldap \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30dd\u30a4\u30f3\u30bf\u3092\u30ec\u30b7\u30fc\u30d0\u306b\u53d6\u3063\u3066\u3044\u307e\u3059\u306e\u3067\u3001<br \/>\n\u63a5\u7d9a\u60c5\u5831\u306f\u3053\u3053\u304b\u3089\u3068\u3063\u3066\u304f\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u306d\u3002<\/p>\n<p>\u3067\u306f\u4e0a\u304b\u3089\u9806\u306b\u898b\u3066\u3044\u304d\u307e\u3059<\/p>\n<h3>LDAP \u30b5\u30fc\u30d0\u30fc\u63a5\u7d9a<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n    \/\/ LDAP \u30b5\u30fc\u30d0\u30fc\u63a5\u7d9a\n    l, err := ldapConnect.Dial(&amp;quot;tcp&amp;quot;, fmt.Sprintf(&amp;quot;%s:%d&amp;quot;, ldap.Host, 389))\n    if err != nil {\n        log.Printf(&amp;quot;Cannot connect server.\\n%s&amp;quot;, err.Error())\n        return nil, err\n    }\n    defer l.Close()\n<\/pre>\n<p>import \u3057\u305f ldap \u30e9\u30a4\u30d6\u30e9\u30ea\u306e <code>Dial<\/code> \u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u3067 LDAP \u30b5\u30fc\u30d0\u30fc\u3078\u63a5\u7d9a\u3067\u304d\u307e\u3059\u3002<br \/>\n<code>Dial(\u30cd\u30c3\u30c8\u30ef\u30fc\u30af string, \u30a2\u30c9\u30ec\u30b9:\u30dd\u30fc\u30c8\u756a\u53f7 string)<\/code> \u306e\u5f62\u3067\u3059\u306d\u3002<br \/>\n\u6700\u5f8c\u306b\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u3092\u5207\u308b\u306e\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3001 <code>defer l.Close()<\/code> \u3082\u547c\u3093\u3067\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>LDAP \u30d0\u30a4\u30f3\u30c9\u30e6\u30fc\u30b6\u30fc\u3067\u306e\u63a5\u7d9a<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n    err = l.Bind(ldap.BindUser, ldap.BindPassword)\n\n    if err != nil {\n        log.Printf(&amp;quot;Cannot connect with bind user\\n%s&amp;quot;, err.Error())\n        return nil, err\n    }\n<\/pre>\n<p>\u63a5\u7d9a\u304c\u3067\u304d\u305f\u3089\u3001 <code>Bind<\/code> \u3067\u30d0\u30a4\u30f3\u30c9\u30e6\u30fc\u30b6\u30fc\u3067\u306e\u63a5\u7d9a\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\n\u30d0\u30a4\u30f3\u30c9\u30e6\u30fc\u30b6\u30fc\u3068\u306f\u3001\u8a8d\u8a3c\u4f5c\u696d\u3092\u884c\u3046\u6642\u306b LDAP \u3078\u4e88\u3081\u30ed\u30b0\u30a4\u30f3\u3055\u305b\u3066\u304a\u304d\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u3055\u308c\u305f\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u30e6\u30fc\u30b6\u30fc\u3067\u3059\u306d\u3002<\/p>\n<p><code>err<\/code> \u304c\u8fd4\u3063\u3066\u3053\u306a\u3051\u308c\u3070\u63a5\u7d9a\u6210\u529f\u3067\u3059\u3002<\/p>\n<h3>LDAP \u691c\u7d22\u8a2d\u5b9a<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n    SearchRequest := ldapConnect.NewSearchRequest(\n        ldap.BindDN,\n        ldapConnect.ScopeWholeSubtree, ldapConnect.NeverDerefAliases, 0, 0, false,\n        fmt.Sprintf(&amp;quot;(sAMAccountName=%s)&amp;quot;, username),\n        &#x5B;]string{&amp;quot;dn&amp;quot;, &amp;quot;sAMAccountName&amp;quot;, &amp;quot;displayName&amp;quot;},\n        nil,\n    )\n\n    log.Printf(&amp;quot;Start search user: %s&amp;quot;, username)\n<\/pre>\n<p><code>NewSearchRequest<\/code> \u3092\u4f7f\u3063\u3066\u3001LDAP \u691c\u7d22\u306e\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\n<code>NewSearchRequest(\u30d0\u30a4\u30f3\u30c9DN, \u691c\u7d22\u30b9\u30b3\u30fc\u30d7, \u95a2\u7bc0\u53c2\u7167\u8a2d\u5b9a, \u30b5\u30a4\u30ba\u30ea\u30df\u30c3\u30c8, \u30bf\u30a4\u30e0\u30ea\u30df\u30c3\u30c8, \u5c5e\u6027 ID \u306e\u307f\u8fd4\u5374\u306e\u30d5\u30e9\u30b0, \u30d5\u30a3\u30eb\u30bf\u30fc, \u691c\u7d22\u5bfe\u8c61\u306e\u6587\u5b57\u5217, \u8fd4\u5374\u306b\u542b\u3080\u5024)<\/code>\u3000\u3067\u3059\u306d\u3002\u5927\u4f53\u898b\u305f\u3089\u308f\u304b\u308b\u3093\u3058\u3083\u306a\u3044\u304b\u306a\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u91cd\u8981\u306a\u306e\u306f\u30d5\u30a3\u30eb\u30bf\u30fc\u3068\u691c\u7d22\u5bfe\u8c61\u306e\u6587\u5b57\u5217\u3067\u3059\u306d\u3002<br \/>\n\u4eca\u56de\u306f AD \u3092\u4f7f\u3046\u306e\u3067\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b <code>sAMAccountName<\/code> \u306b\u5bfe\u3057\u3066\u3001 <code>username<\/code> \u306e\u5024\u3068\u4e00\u81f4\u3059\u308b\u306e\u3082\u306e\u3092\u53d6\u5f97\u3057\u3066\u304f\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3042\u3068\u3001\u8fd4\u5374\u306b\u542b\u3080\u5024\u306b\u306f\u57fa\u672c\u7684\u306b\u5fc5\u8981\u306a\u5024\u3092\u5217\u6319\u3059\u308c\u3070\u3088\u3044\u3067\u3059\u304c\u3001 <code>dn<\/code> \u306f\u5f8c\u3067\u4f7f\u7528\u3059\u308b\u306e\u3067\u5fc5\u305a\u542b\u3081\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>LDAP \u691c\u7d22\u5b9f\u884c<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n    \/\/ LDAP \u691c\u7d22\u5b9f\u884c\n    sr, err := l.Search(SearchRequest)\n    if err != nil {\n        log.Printf(&amp;quot;Search failed.\\n%s&amp;quot;, err.Error())\n        return nil, err\n    }\n<\/pre>\n<p><code>l.Search(SearchRequest)<\/code> \u306e\u3088\u3046\u306b\u3001 <code>Search<\/code> \u306b \u5148\u307b\u3069\u4f5c\u6210\u3057\u305f <code>SearchRequest<\/code> \u3092\u547c\u3076\u3053\u3068\u3067\u3001\u5b9f\u969b\u306b\u691c\u7d22\u3092\u304b\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u7d50\u679c\u306f <code>sr<\/code> \u306b\u5165\u308a\u307e\u3059\u306d\u3002<\/p>\n<h3>\u691c\u7d22\u7d50\u679c\u6570\u78ba\u8a8d (1 \u4ef6\u306b\u7279\u5b9a\u3067\u304d\u306a\u3044\u5834\u5408\u306f\u5931\u6557)<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n    \/\/ \u691c\u7d22\u7d50\u679c\u6570\u78ba\u8a8d (1 \u4ef6\u306b\u7279\u5b9a\u3067\u304d\u306a\u3044\u5834\u5408\u306f\u5931\u6557)\n    if len(sr.Entries) == 0 {\n        log.Printf(&amp;quot;Not found user: %s&amp;quot;, username)\n        return nil, fmt.Errorf(&amp;quot;not found user: %s&amp;quot;, username)\n    } else if len(sr.Entries) &amp;gt; 1 {\n        log.Printf(&amp;quot;Too many found user: %s&amp;quot;, username)\n        return nil, fmt.Errorf(&amp;quot;too many found user: %s&amp;quot;, username)\n    }\n\n    entity := sr.Entries&#x5B;0]\n<\/pre>\n<p>\u7d50\u679c\u306e <code>.Entries<\/code> \u306b\u7d50\u679c\u304c\u5165\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n0 \u4ef6\u306a\u3089\u30de\u30c3\u30c1\u7121\u3057\u3067\u30e6\u30fc\u30b6\u30fc\u540d\u304c\u8aa4\u3063\u3066\u3044\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u306d\u3002<br \/>\n\u307e\u305f\u3001\u9006\u306b 2 \u4ef6\u4ee5\u4e0a\u306a\u3089\u30e6\u30fc\u30b6\u30fc\u304c\u7279\u5b9a\u3067\u304d\u306a\u3044\u6761\u4ef6\u3067\u691c\u7d22\u3057\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u308c\u3082\u5931\u6557\u3067\u3059\u3002<br \/>\n1 \u4ef6\u3060\u3051\u3067\u3042\u308c\u3070\u30e6\u30fc\u30b6\u30fc\u304c\u7279\u5b9a\u3067\u304d\u305f\u306e\u3067\u3001\u3053\u308c\u3092 <code>entity<\/code> \u5909\u6570\u3078\u5165\u308c\u3066\u6b21\u3078\u9032\u307f\u307e\u3059\u3002<\/p>\n<h3>\u8a8d\u8a3c\u30e6\u30fc\u30b6\u30fc\u30d1\u30b9\u30ef\u30fc\u30c9\u6b63\u8aa4\u78ba\u8a8d<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n    \/\/ \u8a8d\u8a3c\u30e6\u30fc\u30b6\u30fc\u30d1\u30b9\u30ef\u30fc\u30c9\u6b63\u8aa4\u78ba\u8a8d\n    err = l.Bind(entity.DN, password)\n    if err != nil {\n        log.Printf(&amp;quot;Authorization failed user: %s&amp;quot;, username)\n        return nil, err\n    }\n\n    log.Printf(&amp;quot;Authorization success user: %s&amp;quot;, username)\n<\/pre>\n<p>\u3053\u3053\u3067\u3001\u5148\u307b\u3069\u53d6\u5f97\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u9001\u3063\u3066\u304d\u305f\u30d1\u30b9\u30ef\u30fc\u30c9\u3068\u4e00\u81f4\u3057\u3066\u3044\u308b\u304b\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<p>\u78ba\u8a8d\u306e\u65b9\u6cd5\u306f\u7c21\u5358\u3067\u3001\u7279\u5b9a\u3067\u304d\u305f\u30e6\u30fc\u30b6\u30fc\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092 LDAP \u30b5\u30fc\u30d0\u30fc\u3078\u6e21\u3057\u3066\u3001\u30ed\u30b0\u30a4\u30f3\u304c\u3067\u304d\u308b\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<br \/>\n<code>err<\/code> \u306b\u4f55\u304b\u304c\u8fd4\u3063\u3066\u304d\u305f\u3089\u5931\u6557\u3067\u30d1\u30b9\u30ef\u30fc\u30c9\u9593\u9055\u3044\u3001 <code>nil<\/code> \u306a\u3089\u30ed\u30b0\u30a4\u30f3\u6210\u529f\u306a\u306e\u3067\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u5408\u3063\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u306d\uff01<\/p>\n<h3>sAMAccountName, displayName, DN \u3092\u8fd4\u5374<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n  \/\/ sAMAccountName, displayName, DN \u3092\u8fd4\u5374\n    return &amp;amp;LdapResult{\n        LoginName: entity.GetAttributeValue(&amp;quot;sAMAccountName&amp;quot;),\n        Name: entity.GetAttributeValue(&amp;quot;displayName&amp;quot;),\n        DN: entity.GetAttributeValue(&amp;quot;dn&amp;quot;),\n    }, nil\n<\/pre>\n<p>\u6700\u5f8c\u306b\u3001\u53d6\u5f97\u3067\u304d\u305f\u60c5\u5831\u3092 LdapResult \u306b\u683c\u7d0d\u3057\u3066\u547c\u3073\u51fa\u3057\u5143\u306b\u8fd4\u3057\u3066\u3042\u3052\u307e\u3057\u3087\u3046\u3002<\/p>\n<h1>\u7d42\u308f\u308a\u306b<\/h1>\n<p>\u30d1\u30c3\u3068\u898b\u8907\u96d1\u305d\u3046\u306b\u898b\u3048\u307e\u3059\u304c\u3001\u7d50\u5c40\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f<\/p>\n<ul>\n<li>LDAP \u30b5\u30fc\u30d0\u30fc\u3078\u8a8d\u8a3c\u7528\u30e6\u30fc\u30b6\u30fc\u3067\u63a5\u7d9a<\/li>\n<li>\u6e21\u3055\u308c\u305f\u60c5\u5831\u304b\u3089\u30e6\u30fc\u30b6\u30fc\u3092\u691c\u7d22<\/li>\n<li>\u898b\u3064\u304b\u3063\u305f\u30e6\u30fc\u30b6\u30fc\u3067\u30ed\u30b0\u30a4\u30f3\u3092\u8a66\u307f\u3066\u3001\u30ed\u30b0\u30a4\u30f3\u51fa\u6765\u305f\u3089 OK !<\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u3060\u3051\u306e\u3053\u3068\u3067\u3059\u306d\u3002<\/p>\n<p>\u3053\u308c\u3067 LDAP \u30b5\u30fc\u30d0\u30fc\u3067\u306e\u8a8d\u8a3c\u3092\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u3068\u3057\u3066\u5207\u308a\u5206\u3051\u3089\u308c\u305d\u3046\u3067\u3059\u306d\uff01<br \/>\nGo\u8a00\u8a9e\u3001\u305c\u3072\u6d3b\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go\u8a00\u8a9e\u3067 LDAP \u8a8d\u8a3c\u3057\u305f\u3044\uff01 \u7686\u3055\u3093\u3001 Go\u8a00\u8a9e\u66f8\u3044\u3066\u307e\u3059\u304b\uff01 Go\u8a00\u8a9e\u306f\u6700\u8fd1\u306f\u3084\u308a\u306e\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u306b\u3082\u5411\u3044\u3066\u3044\u308b\u611f\u304c\u3042\u308a\u307e\u3059\u3057\u3001 \u4e00\u6642\u306e\u71b1\u306f\u51b7\u3081\u3064\u3064\u3042\u308b\u3082\u306e\u306e\u3001\u306a\u304b\u306a\u304b\u4f7f\u3044\u52dd\u624b\u306f\u826f\u3044\u8a00\u8a9e\u3067\u3059\u3088\u306d\u3002 \u4eca\u56de\u306f\u3001 G [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":8421,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10],"tags":[342,343],"class_list":["post-8414","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech","tag-go","tag-ldap"],"jetpack_featured_media_url":"https:\/\/www.agent-grow.com\/self20percent\/wp-content\/uploads\/2018\/06\/850c7612116999490846136e772ab7fd.png","jetpack_shortlink":"https:\/\/wp.me\/p7Bq4F-2bI","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/posts\/8414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/comments?post=8414"}],"version-history":[{"count":0,"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/posts\/8414\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/media\/8421"}],"wp:attachment":[{"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/media?parent=8414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/categories?post=8414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/tags?post=8414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}