コード例 #1
0
        public User Authenticate(Credentials credentials)
        {
            var sect = m_Config ?? App.ConfigRoot[CommonApplicationLogic.CONFIG_SECURITY_SECTION];

            if (sect.Exists && credentials is IDPasswordCredentials)
            {
                var idpass = (IDPasswordCredentials)credentials;

                var usern = findUserNode(sect, idpass);

                if (usern.Exists)
                {
                    var name   = usern.AttrByName(CONFIG_NAME_ATTR).ValueAsString(string.Empty);
                    var descr  = usern.AttrByName(CONFIG_DESCRIPTION_ATTR).ValueAsString(string.Empty);
                    var status = usern.AttrByName(CONFIG_STATUS_ATTR).ValueAsEnum <UserStatus>(UserStatus.Invalid);

                    var rights = Rights.None;

                    var rightsn = usern[CONFIG_RIGHTS_SECTION];

                    if (rightsn.Exists)
                    {
                        var data = new MemoryConfiguration();
                        data.CreateFromNode(rightsn);
                        rights = new Rights(data);
                    }

                    return(new User(credentials,
                                    credToAuthToken(idpass),
                                    status,
                                    name,
                                    descr,
                                    rights));
                }
            }

            return(new User(credentials,
                            new AuthenticationToken(),
                            UserStatus.Invalid,
                            StringConsts.SECURITY_NON_AUTHENTICATED,
                            StringConsts.SECURITY_NON_AUTHENTICATED,
                            Rights.None));
        }
コード例 #2
0
        public User Authenticate(Credentials credentials)
        {
            if (credentials is BearerCredentials bearer)
            {
                var oauth = App.ModuleRoot.TryGet <Services.IOAuthModule>();
                if (oauth == null)
                {
                    return(MakeBadUser(credentials));
                }

                var accessToken = oauth.TokenRing.GetAsync <Tokens.AccessToken>(bearer.Token).GetAwaiter().GetResult(); //since this manager is sync-only
                if (accessToken != null)                                                                                //if token is valid
                {
                    if (SysAuthToken.TryParse(accessToken.SubjectSysAuthToken, out var sysToken))
                    {
                        return(Authenticate(sysToken));
                    }
                }
            }

            var sect = m_Config ?? App.ConfigRoot[CommonApplicationLogic.CONFIG_SECURITY_SECTION];

            if (sect.Exists)
            {
                IConfigSectionNode usern = sect.Configuration.EmptySection;

                if (credentials is IDPasswordCredentials idpass)
                {
                    usern = findUserNode(sect, idpass);
                }
                if (credentials is EntityUriCredentials enturi)
                {
                    usern = findUserNode(sect, enturi);
                }

                if (usern.Exists)
                {
                    var name   = usern.AttrByName(CONFIG_NAME_ATTR).ValueAsString(string.Empty);
                    var descr  = usern.AttrByName(CONFIG_DESCRIPTION_ATTR).ValueAsString(string.Empty);
                    var status = usern.AttrByName(CONFIG_STATUS_ATTR).ValueAsEnum(UserStatus.Invalid);

                    var rights = Rights.None;

                    var rightsn = usern[CONFIG_RIGHTS_SECTION];

                    if (rightsn.Exists)
                    {
                        var data = new MemoryConfiguration();
                        data.CreateFromNode(rightsn);
                        rights = new Rights(data);
                    }

                    return(MakeUser(credentials,
                                    credToAuthToken(credentials),
                                    status,
                                    name,
                                    descr,
                                    rights));
                }
            }

            return(MakeBadUser(credentials));
        }
コード例 #3
0
                                      //20150403 DKh added support for include pragmas
                                      private ConfigSectionNode calculateEffectiveAppConfig(string appName)
                                      {
                                          var pragmasDisabled = Metabank.RootConfig.AttrByName(Metabank.CONFIG_APP_CONFIG_INCLUDE_PRAGMAS_DISABLED_ATTR).ValueAsBool(false);
                                          var includePragma   = Metabank.RootConfig.AttrByName(Metabank.CONFIG_APP_CONFIG_INCLUDE_PRAGMA_ATTR).Value;


                                          var conf = new MemoryConfiguration();

                                          conf.CreateFromNode(Metabank.RootAppConfig);
                                          conf.Application = this.Metabank.SkyApp;

                                          var result = conf.Root;

                                          if (!pragmasDisabled)
                                          {
                                              result.ProcessAllExistingIncludes("root", includePragma);
                                          }

                                          var derivation = new List <configLevel>();

                                          #region build derivation chain --------------------------------------------------------------------------
                                          //Role level
                                          var role = this.Role;

                                          if (!role.AppNames.Any(an => INVSTRCMP.Equals(an, appName)))
                                          {
                                              throw new MetabaseException(StringConsts.METABASE_HOST_ROLE_APP_MISMATCH_ERROR.Args(appName, RoleName));
                                          }

                                          derivation.Add(new configLevel(role, role.AnyAppConfig));

                                          //App level
                                          var app = Metabank.CatalogApp.Applications[appName];
                                          if (app == null)
                                          {
                                              throw new MetabaseException(StringConsts.METABASE_BAD_HOST_APP_ERROR.Args(appName));
                                          }

                                          derivation.Add(new configLevel(app, app.AnyAppConfig));

                                          //Regional level
                                          var parents = this.ParentSectionsOnPath;
                                          foreach (var item in parents)
                                          {
                                              derivation.Add(new configLevel(item, item.AnyAppConfig));
                                              derivation.Add(new configLevel(item, item.GetAppConfig(appName)));
                                          }

                                          //This Level
                                          derivation.Add(new configLevel(this, this.AnyAppConfig));
                                          derivation.Add(new configLevel(this, this.GetAppConfig(appName)));
                                          #endregion

                                          foreach (var clevel in derivation.Where(cl => cl.Node != null))
                                          {
                                              if (!pragmasDisabled)
                                              {
                                                  ((ConfigSectionNode)clevel.Node).ProcessAllExistingIncludes(clevel.From.ToString(), includePragma);
                                              }

                                              try
                                              {
                                                  result.OverrideBy(clevel.Node);
                                              }
                                              catch (Exception error)
                                              {
                                                  throw new MetabaseException(StringConsts.METABASE_EFFECTIVE_APP_CONFIG_OVERRIDE_ERROR.Args(clevel.From.ToString(), error.ToMessageWithType()), error);
                                              }
                                          }

                                          //OS Include
                                          var include = result[CONFIG_OS_APP_CONFIG_INCLUDE_SECTION];
                                          if (include.Exists)
                                          {
                                              var osInclude = Metabank.GetOSConfNode(this.OS)[CONFIG_APP_CONFIG_SECTION] as ConfigSectionNode;
                                              if (osInclude.Exists)
                                              {
                                                  include.Configuration.Include(include, osInclude);
                                              }
                                          }

                                          result.ResetModified();
                                          return(result);
                                      }
コード例 #4
0
        private async Task <TreeNodeInfo> getNodeByGdid(HashSet <GDID> graph, TreePtr tree, GDID gNode, DateTime asOfUtc, ICacheParams caching)
        {
            var tblCache = s_CacheTableName[tree];
            var keyCache = nameof(getNodeByGdid) + gNode.ToHexString() + asOfUtc.Ticks;
            var result   = await m_Data.Cache.FetchThroughAsync(
                keyCache, tblCache, caching,
                async key =>
            {
                if (!graph.Add(gNode))
                {
                    //circular reference
                    var err = new ConfigException("Circular reference in config tree = `{0}`, gnode = `{1}`, asof = `{2}`".Args(tree, gNode, asOfUtc));
                    WriteLogFromHere(Log.MessageType.CatastrophicError,
                                     err.Message,
                                     err,
                                     pars: new { tree = tree.ToString(), gnode = gNode, asof = asOfUtc }.ToJson());
                    throw err;
                }

                //1 - fetch THIS level - rightmost part of the tree
                var qry = new Query <TreeNodeInfo>("Tree.GetNodeInfoByGdid")
                {
                    new Query.Param("tree", tree),
                    new Query.Param("gdid", gNode),
                    new Query.Param("asof", asOfUtc)
                };

                var node = await m_Data.TreeLoadDocAsync(tree, qry);
                if (node == null)
                {
                    return(null);
                }

                //2 - if IAM ROOT, there is no parent for root
                node.EffectiveConfig = new ConfigVector(node.LevelConfig.Content);//Copy
                node.FullPath        = Constraints.VERY_ROOT_PATH_SEGMENT;

                if (node.Gdid == Constraints.G_VERY_ROOT_NODE)
                {
                    return(node);
                }

                //3 - Fetch parent of THIS
                TreeNodeInfo nodeParent = await getNodeByGdid(graph, tree, node.G_Parent, asOfUtc, caching).ConfigureAwait(false);
                if (nodeParent == null)
                {
                    return(null);
                }

                //4 - calculate effective config
                var cfgNode   = node.LevelConfig.Node.NonEmpty(nameof(node.LevelConfig));
                var cfgParent = nodeParent.EffectiveConfig.Node.NonEmpty(nameof(nodeParent.EffectiveConfig));

                var confResult = new MemoryConfiguration()
                {
                    Application = this.App
                };
                confResult.CreateFromNode(cfgParent); //inherit
                confResult.Root.OverrideBy(cfgNode);  //override
                node.EffectiveConfig.Node = confResult.Root;

                node.FullPath = TreePath.Join(nodeParent.FullPath, node.PathSegment);

                //the security check is done post factum AFTER tree node full path is known
                return(node);
            }
                ).ConfigureAwait(false);

            if (result == null)
            {
                return(null);
            }
            App.Authorize(new TreePermission(TreeAccessLevel.Read, result.FullPathId));
            return(result);
        }
コード例 #5
0
            internal static Mapping TryBuild(IApplication app, IConfigSectionNode node)
            {
                var strexts = node.AttrByName(CONFIG_EXTENSIONS_ATTR).Value;

                if (strexts.IsNullOrWhiteSpace())
                {
                    app.Log.Write(new Log.Message
                    {
                        Type  = Log.MessageType.Warning,
                        Topic = CoreConsts.WEB_TOPIC,
                        From  = $"{typeof(Mapping).FullName}{nameof(Mapping.TryBuild)}",
                        Text  = $"{node.RootPath}/${CONFIG_EXTENSIONS_ATTR}.IsNullOrWhiteSpace"
                    });
                    return(null);
                }

                var exts = strexts.Split(SPLITS, System.StringSplitOptions.RemoveEmptyEntries)
                           .Select(e => Mappings.prepExtension(e))
                           .Where(e => e.IsNotNullOrWhiteSpace())
                           .ToArray();

                if (exts.Length == 0)
                {
                    app.Log.Write(new Log.Message
                    {
                        Type  = Log.MessageType.Warning,
                        Topic = CoreConsts.WEB_TOPIC,
                        From  = $"{typeof(Mapping).FullName}{nameof(Mapping.TryBuild)}",
                        Text  = $"{node.RootPath}/${CONFIG_EXTENSIONS_ATTR} no extensions"
                    });
                    return(null);
                }

                var ctyp = node.AttrByName(CONFIG_CONTENT_TYPE_ATTR).Value;

                if (ctyp.IsNullOrWhiteSpace())
                {
                    app.Log.Write(new Log.Message
                    {
                        Type  = Log.MessageType.Warning,
                        Topic = CoreConsts.WEB_TOPIC,
                        From  = $"{typeof(Mapping).FullName}{nameof(Mapping.TryBuild)}",
                        Text  = $"{node.RootPath}/${CONFIG_CONTENT_TYPE_ATTR}.IsNullOrWhiteSpace"
                    });
                    return(null);
                }

                var result = new Mapping();

                result.m_Extensions  = exts;
                result.m_ContentType = ctyp;
                ConfigAttribute.Apply(result, node);
                result.m_Name = new NLSMap(node[CONFIG_NAME_SECTION]);

                var mnode = node[CONFIG_META_SECTION];

                var cfg = new MemoryConfiguration();

                if (mnode.Exists)
                {
                    cfg.CreateFromNode(mnode);
                    result.m_Metadata = cfg.Root;
                }
                else
                {
                    result.m_Metadata = cfg.EmptySection;
                }

                cfg.SetReadOnly(true);

                return(result);
            }