• 信息系统开发平台OpenExpressApp - 使用CSLA类库实现用户管理


      在《信息系统开发平台OpenExpressApp - 用户权限模块设计》中对RBAC以及在OEA中的涉及进行了简要介绍,权限的基础必须存在用户,实现自定义用户管理,CSLA已经提供一些类库来继承使用,本篇简单的讲解一下如何使用CSLA类库实现用户管理以及登录,下一篇再介绍功能权限部分。

    用户管理模块

      这个其实就是一个用户字典管理,包括用户名、登录名和密码,没有考虑证书等功能,由于目前实现比较简单,User类库编写按照以往类库就行了,这里就不单独讲了。

    实现用户主体Principal

      主体实现登录和退出功能,登录成功后返回用户,否则为非法用户。CSLA实现了一个类BusinessPrincipalBase,我们只要从它继承下来就可以很方便的实现OEA的Principal对象,这个对象在登录窗口时调用调用。

      Principal代码如下:

    public class OEAPrincipal : BusinessPrincipalBase
    {
    private OEAPrincipal(IIdentity identity)
    :
    base(identity)
    { }

    public static bool Login(string username, string password)
    {
    var identity
    = OEAIdentity.GetIdentity(username, password);
    if (identity.IsAuthenticated)
    {
    OEAPrincipal principal
    = new OEAPrincipal(identity);
    Csla.ApplicationContext.User
    = principal;
    return true;
    }
    else
    {
    Csla.ApplicationContext.User
    = new UnauthenticatedPrincipal();
    return false;
    }
    }

    public static void Logout()
    {
    Csla.ApplicationContext.User
    = new UnauthenticatedPrincipal();

    实现用户标识Identity

      通过用户名和密码去服务器端查询后返回用户标识对象,在这里会把角色也返回过来,角色部分功能权限blog中再介绍。

    /// <summary>
    /// 注意:防止重名,User增加Code区分唯一性,查询时通过Code查询,同时返回Code和Name
    /// </summary>
    [Serializable()]
    public class OEAIdentity : CslaIdentity
    {
    #region Factory Methods

    internal static OEAIdentity GetIdentity(string username, string password)
    {
    return DataPortal.Fetch<OEAIdentity>(new UsernameCriteria(username, password));
    }

    public User User { get; set; }

    private OEAIdentity()
    {
    /* require use of factory methods */ }

    #endregion

    #region Data Access

    public new OrgPositions Roles { get; private set; }

    private void DataPortal_Fetch(UsernameCriteria criteria)
    {
    User
    = UserList.Get(criteria.Username, criteria.Password);

    if (null != User)
    {
    base.Name = User.Name;
    base.IsAuthenticated = true;
    this.Roles = OrgPositions.GetList(User.Id); // list of roles from security store
    }
    else
    {
    base.Name = string.Empty;
    base.IsAuthenticated = false;
    this.Roles = null;
    }
    }

    #endregion

    }

    更多内容: 开源信息系统开发平台之OpenExpressApp框架.pdf

  • 相关阅读:
    VS2005调试网站时不显示Flash元素
    js中使用弹出窗体
    Ipod Touch/Iphone歌词同步软件整理
    Chrome Dev 4.0.*增加flash支持
    字符串数组排序(qsort参数 比较函数)
    查找两个已经排好序的数组的第k大的元素
    求用1,2,5这三个数不同个数组合的和为100的组合个数
    Hadoop分布式环境下的数据抽样(转)
    Reservoir Sampling
    欧拉回路
  • 原文地址:https://www.cnblogs.com/zhoujg/p/1641388.html
Copyright © 2020-2023  润新知