Click here to Skip to main content
15,896,453 members
Articles / Web Development / ASP.NET

Discretionary ACL Authorization Security Model in Web Applications with NHibernate

Rate me:
Please Sign up or sign in to vote.
4.50/5 (4 votes)
27 Feb 2009CPOL10 min read 81.4K   432   40  
A practical object-level security approach.
using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Event;
using NHibernate.Event.Default;

namespace Vestris.Service.NHibernate
{
    /// <summary>
    /// NHibernate session factory.
    /// </summary>
    public class SessionFactory
    {
        private ISessionFactory _instance = null;
        private IInterceptor _interceptor = null;
        private SessionFactoryEventListeners _eventListeners;

        public SessionFactory()
        {
        }

        public SessionFactory(SessionFactoryEventListeners eventListeners)
        {
            _eventListeners = eventListeners;
        }

        //public SessionFactory(IInterceptor interceptor)
        //{
        //    _interceptor = interceptor;
        //}

        public ISessionFactory Instance
        {
            get
            {
                if (_instance == null)
                {
                    Configuration cfg = new Configuration();
                    cfg.Properties.Add("dialect", "NHibernate.Dialect.MsSql2005Dialect");
                    cfg.Properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
                    cfg.Properties.Add("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
                    cfg.Properties.Add("connection.connection_string", "Server=localhost;initial catalog=OLS;Integrated Security=SSPI");
                    cfg.AddAssembly("Data.NHibernate");
                    if (_interceptor != null) cfg.Interceptor = _interceptor;
                    if (_eventListeners != null) _eventListeners.Configure(cfg);
                    _instance = cfg.BuildSessionFactory();
                }
                return _instance;
            }
            set
            {
                _instance = value;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
dB.
Team Leader Application Security Inc., www.appsecinc.com
United States United States
Daniel Doubrovkine has been in software engineering for twelve years and is currently development manager at Application Security Inc. in New York City. He has been involved in many software ventures, including Xo3 and Vestris Inc, was a development lead at Microsoft Corp. in Redmond, and director of Engineering at Visible Path Corp. in New York City. Daniel also builds and runs a foodie website, http://www.foodcandy.com.

Comments and Discussions