如何使用go-ldap模块将成员添加到GroupOfNames中?

huangapple go评论91阅读模式
英文:

How do I add a member into a GroupOfNames using go-ldap module?

问题

要将ObjectType为PosixAccount的用户添加到ObjectType为groupOfNames的组中,需要将其作为属性member的值添加进去。

我使用go-ldap模块来完成这个需求。

以下是我编写的代码示例:

    package main

    import (
        "log"
        "github.com/go-ldap/ldap"
    )
    
    func main() {
        // 连接代码在这里

        PutOnGroup := ldap.NewModifyRequest("cn=0000-00000-00000f-abc123-app-session,ou=servicesAccounts,dc=example,dc=com", []ldap.Control{})
        PutOnGroup.Replace("member", []string{"cn=1000000-fa00-de00-ac00-f00c00e00d00b00-ingestion-svc"})

        err = conn.Modify(PutOnGroup)

        if err != nil {
            log.Fatalf("error putting user on group %v: %v", PutOnGroup, err)
        }
    }

问题是,通过这样做,我只是替换了已经是组成员属性的用户。

我想将这个成员与已经存在的成员一起添加到组中。

我该如何做到这一点?


我不习惯在StackOverflow上提问,所以如果我的问题缺乏细节,我会提供更多信息。

英文:

The demand is to add an user of ObjectType PosixAccount into a group of ObjectType groupOfNames by adding it as value of attribute member.

I'm using go-ldap module to accomplish that.

Here below is a sample of the code I've written to complete this demand:

    package main

    import (

	"log"

	"github.com/go-ldap/ldap"
    )
    
    func main() {

        // connection code here

        PutOnGroup := ldap.NewModifyRequest("cn=0000-00000-00000f-abc123-app- 
        session,ou=servicesAccounts,dc=example,dc=com", []ldap.Control{})
        PutOnGroup.Replace("member", []string{"cn=1000000-fa00-de00-ac00-f00c00e00d00b00- 
        ingestion-svc"})

        err = conn.Modify(PutOnGroup)

        if err != nil {
	        log.Fatalf("error putting user on group %v: %v", PutOnGroup, err)
        }
    }

The thing is by doing that I just replace the user which is already member's attribute of group.

I'd like to input this member into the group alongside with members which is already there.

How could I do that?


I'm not used to ask questions in StackOverflow so if my question is lacking of details I'm looking foward to provide more information.

答案1

得分: 1

这个问题是通过将ldap.NewModifyRequest函数中的Replace更改为Add来解决的。

     PutOnGroup := ldap.NewModifyRequest("cn=0000-00000-00000f-abc123-app- 
        session,ou=servicesAccounts,dc=example,dc=com", []ldap.Control{})
     PutOnGroup.Add("member", []string{"cn=1000000-fa00-de00-ac00-f00c00e00d00b00- 
        ingestion-svc"})
英文:

This problem was solved by changing the ldap.NewModifyRequest's function Replace to Add.

     PutOnGroup := ldap.NewModifyRequest("cn=0000-00000-00000f-abc123-app- 
        session,ou=servicesAccounts,dc=example,dc=com", []ldap.Control{})
     PutOnGroup.Add("member", []string{"cn=1000000-fa00-de00-ac00-f00c00e00d00b00- 
        ingestion-svc"})

huangapple
  • 本文由 发表于 2022年5月24日 21:16:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/72363590.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定