public ParameterResolverValue HasRoleName(IParameterResolverContext ctx, IList <ParameterResolverValue> args)
        {
            string roleName = args[0].Value as string;

            if (string.IsNullOrEmpty(roleName))
            {
                throw new Exception("HasRoleName expects a non-empty string parameter for rolename");
            }
            ISecurityModel securityModel = ctx.ProcessingContext.InputModel.SecurityModel;

            return(new ParameterResolverValue(securityModel.IsInRole(args[0].Value as string), EValueDataType.Boolean));
        }
 public GoverningBodiesService(IRepositoryWrapper repoWrapper,
                               IMapper mapper,
                               IUniqueIdService uniqueId,
                               IGoverningBodyBlobStorageRepository governingBodyBlobStorage,
                               ISecurityModel securityModel)
 {
     _securityModel = securityModel;
     _securityModel.SetSettingsFile(SecuritySettingsFile);
     _uniqueId    = uniqueId;
     _repoWrapper = repoWrapper;
     _mapper      = mapper;
     _governingBodyBlobStorage = governingBodyBlobStorage;
 }
Esempio n. 3
0
        public override IProcessingContextCollection GenerateProcessingContexts(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            Dictionary <string, object> files       = ResolveMultipartAsJson();
            List <InputModel>           inputModels = new List <InputModel>();

            if (files != null)
            {
                foreach (string key in files.Keys)
                {
                    if (files[key] is IPostedFile postedFile)
                    {
                        if (securityModel == null)
                        {
                            if (kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection.RequireAuthorization)
                            {
                                securityModel = new SecurityModel(_HttpContext);
                            }
                            else
                            {
                                securityModel = new SecurityModelMock(kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection);
                            }
                        }
                        InputModelParameters inputModelParameters = CreateBaseInputModelParameters(kraftGlobalConfigurationSettings, securityModel);
                        inputModelParameters             = ExtendInputModelParameters(inputModelParameters);
                        inputModelParameters.LoaderType |= ELoaderType.DataLoader; //TODO Not override passed in flags

                        foreach (string metaInfoKey in postedFile.MetaInfo.Keys)
                        {
                            inputModelParameters.Data.Add(metaInfoKey, postedFile.MetaInfo[metaInfoKey]);
                        }
                        inputModelParameters.Data.Add(key, postedFile);

                        inputModels.Add(new InputModel(inputModelParameters));
                    }
                }
            }
            _ProcessingContextCollection = new ProcessingContextCollection(CreateProcessingContexts(inputModels));
            return(_ProcessingContextCollection);
        }
Esempio n. 4
0
        public override IProcessingContextCollection GenerateProcessingContexts(string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            IProcessingContext        processingContext  = new ProcessingContext(this);
            List <IProcessingContext> processingContexts = new List <IProcessingContext>();

            processingContexts.Add(processingContext);
            _ProcessingContextCollection = new ProcessingContextCollection(processingContexts);
            return(_ProcessingContextCollection);
        }
Esempio n. 5
0
        protected InputModelParameters CreateBaseInputModelParameters(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, ISecurityModel securityModel)
        {
            InputModelParameters inputModelParameters = new InputModelParameters();

            inputModelParameters.QueryCollection  = _QueryCollection;
            inputModelParameters.HeaderCollection = _HeaderCollection;
            inputModelParameters.FormCollection   = _FormCollection;
            inputModelParameters.KraftGlobalConfigurationSettings = kraftGlobalConfigurationSettings;
            inputModelParameters.SecurityModel = securityModel;
            return(inputModelParameters);
        }
 public abstract IProcessingContextCollection GenerateProcessingContexts(string kraftRequestFlagsKey, ISecurityModel securityModel = null);
Esempio n. 7
0
        public override IProcessingContextCollection GenerateProcessingContexts(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            if (securityModel == null)
            {
                if (kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection.RequireAuthorization)
                {
                    securityModel = new SecurityModel(_HttpContext);
                }
                else
                {
                    securityModel = new SecurityModelMock(kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection);
                }
            }
            InputModelParameters inputModelParameters = CreateBaseInputModelParameters(kraftGlobalConfigurationSettings, securityModel);

            inputModelParameters = ExtendInputModelParameters(inputModelParameters);
            if (_RequestContentType == ESupportedContentTypes.JSON)
            {
                inputModelParameters.Data = GetBodyJson <Dictionary <string, object> >(_HttpContext.Request);
            }
            else
            {
                inputModelParameters.Data = _FormCollection;
            }
            inputModelParameters.FormCollection = _FormCollection;
            inputModelParameters.LoaderType     = GetLoaderType(kraftRequestFlagsKey);

            RouteData routeData = _HttpContext.GetRouteData();

            if (routeData != null)
            {
                string routeDataKey = routeData.DataTokens["key"]?.ToString()?.ToLower();
                if (!string.IsNullOrEmpty(routeDataKey))
                {
                    string signal           = routeData.Values[Constants.RouteSegmentConstants.RouteModuleSignalParameter]?.ToString();
                    bool   isWriteOperation = routeDataKey.Equals(Constants.RouteSegmentConstants.RouteDataTokenSignalWrite);
                    return(PrepareSignals(inputModelParameters.Module, signal, isWriteOperation, inputModelParameters));
                }
            }
            //Return only empty collection
            return(new ProcessingContextCollection(new List <IProcessingContext>()));
        }
        public override IProcessingContextCollection GenerateProcessingContexts(string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            List <InputModel>   inputModels   = new List <InputModel>();
            List <BatchRequest> batchRequests = new List <BatchRequest>();

            if (_RequestContentType == ESupportedContentTypes.JSON)
            {
                batchRequests = GetBodyJson <List <BatchRequest> >(_HttpContext.Request);
            }
            foreach (BatchRequest batchRequest in batchRequests)
            {
                InputModel inputModel = CreateInputModel(batchRequest, _KraftGlobalConfigurationSettings, kraftRequestFlagsKey, securityModel);
                inputModels.Add(inputModel);
            }
            _ProcessingContextCollection = new ProcessingContextCollection(CreateProcessingContexts(inputModels));
            return(_ProcessingContextCollection);
        }
Esempio n. 9
0
 public abstract IProcessingContextCollection GenerateProcessingContexts(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null);
Esempio n. 10
0
        public override IProcessingContextCollection GenerateProcessingContexts(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            IProcessingContext processingContext = new ProcessingContext(this);

            processingContext.InputModel = new InputModel(new InputModelParameters());
            List <IProcessingContext> processingContexts = new List <IProcessingContext>();

            processingContexts.Add(processingContext);
            _ProcessingContextCollection = new ProcessingContextCollection(processingContexts);
            return(_ProcessingContextCollection);
        }
Esempio n. 11
0
        public IProcessingContextCollection GenerateProcessingContexts(string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            InputModelParameters inputModelParameters = new InputModelParameters();

            inputModelParameters.KraftGlobalConfigurationSettings = _KraftGlobalConfigurationSettings;
            inputModelParameters.SecurityModel    = securityModel;
            inputModelParameters.Module           = _InputModel.Module;
            inputModelParameters.Nodeset          = _InputModel.Nodeset;
            inputModelParameters.Nodepath         = _InputModel.Nodepath;
            inputModelParameters.IsWriteOperation = _InputModel.IsWriteOperation;
            inputModelParameters.QueryCollection  = _InputModel.QueryCollection;
            inputModelParameters.Data             = _InputModel.Data;
            inputModelParameters.LoaderType       = ELoaderType.DataLoader;

            IProcessingContext processingContext = new ProcessingContext(this);

            processingContext.InputModel = new InputModel(inputModelParameters);
            List <IProcessingContext> processingContexts = new List <IProcessingContext>(1);

            processingContexts.Add(processingContext);
            return(new ProcessingContextCollection(processingContexts));
        }
Esempio n. 12
0
        public override IProcessingContextCollection GenerateProcessingContexts(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            if (securityModel == null)
            {
                if (kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection.RequireAuthorization)
                {
                    securityModel = new SecurityModel(_HttpContext);
                }
                else
                {
                    securityModel = new SecurityModelMock(kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection);
                }
            }
            InputModelParameters inputModelParameters = CreateBaseInputModelParameters(kraftGlobalConfigurationSettings, securityModel);

            inputModelParameters                = ExtendInputModelParameters(inputModelParameters);
            inputModelParameters.Data           = GetBodyJson <Dictionary <string, object> >(_HttpContext.Request);
            inputModelParameters.FormCollection = _FormCollection;
            inputModelParameters.LoaderType     = GetLoaderType(kraftRequestFlagsKey);
            if (inputModelParameters.LoaderType == ELoaderType.None)
            {
                inputModelParameters.LoaderType = ELoaderType.ViewLoader;
            }
            RouteData routeData = _HttpContext.GetRouteData();

            if (routeData != null)
            {
                inputModelParameters.BindingKey = routeData.Values[Constants.RouteSegmentConstants.RouteBindingkey] as string;
            }
            IProcessingContext processingContext = new ProcessingContext(this);

            processingContext.InputModel = new InputModel(inputModelParameters);
            List <IProcessingContext> processingContexts = new List <IProcessingContext>(1);

            processingContexts.Add(processingContext);
            _ProcessingContextCollection = new ProcessingContextCollection(processingContexts);
            return(_ProcessingContextCollection);
        }
        private InputModel CreateInputModel(BatchRequest request, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            if (securityModel == null)
            {
                if (kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection.RequireAuthorization)
                {
                    securityModel = new SecurityModel(_HttpContext);
                }
                else
                {
                    securityModel = new SecurityModelMock(kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection);
                }
            }
            InputModelParameters inputModelParameters = CreateBaseInputModelParameters(kraftGlobalConfigurationSettings, securityModel);
            //we expect the routing to be like this:
            //domain.com/startnode/<read|write>/module/nodeset/<nodepath>?lang=de
            string decodedUrl = WebUtility.UrlDecode(request.Url);
            string pattern    = @"(?:http:\/\/.+?\/|https:\/\/.+?\/|www.+?\/)(?:.+?)\/(read|write)*(?:\/)*(.+?)\/(.+?)($|\/.+?)($|\?.+)";
            Regex  regex      = new Regex(pattern);
            var    match      = regex.Match(decodedUrl);

            if (match.Groups[1] != null)
            {
                inputModelParameters.IsWriteOperation = match.Groups[1].Value == "write";
            }
            inputModelParameters.Module   = match.Groups[2].Value;
            inputModelParameters.Nodeset  = match.Groups[3].Value;
            inputModelParameters.Nodepath = string.IsNullOrEmpty(match.Groups[4].Value) ? string.Empty : match.Groups[4].Value.Substring(1);
            string paramsStr = string.IsNullOrEmpty(match.Groups[5].Value) ? string.Empty : match.Groups[5].Value.Substring(1);

            if (!string.IsNullOrEmpty(paramsStr))
            {
                string[] parameters = paramsStr.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var parameter in parameters)
                {
                    string[] kvp   = parameter.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    string   key   = kvp[0];
                    string   value = kvp[1];

                    if (key.Equals(kraftRequestFlagsKey, StringComparison.CurrentCultureIgnoreCase))
                    {
                        inputModelParameters.LoaderType = GetLoaderContent(value);
                    }
                    else
                    {
                        inputModelParameters.QueryCollection.Add(key, value);
                    }
                }
            }
            return(new InputModel(inputModelParameters));
        }
Esempio n. 14
0
        public override IProcessingContextCollection GenerateProcessingContexts(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            if (securityModel == null)
            {
                if (kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection.RequireAuthorization)
                {
                    securityModel = new SecurityModel(_HttpContext);
                }
                else
                {
                    securityModel = new SecurityModelMock(kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection);
                }
            }
            InputModelParameters inputModelParameters = CreateBaseInputModelParameters(kraftGlobalConfigurationSettings, securityModel);

            inputModelParameters                = ExtendInputModelParameters(inputModelParameters);
            inputModelParameters.Data           = GetBodyJson <Dictionary <string, object> >(_HttpContext.Request);
            inputModelParameters.FormCollection = _FormCollection;
            inputModelParameters.LoaderType     = GetLoaderType(kraftRequestFlagsKey);
            _ProcessingContextCollection        = new ProcessingContextCollection(CreateProcessingContexts(new List <InputModel> {
                new InputModel(inputModelParameters)
            }));
            return(_ProcessingContextCollection);
        }
Esempio n. 15
0
        internal static RequestDelegate ExecutionDelegate(IApplicationBuilder app, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings)
        {
            RequestDelegate requestDelegate = async httpContext =>
            {
                httpContext.Request.RouteValues.TryGetValue("p", out object val);
                ISecurityModel securityModel = null;
                const string   contentType   = "text/html; charset=UTF-8";
                int            statusCode    = 200;
                string         message       = string.Empty;
                if (kraftGlobalConfigurationSettings.GeneralSettings.ToolsSettings.RequestRecorder.IsEnabled)
                {
                    if (kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection.RequireAuthorization)
                    {
                        securityModel = new SecurityModel(httpContext);
                    }
                    else
                    {
                        securityModel = new SecurityModelMock(kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection);
                    }
                }
                switch (val)
                {
                case "0":
                {
                    if (kraftGlobalConfigurationSettings.GeneralSettings.ToolsSettings.RequestRecorder.IsEnabled)
                    {
                        if (securityModel.IsAuthenticated)
                        {
                            RecordersStoreImp recordersStoreImp = app.ApplicationServices.GetRequiredService <RecordersStoreImp>();
                            IRequestRecorder  requestRecorder   = recordersStoreImp.Get(securityModel.UserName);
                            if (requestRecorder != null)
                            {
                                requestRecorder.IsRunning = false;
                                message = "Recorder is paused.";
                            }
                            else
                            {
                                message = "The Recorder is not running.";
                            }
                        }
                        else
                        {
                            message = "Please login because the recorder can't be run for anonymous users.";
                        }
                    }
                    else
                    {
                        statusCode = (int)HttpStatusCode.NotFound;
                        message    = "Recorder is not configured and can't be started.";
                    }
                    break;
                }

                case "1":
                {
                    if (kraftGlobalConfigurationSettings.GeneralSettings.ToolsSettings.RequestRecorder.IsEnabled)
                    {
                        if (securityModel.IsAuthenticated)
                        {
                            Type              typeRecorder      = Type.GetType(kraftGlobalConfigurationSettings.GeneralSettings.ToolsSettings.RequestRecorder.ImplementationAsString, true);
                            IRequestRecorder  requestRecorder   = Activator.CreateInstance(typeRecorder) as IRequestRecorder;
                            RecordersStoreImp recordersStoreImp = app.ApplicationServices.GetRequiredService <RecordersStoreImp>();
                            recordersStoreImp.Set(requestRecorder, securityModel.UserName);
                            requestRecorder.IsRunning = true;
                            message = "Recorder is enabled";
                        }
                        else
                        {
                            statusCode = (int)HttpStatusCode.Unauthorized;
                            message    = "Please login because the recorder can't be run for anonymous users.";
                        }
                    }
                    else
                    {
                        statusCode = (int)HttpStatusCode.NotFound;
                        message    = "Recorder is not configured and can't be started.";
                    }
                    break;
                }

                case "2":
                {
                    if (kraftGlobalConfigurationSettings.GeneralSettings.ToolsSettings.RequestRecorder.IsEnabled)
                    {
                        if (securityModel.IsAuthenticated)
                        {
                            RecordersStoreImp recordersStoreImp = app.ApplicationServices.GetRequiredService <RecordersStoreImp>();
                            IRequestRecorder  requestRecorder   = recordersStoreImp.Get(securityModel.UserName);
                            if (requestRecorder != null)
                            {
                                message = requestRecorder.GetFinalResult()?.Result ?? string.Empty;
                                Type typeRecorder = Type.GetType(kraftGlobalConfigurationSettings.GeneralSettings.ToolsSettings.RequestRecorder.ImplementationAsString, true);
                                requestRecorder = Activator.CreateInstance(typeRecorder) as IRequestRecorder;
                                recordersStoreImp.Set(requestRecorder, securityModel.UserName);
                                httpContext.Response.Clear();
                                httpContext.Response.Headers.Add("Content-Length", message.Length.ToString());
                                httpContext.Response.Headers.Add("Content-Disposition", "attachment;filename=RecordedSession.json");
                            }
                            else
                            {
                                message = "The Recorder is not enabled and no data is available.";
                            }
                        }
                        else
                        {
                            statusCode = (int)HttpStatusCode.Unauthorized;
                            message    = "Please login because the recorder can't be run for anonymous users.";
                        }
                    }
                    else
                    {
                        statusCode = (int)HttpStatusCode.NotFound;
                        message    = "Recorder is not configured and can't be started.";
                    }
                    break;
                }

                case "3":
                {
                    if (kraftGlobalConfigurationSettings.GeneralSettings.ToolsSettings.RequestRecorder.IsEnabled)
                    {
                        if (securityModel.IsAuthenticated)
                        {
                            RecordersStoreImp recordersStoreImp = app.ApplicationServices.GetRequiredService <RecordersStoreImp>();
                            IRequestRecorder  requestRecorder   = recordersStoreImp.Get(securityModel.UserName);
                            if (requestRecorder != null)
                            {
                                recordersStoreImp.Remove(securityModel.UserName);
                                message = "Recorder is destroyed.";
                            }
                            else
                            {
                                message = "The Recorder is not running.";
                            }
                        }
                        else
                        {
                            statusCode = (int)HttpStatusCode.Unauthorized;
                            message    = "Please login because the recorder can't be used for anonymous users.";
                        }
                    }
                    else
                    {
                        statusCode = (int)HttpStatusCode.NotFound;
                        message    = "Recorder is not configured and can't be started.";
                    }
                    break;
                }

                default:
                    break;
                }
                httpContext.Response.StatusCode  = statusCode;
                httpContext.Response.ContentType = contentType;
                await httpContext.Response.WriteAsync(message);
            };

            return(requestDelegate);
        }
 public RegionsBoardService(ISecurityModel securityModel)
 {
     _securityModel = securityModel;
     _securityModel.SetSettingsFile(SecuritySettingsFile);
 }
Esempio n. 17
0
        public override IProcessingContextCollection GenerateProcessingContexts(string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            Dictionary <string, object> data        = ReconstructFromMultipart();
            List <InputModel>           inputModels = new List <InputModel>();

            if (securityModel == null)
            {
                if (_KraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection.RequireAuthorization)
                {
                    securityModel = new SecurityModel(_HttpContext);
                }
                else
                {
                    securityModel = new SecurityModelMock(_KraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection);
                }
            }
            InputModelParameters inputModelParameters = CreateBaseInputModelParameters(_KraftGlobalConfigurationSettings, securityModel);

            inputModelParameters             = ExtendInputModelParameters(inputModelParameters);
            inputModelParameters.LoaderType |= ELoaderType.DataLoader; //TODO Not override passed in flags

            inputModelParameters.Data = data;


            _ProcessingContextCollection = new ProcessingContextCollection(CreateProcessingContexts(new List <InputModel>()
            {
                new InputModel(inputModelParameters)
            }));
            return(_ProcessingContextCollection);
        }