public void CreateItemsFromAFolder( string storageConnectionString, string storeName, string applicationName, string folderPath, string searchPattern, ItemType itemType) { using (IAzManStorage storage = new SqlAzManStorage(storageConnectionString)) { storage.OpenConnection(); storage.BeginTransaction(); try { IAzManApplication app = storage.GetStore(storeName).GetApplication(applicationName); DirectoryInfo di = new DirectoryInfo(folderPath); foreach (FileInfo fi in di.GetFiles(searchPattern)) { //Use some recursive function to get subfolder files app.CreateItem(fi.Name, String.Empty, itemType); } storage.CommitTransaction(); } catch { storage.RollBackTransaction(); } finally { storage.Dispose(); } } }
/// <summary> /// Create an Authorization Delegate /// </summary> private void AddDBUserToRole(string dbUserName, string roleName) { //Sql Storage connection string string sqlConnectionString = "data source=(local);initial catalog=NetSqlAzManStorage;user id=sa;password=password"; //Create an instance of SqlAzManStorage class using (IAzManStorage storage = new SqlAzManStorage(sqlConnectionString)) { storage.OpenConnection(); IAzManStore mystore = storage.GetStore("My Store"); //or storage["My Store"] IAzManApplication myapp = mystore.GetApplication("My Application"); IAzManItem myRole = myapp.GetItem(roleName); //Retrieve DB user identity IAzManDBUser dbUser = storage.GetDBUser(dbUserName); //Add DB "My Db User" to "My Role" role. IAzManAuthorization auth = myRole.CreateAuthorization(new SqlAzManSID(WindowsIdentity.GetCurrent().User), WhereDefined.LDAP, dbUser.CustomSid, WhereDefined.Database, AuthorizationType.Allow, null, null); //Optional: add authorization attribute //auth.CreateAttribute("attribute key", "attribute value"); storage.CloseConnection(); storage.Dispose(); } }
private void button1_Click_2(object sender, EventArgs e) { IAzManStorage storage = new SqlAzManStorage("data source=.;Initial Catalog=NetSqlAzManStorage;Integrated Security = SSPI;"); IAzManStore store = storage.GetStore("Store Stress Test"); foreach (KeyValuePair<string, bool> kvp in store.GetManagers()) { MessageBox.Show(String.Format("Manager: {0} IsSqlRole: {1}", kvp.Key, kvp.Value)); } foreach (KeyValuePair<string, bool> kvp in store.GetUsers()) { MessageBox.Show(String.Format("User: {0} IsSqlRole: {1}", kvp.Key, kvp.Value)); } foreach (KeyValuePair<string, bool> kvp in store.GetReaders()) { MessageBox.Show(String.Format("Reader: {0} IsSqlRole: {1}", kvp.Key, kvp.Value)); } IAzManApplication app = store["Application1"]; foreach (KeyValuePair<string, bool> kvp in app.GetManagers()) { MessageBox.Show(String.Format("Manager: {0} IsSqlRole: {1}", kvp.Key, kvp.Value)); } foreach (KeyValuePair<string, bool> kvp in app.GetUsers()) { MessageBox.Show(String.Format("User: {0} IsSqlRole: {1}", kvp.Key, kvp.Value)); } foreach (KeyValuePair<string, bool> kvp in app.GetReaders()) { MessageBox.Show(String.Format("Reader: {0} IsSqlRole: {1}", kvp.Key, kvp.Value)); } }
private void btnTestImport_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.DefaultExt = "xml"; openFileDialog.FileName = "NetSqlAzMan.xml"; openFileDialog.Filter = "Xml files|*.xml|All files|*.*"; openFileDialog.SupportMultiDottedExtensions = true; openFileDialog.Title = "Import from ..."; DialogResult dr = openFileDialog.ShowDialog(this); if (dr == DialogResult.OK) { frmImportOptions frm = new frmImportOptions(); IAzManStorage storage = new SqlAzManStorage("data source=.;Initial Catalog=NetSqlAzManStorage;Integrated Security = SSPI;"); IAzManStore store = storage.GetStore("Eidos"); frm.importIntoObject = store; frm.fileName = openFileDialog.FileName; frm.ShowDialog(); } }
private void btnItemManipulate_Click(object sender, EventArgs e) { try { IAzManStorage storage = new SqlAzManStorage("data source=.;Initial Catalog=NetSqlAzManStorage;Integrated Security = SSPI;"); IAzManStore store = storage.GetStore("Store Stress Test"); //IAzManStoreGroup storage = store.GetStoreGroup("Store Group 1"); IAzManItem item = store.GetApplication("Application0").GetItem("Operation0"); string bizRule = @"using System; using System.Security.Principal; using System.IO; using System.Data; using System.Collections; using System.Collections.Specialized; using System.Collections.Generic; using System.Text; using NetSqlAzMan; using NetSqlAzMan.Interfaces; namespace Prova.BizRules { public sealed class BizRule : IAzManBizRule { public BizRule() { } public bool Execute(Hashtable contextParameters, IAzManSid identity, IAzManItem ownerItem, ref AuthorizationType authorizationType) { //my comments //Assign authorizationType to some AuthorizationType value to force CheckAccess result for this item. return true; } } } "; //@"Imports System //Imports System.Security.Principal //Imports System.IO //Imports System.Data //Imports System.Data.SqlClient //Imports System.Collections //Imports System.Collections.Specialized //Imports System.Collections.Generic //Imports System.Text //Imports NetSqlAzMan //Imports NetSqlAzMan.Interfaces // //Namespace MyApplication.BizRules // Public NotInheritable Class BizRule : Implements IAzManBizRule // Public Sub New() // End Sub // // Public Overloads Function Execute(ByVal contextParameters As Hashtable, ByVal identity As WindowsIdentity, ByVal ownerItem As IAzManItem) As Boolean _ // Implements IAzManBizRule.Execute // Return True // End Function // End Class //End Namespace // //"; item.ReloadBizRule(bizRule, NetSqlAzMan.BizRuleSourceLanguage.CSharp); Assembly ass = item.LoadBizRuleAssembly(); //AuthorizationType authorizationType = storage.CheckAccess(System.Security.Principal.WindowsIdentity.GetCurrent(), DateTime.Now); //MessageBox.Show(authorizationType.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnIHV_Click(object sender, EventArgs e) { //IAzManStorage storage = new SqlAzManStorage("data source=.;Initial Catalog=NetSqlAzManStorage;Integrated Security = SSPI;"); //IAzManStore store = storage.GetStore("Store Stress Test"); //NetSqlAzMan.SnapIn.Printing.ptItemAuthorizations doc = new NetSqlAzMan.SnapIn.Printing.ptItemAuthorizations(); //doc.Applications = new IAzManApplication[] { // store.GetApplication("Application0") // //,store.GetApplication("Application1"), // //store.GetApplication("Application2"), // //store.GetApplication("Application3"), // //store.GetApplication("Application4") //}; //frmPrint frm = new frmPrint(); //frm.Document = doc; //frm.ShowDialog(this); IAzManStorage storage = new SqlAzManStorage("data source=.;Initial Catalog=NetSqlAzManStorage;Integrated Security = SSPI;"); IAzManStore store = storage.GetStore("Eidos"); NetSqlAzMan.SnapIn.Printing.ptEffectivePermissions doc = new NetSqlAzMan.SnapIn.Printing.ptEffectivePermissions(); doc.Applications = new IAzManApplication[] { store.GetApplication("DB Persone") //,store.GetApplication("Application1"), //store.GetApplication("Application2"), //store.GetApplication("Application3"), //store.GetApplication("Application4") }; frmPrint frm = new frmPrint(); frm.Document = doc; frm.ShowDialog(this); }
private void btnExport_Click(object sender, EventArgs e) { IAzManStorage storage = new SqlAzManStorage("data source=.;Initial Catalog=NetSqlAzManStorage;user id=sa;password="******"Eidos").GetApplication("Feedback"); frmExportOptions frm = new frmExportOptions(); frmExport frmwait = new frmExport(); frmwait.ShowDialog(null, "c:\\netsqlazman.xml", new IAzManExport[] { app }, true, false, true, app.Store.Storage); }
private void btnEventHandling_Click(object sender, EventArgs e) { //SqlAzManENS.ApplicationUpdated += new ApplicationUpdatedDelegate(SqlAzManENS_ApplicationUpdated); IAzManStorage storage = new SqlAzManStorage("data source=.;Initial Catalog=NetSqlAzManStorage;Integrated Security = SSPI;"); IAzManStore store = storage.GetStore("Store Stress Test"); IAzManApplication application = store.GetApplication("Application0"); application.ApplicationUpdated += new NetSqlAzMan.ENS.ApplicationUpdatedDelegate(application_Updated); application.Update("New Description"); MessageBox.Show("Descrizione dell'Applicazione modificata !"); }
private void btnCheckAccessTest_Click(object sender, EventArgs e) { //IAzManStorage storage = new SqlAzManStorage("data source=.;Initial Catalog=NetSqlAzManStorage;Integrated Security = SSPI;"); //List<KeyValuePair<string, string>> attributes; //var auth = storage.CheckAccess("AET Authorization Store", "Trading Hub", "Create Deal", WindowsIdentity.GetCurrent(), DateTime.Now, false, out attributes); //return; frmCheckAccessTest frm = new frmCheckAccessTest(); IAzManStorage storage = new SqlAzManStorage("data source=(local);Initial Catalog=NetSqlAzManStorage;Integrated Security = SSPI;"); //IAzManStore store = storage.GetStore("Sistel-1Sez"); //frm.application = store.GetApplication("Perseo.Net"); IAzManStore store = storage.GetStore("Eidos"); frm.application = store.GetApplication("DB persone"); frm.ShowDialog(); }
public bool AddRole(string user, string application, string role) { const string store = "CATS"; string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["CatsContext"].ConnectionString; IAzManStorage storage = new SqlAzManStorage(connectionString); IAzManStore mystore = storage.GetStore(store); //or storage["My Store"] IAzManApplication myapp = mystore.GetApplication(application); //mystore.GetApplications(); IAzManItem azManRole = myapp.GetItem(role); IAzManAuthorization dele = azManRole.CreateAuthorization( mystore.GetDBUser("Admin").CustomSid, WhereDefined.Database, mystore.GetDBUser(user).CustomSid, WhereDefined.Database, AuthorizationType.AllowWithDelegation, null, null ); //IAzManAuthorization del = azManRole.CreateDelegateAuthorization(mystore.GetDBUser("Admin"),mystore.GetDBUser(user).CustomSid,RestrictedAuthorizationType.Allow, null,null); return true; }
public List<Application> GetUserPermissions(string UserName) { var apps = new List<Application>(); //try //{ const string store = "CATS"; string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["CatsContext"].ConnectionString; IAzManStorage storage = new SqlAzManStorage(connectionString); IAzManStore mystore = storage.GetStore(store); //or storage["My Store"] // IAzManApplication myapp = mystore.GetApplication(application); List<IAzManApplication> Applications = mystore.GetApplications().ToList(); //_provider.Initialize("AuthorizationRoleProvider", ConfigureAuthorizationRoleProvider("CATS","Early warning")); //Dictionary<string, IAzManApplication> Applications = _provider.GetStorage().Stores["CATS"].Applications; foreach (var app in Applications) { apps.Add(new Application() { ApplicationName = app.Name, Roles = GetUserPermissions(UserName, "CATS", app.Name) }); } return apps; //} //catch(Exception ex) //{ // var s = ex.Message; // return apps; //} }
/// <summary> /// Remove Authorization Delegate /// </summary> private void RemoveDelegate() { // USER MUST BE A MEMBER OF SQL DATABASE ROLE: NetSqlAzMan_Users //Sql Storage connection string string sqlConnectionString = "data source=(local);initial catalog=NetSqlAzManStorage;user id=netsqlazmanuser;password=password"; //Create an instance of SqlAzManStorage class IAzManStorage storage = new SqlAzManStorage(sqlConnectionString); IAzManStore mystore = storage.GetStore("My Store"); //or storage["My Store"] IAzManApplication myapp = mystore.GetApplication("My Application"); IAzManItem myop = myapp.GetItem("My Operation"); //Retrieve current user identity (delegating user) WindowsIdentity userIdentity = ((System.Threading.Thread.CurrentPrincipal.Identity as WindowsIdentity) ?? WindowsIdentity.GetCurrent()); //for Windows Applications //WindowsIdentity userIdentity = this.Request.LogonUserIdentity; //for ASP.NET Applications //Retrieve delegate user Login NTAccount delegateUserLogin = new NTAccount("DOMAIN", "delegateuseraccount"); //Retrieve delegate user SID SecurityIdentifier delegateSID = (SecurityIdentifier)delegateUserLogin.Translate(typeof(SecurityIdentifier)); IAzManSid delegateNetSqlAzManSID = new SqlAzManSID(delegateSID); //Estabilish delegate authorization (only Allow or Deny) RestrictedAuthorizationType delegateAuthorization = RestrictedAuthorizationType.Allow; //Remove delegate and all custom attributes myop.DeleteDelegateAuthorization(userIdentity, delegateNetSqlAzManSID, delegateAuthorization); }
/// <summary> /// Navigate through NetSqlAzMan DOM (Document Object Model) /// </summary> private void NetSqlAzMan_DOM_Sample() { // USER MUST BE A MEMBER OF SQL DATABASE ROLE: NetSqlAzMan_Readers //Sql Storage connection string string sqlConnectionString = "data source=(local);initial catalog=NetSqlAzManStorage;user id=netsqlazmanuser;password=password"; //Create an instance of SqlAzManStorage class IAzManStorage storage = new SqlAzManStorage(sqlConnectionString); IAzManStore mystore = storage.GetStore("My Store"); //or storage["My Store"] IAzManApplication myapp = mystore.GetApplication("My Application"); IAzManItem myop = myapp.GetItem("My Operation"); IAzManAuthorization[] auths = myop.GetAuthorizations(); foreach (IAzManAuthorization auth in auths) { IAzManAttribute<IAzManAuthorization>[] attrs = auth.GetAttributes(); foreach (IAzManAttribute<IAzManAuthorization> attr in attrs) { string attrKey = attr.Key; string attrValue = attr.Value; //do something } } }