簡體   English   中英

如何使用 springboot 檢查用戶是否已添加到 LDAP 組

[英]How to check if the user has been added to LDAP group using springboot

我需要驗證用戶是否已成功添加到特定組。 我能想到的唯一選擇是使用異常處理。 是否有更好的方法來使用任何類型的 LDAP 響應代碼。

public boolean addMemberToGroup(String groupName, Person p) {
        boolean status = false;
        Name groupDn = buildGroupDn(groupName);
        Name personDn = buildPersonDn(p);
        try {
            
            DirContextOperations ctx = ldapTemplate.lookupContext(groupDn);
            ctx.addAttributeValue(UNIQUE_MEMBER, personDn);
            ldapTemplate.modifyAttributes(ctx);
            status  = true;
        }catch (Exception e) {
            status =false;
        }
        return status;
    }

好吧,這是我過去的處理方式:

  • 查找我需要在我的活動目錄中創建的用戶(如果為真則返回 false 則該用戶已存在)
  • 創建用戶
  • 再次查找用戶(這次返回 true)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM