/// <summary> /// 根据认证凭证类型选择合适的Provider /// </summary> /// <param name="credential"></param> /// <returns></returns> public IAuthenticationProvider Create(CredentialBase credential) { if (credential == null) { throw new ArgumentNullException("credential"); } Type providerType; if (AuthenticationConfigurationFacade.Providers.TryGetValue(credential.GetType(), out providerType)) { return((IAuthenticationProvider)Activator.CreateInstance(providerType)); } else { throw new NotSupportedException(credential.GetType().Name); } }
public virtual IIdentity Verify(CredentialBase credential) { if ((credential == null) || (credential.GetType() != CredentialType)) { throw new ArgumentException("credential"); } return(new IdentityMock() { AuthenticationType = AuthenticationType, Name = Name, State = State, IsAuthenticated = true }); }
/// <summary> /// 默认的认证过程 /// </summary> /// <param name="credential"></param> /// <returns></returns> public virtual IIdentity Authenticate(CredentialBase credential) { Trace.WriteLine("credential type is " + credential.GetType().Name); // 正常的验证过程 var result = Provider.Verify(credential); // 非功能性控制策略); if (AuthenticationConfigurationFacade.HandlerCoR != null) { AuthenticationConfigurationFacade.HandlerCoR.Handle(credential); } Trace.WriteLine("authentication result : " + result); return(result); }
public override IIdentity Verify(CredentialBase credential) { var adapter = new UsbAdapter(); if (!adapter.IsOpen) { adapter.Open(); } if (credential.GetType() != adapter.GetCredential(UsbAdapter.Pin).GetType()) { throw new NotSupportedException(); } var result = base.Verify(credential); adapter.Close(); return(result); }
public bool IsMatch(CredentialBase credential) { if (credential == null) { throw new ArgumentNullException("credential"); } bool result; if (ApplyToCredentialTypes.Count == 0) { result = false; } else { result = ApplyToCredentialTypes.Contains(credential.GetType()); } if (result) { Trace.WriteLine(string.Format(Resources.OutputFormat, "Policy", GetType().Name, "match")); } return(result); }