JMDSecurity.cs :  » Content-Management-Systems-CMS » JMDCMS » JMDCMS.Web.Lib » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » JMDCMS 
JMDCMS » JMDCMS.Web.Lib » JMDSecurity.cs
/*
  Copyright (C) 2007  Ajay Handa - jmdcms.com 
  This program is free software; 
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  License for more details.
  Some rights reserved. Please read License.txt for details.
  Removing above copyright message is a violation of license terms.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Principal;
using System.Web;
using System.Data;

namespace JMDCMS.Web.Lib{
    public class JMDSecurity
    {
        private bool isAdmin = false;

        // PAGE SECURITY FLAGS...
        private bool pageView = false;
        private bool pageAdd = false;
        private bool pageEdit = false;
        private bool pageDelete = false;
        private bool pageMove = false;
        private bool pageAddModules = false;

        // MODULE SECURITY FLAGS...
        private bool modView = false;
        private bool modEdit = false;
        private bool modDelete = false;
        private bool modMove = false;
        private bool modEditContent = false;

        public JMDSecurity()
        {
            // Constructor
        }
        public bool IsAdmin
        {
            get { return isAdmin; }
        }
        public bool PageView
        {
            get { return pageView; }
        }
        public bool PageAdd
        {
            get { return pageAdd; }
        }
        public bool PageEdit
        {
            get { return pageEdit; }
        }
        public bool PageDelete
        {
            get { return pageDelete; }
        }
        public bool PageMove
        {
            get { return pageMove; }
        }

        public bool PageAddModules
        {
            get { return pageAddModules; }
        }

        public void CheckPageAuth(string SqlConnectionString, string Site_Url, 
            string Page_Name)
        {
            //IPrincipal p = HttpContext.Current.User;
            IPrincipal p = HttpContext.Current.User;
            if (p.IsInRole("Admin"))
            {
                isAdmin = true;
                pageView = true;
                pageAdd = true;
                pageEdit = true;
                pageDelete = true;
                pageMove = true;
                pageAddModules = true;
            }
            else
            {
                SqlServer sqlServer = new SqlServer(SqlConnectionString);
                DataTable dt = sqlServer.JMD_PAGE_AUTH(Site_Url, Page_Name);
                if (dt.Rows.Count > 0)
                {
                    //string[] roles = authTicket.UserData.Split(new char[] { ';' });
                    string[] ViewRoles = dt.Rows[0]["VIEW_ROLES"].ToString().Split(new char[] { ';' });
                    string[] AddRoles = dt.Rows[0]["ADD_ROLES"].ToString().Split(new char[] { ';' });
                    string[] EditRoles = dt.Rows[0]["EDIT_ROLES"].ToString().Split(new char[] { ';' });
                    string[] MoveRoles = dt.Rows[0]["MOVE_ROLES"].ToString().Split(new char[] { ';' });
                    string[] DeleteRoles = dt.Rows[0]["DELETE_ROLES"].ToString().Split(new char[] { ';' });
                    string[] AddModuleRoles = dt.Rows[0]["ADD_MODULE_ROLES"].ToString().Split(new char[] { ';' });
                    foreach (string Role in ViewRoles)
                    {
                        if ((p.IsInRole(Role) && (string.Compare(Role.Trim(),string.Empty) != 0 )) || 
                            (String.Compare(Role, "Guests", true) == 0))
                        {
                            pageView = true;
                            break;
                        }
                        else if ((p.Identity.IsAuthenticated) && (String.Compare(Role, "Registered", true) == 0))
                        {
                            pageView = true;
                            break;
                        }
                    }
                    foreach (string Role in AddRoles)
                    {
                        if (p.IsInRole(Role) && (string.Compare(Role.Trim(), string.Empty) != 0 ))
                        {
                            pageAdd = true;
                            break;
                        }
                        else if ((p.Identity.IsAuthenticated) && (String.Compare(Role, "Registered", true) == 0))
                        {
                            pageAdd = true;
                            break;
                        }
                    }

                    foreach (string Role in EditRoles)
                    {
                        if (p.IsInRole(Role) && (string.Compare(Role.Trim(), string.Empty) != 0))
                        {
                            pageEdit = true;
                            break;
                        }
                        else if ((p.Identity.IsAuthenticated) && (String.Compare(Role, "Registered", true) == 0))
                        {
                            pageEdit = true;
                            break;
                        }
                    }
                    foreach (string Role in DeleteRoles )
                    {
                        if (p.IsInRole(Role) && (string.Compare(Role.Trim(), string.Empty) != 0 ))
                        {
                            pageDelete = true;
                            break;
                        }

                        else if ((p.Identity.IsAuthenticated) && (String.Compare(Role, "Registered", true) == 0))
                        {
                            pageDelete = true;
                            break;
                        }
                    }
                    foreach (string Role in MoveRoles)
                    {
                        if (p.IsInRole(Role) && (string.Compare(Role.Trim(), string.Empty) != 0 ))
                        {
                            pageMove = true;
                            break;
                        }

                        else if ((p.Identity.IsAuthenticated) && (String.Compare(Role, "Registered", true) == 0))
                        {
                            pageMove = true;
                            break;
                        }
                    }
                    foreach (string Role in AddModuleRoles)
                    {
                        if (p.IsInRole(Role) && (string.Compare(Role.Trim(), string.Empty) != 0 ))
                        {
                            pageAddModules = true;
                            break;
                        }
                        else if ((p.Identity.IsAuthenticated) && (String.Compare(Role, "Registered", true) == 0))
                        {
                            pageAddModules = true;
                            break;
                        }
                    }
                }
                dt.Dispose();
                sqlServer = null;
            }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.