zoukankan      html  css  js  c++  java
  • Enterprise Library: Security Quickstart代码解析篇, Part 1

    Enterprise Library: Security Quickstart代码解析篇

    Part 1

    Written by: Rickie Lee (rickieleemail#yahoo.com)

    My blog: www.cnblogs.com/rickie

    Enterprise Library Security Quickstart基于Security Application Block, Database Application Block, Caching Application Block, Configuration Application Block, Cryptography Application Block等构建,是所有Quickstart中较复杂的一个。其中,用户、角色、用户角色关系、Profile等等均存放在数据库中。

     

    Security Application Block Quick Start应用程序运行界面包括Security Database Management, Authentication, Authorization, Profile, Roles5个部分。

    1. Security Database Management

    Security Database Management部分包括用户管理、用户角色关系管理等功能。

    如下是增加用户部分代码:

           this.databaseManager.InsertUser(this.credentialsForm.Username, this.credentialsForm.Password);

           this.DisplayDatabaseResults(SR.UserCreatedMessage(this.credentialsForm.Username));

    SecurityDatabaseManager.InsertUser()调用Microsoft.Practices.EnterpriseLibrary.Security.Database.UserRoleManage类的InsertUser方法,将用户信息Username/Password插入数据表,方法如下:

                  public void InsertUser(string userName, string password)

                  {

                         byte[] pwdBytes = SHA1Managed.Create().ComputeHash(ASCIIEncoding.ASCII.GetBytes(password));

                         if (!this.manager.UserExists(userName))

                         {

                                this.manager.CreateUser(userName, pwdBytes);

                         }

                  }

    如下是Quickstart应用程序中的SecurityDatabaseManager类,该类包含类型UserRoleManager的成员变量manage

    this.manager = new UserRoleManager(DbInstanceName, ConfigurationManager.GetCurrentContext());

    SecurityDatabaseManager类提供的方法几乎都是调用Microsoft.Practices.EnterpriseLibrary.Security.Database.UserRoleManager类的方法来实现的,上述2个类的Class Diagram如下所示:

    Enterprise_SecurityAB_SecurityDatabaseManager.JPG

     

    Security Database Management中其它功能,如删除用户、用户角色管理(增加用户角色和删除用户角色)等代码类似。

    ***

    作者:Rickie Lee (rickieleemail#yahoo.com)

    本文参考分析Enterprise Library Security Application Block Quickstart应用程序。

     

    References:

    1. Microsoft Enterprise Library: Enterprise Library Security Application Block Quickstart.

    2. Rickie, Microsoft patterns & practices Enterprise Library January 2005 [中文稿], http://www.cnblogs.com/rickie/archive/2005/01/30/99443.html

    3. Rickie, Enterprise Library released! http://www.cnblogs.com/rickie/archive/2005/01/29/99106.html

  • 相关阅读:
    资源链接
    python pip下载速度慢的解决方法
    淘宝 NPM 镜像
    python学习链接
    Linux升级python3之后yum不能正常使用解决方法一:重新配置yum源
    rand和srand的用法
    static与volatile的用法
    CentOS 7
    C++类(Class)总结
    简单的linux命令
  • 原文地址:https://www.cnblogs.com/rickie/p/109524.html
Copyright © 2011-2022 走看看