2010-05-14 43 views
3

我目前正在使用Spring Security 3.0實現/配置Java Web應用程序的LDAP身份驗證。我將Microsoft AD LDS用作LDAP服務器,並選擇了Spring的BindAuthenticator。 我發現,只有經過身份驗證的用戶是該分區的Readers角色的成員時,身份驗證才起作用。 BindAuthenticator嘗試在身份驗證後讀取用戶的屬性,這在從目錄服務中檢索權限的情況下似乎是合理的。爲什麼Spring Security的BindAuthenticator需要讀取用戶權限?

作爲LDAP和AD的新手,當應用程序集成到現有AD結構中時,這是一種可接受的做法嗎? 可以微調給予用戶dns只讀屬性的讀取權限,而不是將它們添加到讀取器組中?

感謝 托馬斯


編輯2010年3月8日: 這是我落得這樣做: 我複製Spring的認證者(整個班級),併爲如下方法bindWithDn()。差異標記爲DIFF

private DirContextOperations bindWithDn(String userDn, String username, String password) { 
    BaseLdapPathContextSource ctxSource = (BaseLdapPathContextSource) getContextSource(); 
    DistinguishedName fullDn = new DistinguishedName(userDn); 
    fullDn.prepend(ctxSource.getBaseLdapPath()); 

    logger.debug("Attempting to bind as " + fullDn); 

    DirContext ctx = null; 
    try { 
     ctx = getContextSource().getContext(fullDn.toString(), password); 
     // Check for password policy control 
     PasswordPolicyControl ppolicy = PasswordPolicyControlExtractor.extractControl(ctx); 

     // *DIFF* Attributes attrs = ctx.getAttributes(userDn, getUserAttributes()); 

     DirContextAdapter result = new DirContextAdapter(null, new DistinguishedName(userDn), // *DIFF* 
       ctxSource.getBaseLdapPath()); 

     if (ppolicy != null) { 
      result.setAttributeValue(ppolicy.getID(), ppolicy); 
     } 

     return result; 
    } catch (NamingException e) { 
     // This will be thrown if an invalid user name is used and the method may 
     // be called multiple times to try different names, so we trap the exception 
     // unless a subclass wishes to implement more specialized behaviour. 
     if ((e instanceof org.springframework.ldap.AuthenticationException) 
       || (e instanceof org.springframework.ldap.OperationNotSupportedException)) { 
      handleBindException(userDn, username, e); 
     } else { 
      throw e; 
     } 
    // *DIFF* } catch (javax.naming.NamingException e) { 
    // *DIFF*  throw LdapUtils.convertLdapException(e); 
    } finally { 
     LdapUtils.closeContext(ctx); 
    } 

    return null; 
} 
+1

解決方案我去了 - 幾乎重複了Spring Security的BindAuthenticator並刪除了讀取用戶屬性的行。我正在使用一個自定義的AuthoritiesPopulator,所以沒有問題。 – Thomas 2010-05-17 00:28:59

回答

1

這對我來說很有意義,它感知認證者執行一個LDAP綁定「爲」身份驗證的用戶,並使用LDAP來填充細節對象的用戶。我猜測LDAP服務器要求用戶有一個角色授權他們讀取他們自己的屬性。

您是否嘗試將屬性集合(通過setUserAttributes)限制爲僅有的幾個屬性。我認爲在AD中,您可以將RBAC放在個別屬性上,因此您可能正在讀取具有「讀者」角色保護的一個屬性以及其他一些未受保護的屬性。

你的其他選擇是:

  • 的LDAP服務器上更改RBAC像你建議,但我沒有處方給你。
  • 使用不同的身份驗證方法,該身份驗證方法將綁定作爲通用服務器主體執行並讀取屬性。您可能仍然需要以用戶身份進行綁定以檢查其密碼。
+1

謝謝賈斯汀。我現在不查詢任何屬性。也想過創建一個不讀取屬性的定製BindAuthenticator,但是在這之前,我對如果一個綁定用戶讀取自己的屬性的常見行爲感興趣。 – Thomas 2010-05-14 05:38:40

相關問題