博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

从EntLib(1.0)的一个例子理解身份验证的三个概念。

Posted on 2007-06-29 17:47  吴博  阅读(188)  评论(0)    收藏  举报
 1 public static bool Authenticate(string username, string password)
 
2        {
 
3            bool authenticated = false;
 
4
 
5            
 
6            NamePasswordCredential credentials;
 
7            credentials = new NamePasswordCredential(username, password);
 
8 
 
9            IAuthenticationProvider authprovider;
10            authprovider = AuthenticationFactory.GetAuthenticationProvider();
11 
12            IIdentity identity;
13            authenticated = authprovider.Authenticate(credentials, out identity);
14 
15            if (!authenticated)
16            {
17                throw new SecurityException("Invalid username or password.");
18            }

19            
20          
21            
22            IRolesProvider rolesprovider;
23            rolesprovider = RolesFactory.GetRolesProvider();
24 
25            IPrincipal principal;
26            principal = rolesprovider.GetRoles(identity);
27 
28            // Place user's principal on the thread
29            Thread.CurrentPrincipal = principal;
30            
31            return authenticated;
32        }

这三个概念是:

1.          Credential(令牌)
2.          Identity(身份)
3.          Principal(主体特征)


您理解了吗?