示例#1
0
        private ObservableCollection <TreeViewVMItem> GetTokenIssuers()
        {
            var cps = new ObservableCollection <TreeViewVMItem>();

            // Find the CP which contains TPs for token issuers
            foreach (var tp in App.PolicySet.Base.Root
                     .Element(Constants.dflt + "ClaimsProviders")
                     .Elements() // ClaimsProvider
                     .First(cp => cp.Element(Constants.dflt + "DisplayName").Value == "Token Issuer")
                     .Element(Constants.dflt + "TechnicalProfiles")
                     .Elements(Constants.dflt + "TechnicalProfile"))
            {
                var ti = new TreeViewVMItem()
                {
                    Name       = tp.Attribute("Id").Value,
                    DataSource = tp,
                    Category   = TreeViewVMItem.TreeViewItemCatorgies.Detail,
                    DetailType = TreeViewVMItem.TreeViewItemDetails.TokenIssuer,
                    OnSelect   = new DelegateCommand((obj) => DetailView = new Page()
                    {
                        Content = new Views.TokenIssuerDetails()
                        {
                            DataContext = new ViewModels.TokenIssuerDetails()
                            {
                                Source = tp
                            }
                        }
                    })
                };
                cps.Add(ti);
            }

            return(cps);
        }
示例#2
0
        TreeViewVMItem FindArtifact(XElement vm, ObservableCollection <TreeViewVMItem> items)
        {
            if (items == null)
            {
                return(null);
            }
            TreeViewVMItem item = null;

            foreach (var i in items)
            {
                if (i.DataSource == vm)
                {
                    item = i;
                }
                else
                {
                    item = FindArtifact(vm, i.Items);
                }
                if (item != null)
                {
                    break;
                }
            }
            return(item);
        }
示例#3
0
        private ObservableCollection <TreeViewVMItem> GetInternalClaimProviders()
        {
            var cps = new ObservableCollection <TreeViewVMItem>();

            // Find all CPs using the 'proprietary' protocol or no protocol (because they use an include)
            foreach (var el in App.PolicySet.Base.Root
                     .Element(Constants.dflt + "ClaimsProviders")
                     .Elements() // ClaimsProvider
                     .Where(cp => cp.Element(Constants.dflt + "TechnicalProfiles").Elements(Constants.dflt + "TechnicalProfile").First().Element(Constants.dflt + "Protocol").Attribute("Name").Value == "Proprietary"))
            {
                var cp = new TreeViewVMItem()
                {
                    Name       = el.Element(Constants.dflt + "DisplayName").Value,
                    DataSource = el,
                    Category   = TreeViewVMItem.TreeViewItemCatorgies.Detail,
                    DetailType = TreeViewVMItem.TreeViewItemDetails.ClaimsProvider,
                };
                foreach (var tp in el.Element(Constants.dflt + "TechnicalProfiles").Elements(Constants.dflt + "TechnicalProfile"))
                {
                    var protocol = tp.element("Protocol");
                    if ((protocol != null) && (protocol.Attribute("Handler") != null) && protocol.Attribute("Handler").Value.StartsWith("Web.TPEngine.Providers.RestfulProvider"))
                    {
                        cp.Items.Add(new TreeViewVMItem()
                        {
                            Name       = tp.Attribute("Id").Value,
                            DataSource = tp,
                            Category   = TreeViewVMItem.TreeViewItemCatorgies.Detail,
                            DetailType = TreeViewVMItem.TreeViewItemDetails.TechnicalProfile,
                            OnSelect   = new DelegateCommand((obj) => DetailView = new Page()
                            {
                                Content = new Views.RESTDetails()
                                {
                                    DataContext = new RESTDetails((XElement)obj)
                                }
                            })
                        });
                    }
                    else
                    {
                        cp.Items.Add(new TreeViewVMItem()
                        {
                            Name       = tp.Attribute("Id").Value,
                            DataSource = tp,
                            Category   = TreeViewVMItem.TreeViewItemCatorgies.Detail,
                            DetailType = TreeViewVMItem.TreeViewItemDetails.TechnicalProfile,
                            OnSelect   = new DelegateCommand((obj) => DetailView = new Page()
                            {
                                Content = new Views.TechnicalProfileClaims()
                                {
                                    DataContext = new TechnicalProfileClaims((XElement)obj)
                                }
                            })
                        });
                    }
                }
                cps.Add(cp);
            }

            return(cps);
        }
示例#4
0
        public void SelectArtifact(XElement source)
        {
            var artifact = GetArtifact(source);

            if (artifact == null)
            {
                throw new ApplicationException("Artifact (treeview vm) representing this model element was not found in the tree.");
            }
            SelectedArtifact = artifact;
        }
示例#5
0
        private TreeViewVMItem GetArtifact(XElement source, TreeViewVMItem parent = null)
        {
            IEnumerable <TreeViewVMItem> items = parent == null ? Items : parent.Items;

            if (items == null)
            {
                return(null);
            }
            foreach (var a in items)
            {
                if (a.DataSource == source)
                {
                    return(a);
                }
                var resp = GetArtifact(source, a);
                if (resp != null)
                {
                    return(resp);
                }
            }
            return(null);
        }
示例#6
0
        private ObservableCollection <TreeViewVMItem> GetExternalClaimProviders()
        {
            var cps = new ObservableCollection <TreeViewVMItem>();

            // Find all CPs NOT using the 'proprietary' protocol (ie. OAuth or OIDC)
            foreach (var el in App.PolicySet.Base.Root
                     .Element(Constants.dflt + "ClaimsProviders")
                     .Elements() // ClaimsProvider
                     .Elements(Constants.dflt + "TechnicalProfiles")
                     .Elements()
                     .Where(tp => (tp.Element(Constants.dflt + "Protocol") != null)))
            {
                var protocolName = el.Element(Constants.dflt + "Protocol").Attribute("Name").Value;
                if ((String.Compare(protocolName, "Proprietary", true) == 0) ||
                    (String.Compare(protocolName, "None", true) == 0))
                {
                    continue;
                }
                var cp = new TreeViewVMItem()
                {
                    DataSource = el,
                    Category   = TreeViewVMItem.TreeViewItemCatorgies.Detail,
                    DetailType = TreeViewVMItem.TreeViewItemDetails.IdP
                };
                var attr = el.Element(Constants.dflt + "DisplayName");
                if (attr != null)
                {
                    cp.Name = attr.Value;
                }
                var domain = el.Parent.Parent.Element(Constants.dflt + "Domain");
                if ((domain != null) && (new string[] { "facebook.com", "google.com", "live.com", "google.com", "linkedin.com", "twitter.com" }).Contains(domain.Value))
                {
                    cp.OnSelect = new DelegateCommand((obj) => DetailView = new Views.SocialIdP()
                    {
                        DataContext = new ViewModels.SocialIdP((XElement)obj)
                    });
                }
                else if (protocolName == "OAuth2")
                {
                    cp.OnSelect = new DelegateCommand((obj) => DetailView = new Views.OAuthConfiguration(obj));
                }
                else if (protocolName == "SAML2")
                {
                    cp.OnSelect = new DelegateCommand((obj) => DetailView = new Views.SAMLIdP()
                    {
                        DataContext = new ViewModels.SAMLIdP((XElement)obj)
                    });
                }
                else if (String.Compare(el.Attribute("Id").Value, "login-NonInteractive") != 0) // AAD?
                {
                    var meta = el.Element(Constants.dflt + "Metadata");
                    if (meta != null)
                    {
                        var sts = meta.Elements(Constants.dflt + "Item").Where(i => i.Attribute("Key")?.Value == "METADATA").First();
                        if ((sts != null) && (sts.Value.StartsWith("https://login.microsoftonline.com/")))
                        {
                            cp.OnSelect = new DelegateCommand((obj) => DetailView = new Views.AADIdP()
                            {
                                DataContext = new ViewModels.AADIdP((XElement)obj)
                            });
                        }
                    }
                }
                cps.Add(cp);
            }

            return(cps);
        }
示例#7
0
        public MainWindow()
        {
            Current   = this;
            Trace     = new ObservableCollection <TraceItem>();
            NewPolicy = new DelegateCommand(() =>
            {
                if (SaveCurrent(true))
                {
                    var dlgVm = new ViewModels.NewPolicyLoad();
                    var dlg   = new Views.NewPolicyLoad()
                    {
                        DataContext = dlgVm
                    };
                    dlgVm.Closing += () => dlg.Close();
                    dlg.ShowDialog();
                    App.MRU.ProjectFolder = String.Empty;
                    UpdateTree();
                }
            });
            Open = new DelegateCommand(() =>
            {
                if (SaveCurrent(true))
                {
                    if (App.PolicySet.IsDirty)
                    {
                        Save.Execute(null);
                    }
                    var dlg = new System.Windows.Forms.FolderBrowserDialog()
                    {
                        SelectedPath = App.MRU.ProjectFolder
                    };
                    if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return;
                    }
                    var projectDir = dlg.SelectedPath;
                    //var projectDir = ConfigurationManager.AppSettings["xml:ProjectDir"];
                    var projFile = $"{projectDir}/PolicySet.json";
                    if (File.Exists(projFile))
                    {
                        using (var str = File.OpenText(projFile))
                        {
                            var json      = str.ReadToEnd();
                            App.PolicySet = JsonConvert.DeserializeObject <Models.PolicySet>(json);
                        }
                    }
                    else
                    {
                        App.PolicySet = new Models.PolicySet()
                        {
                            NamePrefix = "Prefix"
                        }
                    };

                    App.MRU.ProjectFolder = projectDir;

                    //var sourceDir = "";
                    //if ((App.PolicySet.FileNames != null) && File.Exists($"{projectDir}/{App.PolicySet.FileNames[0]}.xml"))
                    //    sourceDir = projectDir;
                    //else
                    //    sourceDir = ConfigurationManager.AppSettings["xml:Base"];
                    //App.PolicySet.Load(sourceDir);
                    App.PolicySet.Load(projectDir);
                    if (App.PolicySet.Base != null)
                    {
                        PopulateTreeView();
                    }
                }
            });
            Save = new DelegateCommand(() =>
            {
                var projectDir = App.MRU.ProjectFolder; // ConfigurationManager.AppSettings["xml:ProjectDir"];
                if (String.IsNullOrEmpty(projectDir))
                {
                    var dlg = new System.Windows.Forms.FolderBrowserDialog()
                    {
                        ShowNewFolderButton = true,
                        SelectedPath        = App.MRU.ProjectFolder
                    };
                    //dlg.RootFolder = Environment.SpecialFolder.Desktop;
                    if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return;
                    }
                    App.MRU.ProjectFolder = projectDir = dlg.SelectedPath;
                }
                ;
                var projFile = $"{projectDir}/PolicySet.json";
                using (var str = File.CreateText(projFile))
                {
                    var json = JsonConvert.SerializeObject(App.PolicySet);
                    str.Write(json);
                }
                App.PolicySet.Save();
                Trace.Add(new TraceItem()
                {
                    Msg = $"Policy {NamePrefix} generated to {projectDir}"
                });
                App.PolicySet.IsDirty = false;
            });
            AddIdP = new DelegateCommand(() =>
            {
                var vm  = new ViewModels.AddIdPWizard();
                var wiz = new Views.AddIdPWizard()
                {
                    DataContext = vm
                };
                wiz.ShowDialog();
                //wiz.Close();
                if (vm.IsApplied)
                {
                    UpdateTree();
                    SelectArtifact(vm.CreatedIdP.Element(Constants.dflt + "TechnicalProfiles").Element(Constants.dflt + "TechnicalProfile"));
                }
            });
            AddRESTApi = new DelegateCommand(() =>
            {
                var restAPIs = App.PolicySet.Base.Root
                               .element("ClaimsProviders")
                               .elements("ClaimsProvider")
                               .FirstOrDefault(el => el.Attribute("DisplayName")?.Value == "REST APIs");
                if (restAPIs == null)
                {
                    restAPIs = new XElement(Constants.dflt + "ClaimsProvider",
                                            new XElement(Constants.dflt + "DisplayName", "REST APIs"),
                                            new XElement(Constants.dflt + "TechnicalProfiles"));
                    App.PolicySet.Base.Root.element("ClaimsProviders").Add(restAPIs);
                }
                var restAPI = XElement.Load(System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream("B2CPolicyEditor.IdPPolicies.REST.xml"));
                restAPIs.element("TechnicalProfiles").Add(restAPI);
                PopulateTreeView();
                SelectedArtifact = FindArtifact(restAPI, _items);
            });
            DeleteItem = new DelegateCommand(() =>
            {
                if ((SelectedArtifact == null) || (SelectedArtifact.Category != TreeViewVMItem.TreeViewItemCatorgies.Detail))
                {
                    return;
                }
                switch (SelectedArtifact.DetailType)
                {
                case TreeViewVMItem.TreeViewItemDetails.IdP:
                    {
                        App.PolicySet.RemoveIdP((XElement)SelectedArtifact.DataSource);
                        var header = Items.First(i => i.Category == TreeViewVMItem.TreeViewItemCatorgies.IdPs);
                        header.Items.Remove(SelectedArtifact);
                        SelectedArtifact = Items[0];
                    }
                    break;

                default:
                    break;
                }
            });
            CopyItem = new DelegateCommand(() =>
            {
                if ((SelectedArtifact == null) || (SelectedArtifact.Category != TreeViewVMItem.TreeViewItemCatorgies.Detail))
                {
                    return;
                }
                switch (SelectedArtifact.DetailType)
                {
                case TreeViewVMItem.TreeViewItemDetails.TechnicalProfile:
                    {
                        var tp         = (XElement)SelectedArtifact.DataSource;
                        var copy       = new XElement(tp);
                        var cp         = tp.Parent.Parent;
                        string newName = String.Empty;
                        for (int i = 1; i < 100; i++)
                        {
                            newName = $"{tp.Attribute("Id").Value}({i})";
                            if (cp.Element(Constants.dflt + "TechnicalProfiles").
                                Elements(Constants.dflt + "TechnicalProfile").
                                FirstOrDefault(t => t.Attribute("Id").Value == newName) == null)
                            {
                                break;
                            }
                        }
                        copy.SetAttributeValue("Id", newName);
                        tp.AddAfterSelf(copy);
                        var header = Items.First(i => i.Category == TreeViewVMItem.TreeViewItemCatorgies.ClaimProviders);
                        header     = header.Items.First(h => h.DataSource == cp);
                        var tvi    = new TreeViewVMItem()
                        {
                            Name       = newName,
                            DataSource = copy,
                            Category   = TreeViewVMItem.TreeViewItemCatorgies.Detail,
                            DetailType = TreeViewVMItem.TreeViewItemDetails.TechnicalProfile,
                            OnSelect   = new DelegateCommand((obj) => DetailView = new Page()
                            {
                                Content = new Views.TechnicalProfileClaims()
                                {
                                    DataContext = new TechnicalProfileClaims((XElement)obj)
                                }
                            })
                        };
                        var currIx = header.Items.IndexOf(_selectedArtifact);
                        if (currIx == header.Items.Count - 1)
                        {
                            header.Items.Add(tvi);
                        }
                        else
                        {
                            header.Items.Insert(currIx + 1, tvi);
                        }
                        SelectedArtifact = tvi;
                    }
                    break;

                default:
                    break;
                }
            });
            AddJourneyType = new DelegateCommand(() =>
            {
                var journeys = App.PolicySet.Base.Root.Element(Constants.dflt + "UserJourneys");
                if (journeys == null)
                {
                    App.PolicySet.Base.Root.Add(new XElement(Constants.dflt + "UserJourneys"));
                    journeys = App.PolicySet.Base.Root.Element(Constants.dflt + "UserJourneys");
                }
                var name    = "NewJourney";
                var journey = new XElement(Constants.dflt + "UserJourney",
                                           new XAttribute("Id", name),
                                           new XElement(Constants.dflt + "OrchestrationSteps",
                                                        new XElement(Constants.dflt + "OrchestrationStep",
                                                                     new XAttribute("Order", 1),
                                                                     new XAttribute("Type", "SendClaims"),
                                                                     new XAttribute("CpimIssuerTechnicalProfileReferenceId", "JwtIssuer"))),
                                           new XElement(Constants.dflt + "ClientDefinition", new XAttribute("ReferenceId", "DefaultWeb")));
                journeys.Add(journey);
                var header = Items.FirstOrDefault(i => i.Category == TreeViewVMItem.TreeViewItemCatorgies.Journeys);
                header.Items.Add(new JourneyTypeItem()
                {
                    Category = TreeViewVMItem.TreeViewItemCatorgies.Detail,
                    OnSelect = new DelegateCommand((obj) => DetailView = new Views.JourneyEditor()
                    {
                        DataContext = new ViewModels.JourneyEditor((XElement)obj)
                    }),
                    DetailType  = TreeViewVMItem.TreeViewItemDetails.Journey,
                    DataSource  = journey,
                    IsNameFixed = false,
                });
            });
            AddJourneyStep = new DelegateCommand(() =>
            {
                var wiz = new Views.AddJourneyStepWizard()
                {
                    DataContext = new JourneyEditor(_selectedArtifact.DataSource)
                };
                wiz.ShowDialog();
            });
            RecUserId = new DelegateCommand(() =>
            {
                if (App.PolicySet.Base == null)
                {
                    return;
                }
                var xml = XDocument.Load(System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream("B2CPolicyEditor.Recipies.UsingUserId.xml"));
                App.PolicySet.Base.Merge(xml);
                App.PolicySet.Base.ChangeLocalUserIdTypeInJourneys(true);
                UpdateTree();
            });
            AddSAMLAsIdP = new DelegateCommand(() =>
            {
                throw new NotSupportedException();
                //if (App.PolicySet.Base == null) return;
                //DetailView = new Views.SAMLAsRPSetup();
                //var xml = XDocument.Load(System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream("B2CPolicyEditor.IdPPolicies.AsSAMLIdP.xml"));
                //App.PolicySet.Base.Merge(xml);
                //UpdateTree();
            });
            AddTOU = new DelegateCommand(() =>
            {
                if (App.PolicySet.Base == null)
                {
                    return;
                }
                var vm  = new ViewModels.TOUSettings(App.PolicySet.Base);
                var wiz = new Views.TOUSettings()
                {
                    DataContext = vm
                };
                vm.Done += (r) =>
                {
                    var xml = XDocument.Load(System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream("B2CPolicyEditor.Recipies.AddTermsOfUse.xml"));
                    App.PolicySet.Base.Merge(xml);
                    App.PolicySet.Base.SetTOUVersion(vm.NewVersionId, vm.SignUpJourneys.Where(j => j.IsSelected).Select(j => j.Name));
                    UpdateTree();
                    wiz.Close();
                };
                wiz.ShowDialog();
            });
            RequirePwdChange = new DelegateCommand(() =>
            {
                if (App.PolicySet.Base == null)
                {
                    return;
                }
                var vm  = new ViewModels.RequirePwdChange();
                var wiz = new Views.RequirePwdChange()
                {
                    DataContext = vm
                };
                vm.Done += (r) =>
                {
                    var xml = XDocument.Load(System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream("B2CPolicyEditor.Recipies.ForcePwdChange.xml"));
                    App.PolicySet.Base.Merge(xml);
                    UpdateTree();
                    wiz.Close();
                };
                wiz.ShowDialog();
            });

            PolicySetup = new DelegateCommand(() => DetailView = new Views.PolicySetup());
            ShowClaims  = new DelegateCommand(() => DetailView = new Views.Claims()
            {
                DataContext = new ViewModels.Claims()
            });
        }