2010-07-19 2 views
0

폼 인증을 사용하는 웹 응용 프로그램과 Active Directory에 대해 사용자를 인증하기 위해 ActiveDirectoryMembershipProvider를 개발 중입니다. 우리는 곧 Active Directory에서 완벽하게 합법적 인 경우에도 (암호 정책이없는 경우) 공급자가 공백/비어있는 암호를 지정할 수 없음을 알게되었습니다. 반사판의ActiveDirectoryMembershipProvider가 빈 암호를 허용하는 방법?

씨 : .NET의 마법을 사용하여이 기능을 오버라이드 (override) 할 수있는 방법은 우리 자신의 사용자 지정 공급자를 작성 짧은

private void CheckPassword(string password, int maxSize, string paramName) 
{ 
    if (password == null) 
    { 
     throw new ArgumentNullException(paramName); 
    } 
    if (password.Trim().Length < 1) 
    { 
     throw new ArgumentException(SR.GetString("Parameter_can_not_be_empty", new object[] { paramName }), paramName); 
    } 
    if ((maxSize > 0) && (password.Length > maxSize)) 
    { 
     throw new ArgumentException(SR.GetString("Parameter_too_long", new object[] { paramName, maxSize.ToString(CultureInfo.InvariantCulture) }), paramName); 
    } 
} 

?

답변

1

나는 당신이이 동작을 변경할 수 있습니다 믿지 않는를 파생 클래스를 생성하고 개인 checkpassword를 메서드를 호출하는 모든 방법을 overiding없이. 그러나이 옵션을 권장하지는 않을 것입니다. 귀하의 디자인을 검토하고 응용 프로그램에서 빈 암호를 허용하는 것이 적절한 지 여부를 질문하는 것이 좋습니다. AD에서 유효하지만 실제로는 허용되지 않으며 Windows 네트워크에서 다른 것들에 영향을 미칩니다. 네트워크 파일 공유의 기본 설정은 빈 암호가있는 사용자가 공유에 연결할 수 없도록하는 것입니다.

+0

빈/빈 암호로 파일 공유 및 네트워크 드라이브 등을 연결할 수 있습니다. ActiveDirectoryMembershipProvider를 제외하고 전폭적으로 지원됩니다. 맞습니다. 하위 클래스를 만들지 않고이 동작을 특별히 재정의 할 방법이 없습니다. – fletcher

0

아마도 가장을 사용하여 볼 수는 있지만 같은 문제가 있는지 잘 모릅니다. 사용자를 승인하는 것이면 가장을 사용하여 시스템의 사용자를 "가장 할"수 있습니다. 나는 그것이 도움이되는지 모르지만 나는 다른 주에 이것과 비슷한 것을하고 있었다. 이 중 하나라도 도움이된다면 아래의 코드를 넣어 가지고 ... :)

using System; 
using System.Runtime.InteropServices; 

public partial class Test_Index : System.Web.UI.Page { 
protected void Page_Load(object sender, EventArgs e) 
{   
    IntPtr ptr = IntPtr.Zero; 
    if (LogonUser("USERNAME", "", "LEAVE-THIS-BLANK", LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, ref ptr)) 
    { 
     using (System.Security.Principal.WindowsImpersonationContext context = new System.Security.Principal.WindowsIdentity(ptr).Impersonate()) 
     { 
      try 
      { 
       // Do do something 
      } 
      catch (UnauthorizedAccessException ex) 
      { 
       // failed to do something 
      } 

      // un-impersonate user out 
      context.Undo(); 
     } 
    } 
    else 
    { 
     Response.Write("login fail"); 
    } 
} 

#region imports 

[DllImport("advapi32.dll", SetLastError = true)] 
private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken); 

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] 
private static extern bool CloseHandle(IntPtr handle); 

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] 
public extern static bool DuplicateToken(IntPtr existingTokenHandle, int SECURITY_IMPERSONATION_LEVEL, ref IntPtr duplicateTokenHandle); 

#endregion 

#region logon consts 

// logon types 
const int LOGON32_LOGON_INTERACTIVE = 2; 
const int LOGON32_LOGON_NETWORK = 3; 
const int LOGON32_LOGON_NEW_CREDENTIALS = 9; 

// logon providers 
const int LOGON32_PROVIDER_DEFAULT = 0; 
const int LOGON32_PROVIDER_WINNT50 = 3; 
const int LOGON32_PROVIDER_WINNT40 = 2; 
const int LOGON32_PROVIDER_WINNT35 = 1; 
#endregion } 
관련 문제