public new bool Authorize(Permission permission, IContent content, LocalizedString message) {
            var authorizerMessage = new AuthorizerMessage {PermissionName = permission.Name};

            if (content != null)
            {
                authorizerMessage.ContentId = content.Id;
                authorizerMessage.ContentType = content.ContentItem.ContentType;
                authorizerMessage.ContentName = content.GetContentName();
            }

            return _performanceMonitor.PublishTimedAction(() =>
            {
                if (permission == StandardPermissions.AccessFrontEnd)
                {
                    return true;
                }

                return base.Authorize(permission, content, message);
            }, (r, t) => { 
                authorizerMessage.Duration = t.Duration;
                authorizerMessage.UserIsAuthorized = r;

                return authorizerMessage;
            }, TimelineCategories.Authorization, "Authorize", permission.Name).ActionResult;
        }
 public GraphDescriptor(string name, LocalizedString displayName, IEnumerable<string> contentTypes, Func<IGraphDescriptor, IGraphServices> servicesFactory)
 {
     Name = name;
     DisplayName = displayName;
     ContentTypes = contentTypes;
     _graphServicesField = new Lazy<IGraphServices>(() => servicesFactory(this));
 }
        public void OnActionExecuting(ActionExecutingContext filterContext) {
            var messages = Convert.ToString(filterContext.Controller.TempData[TempDataMessages]);
            if (String.IsNullOrEmpty(messages))
                return;

            var messageEntries = new List<NotifyEntry>();
            foreach (var line in messages.Split(new[] { System.Environment.NewLine + "-" + System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
                var delimiterIndex = line.IndexOf(':');
                if (delimiterIndex != -1) {
                    var type = (NotifyType)Enum.Parse(typeof(NotifyType), line.Substring(0, delimiterIndex));
                    var message = new LocalizedString(line.Substring(delimiterIndex + 1));
                    if (!messageEntries.Any(ne => ne.Message.TextHint == message.TextHint)) {
                        messageEntries.Add(new NotifyEntry {
                            Type = type,
                            Message = message
                        });
                    }
                }
                else {
                    var message = new LocalizedString(line.Substring(delimiterIndex + 1));
                    if (!messageEntries.Any(ne => ne.Message.TextHint == message.TextHint)) {
                        messageEntries.Add(new NotifyEntry {
                            Type = NotifyType.Information,
                            Message = message
                        });
                    }
                }
            }

            if (!messageEntries.Any())
                return;

            // Make the notifications available for the rest of the current request.
            filterContext.HttpContext.Items[TempDataMessages] = messageEntries;
        }
 public DescribeSortCriterionFor For(string category, LocalizedString name, LocalizedString description) {
     DescribeSortCriterionFor describeFor;
     if (!_describes.TryGetValue(category, out describeFor)) {
         describeFor = new DescribeSortCriterionFor(category, name, description);
         _describes[category] = describeFor;
     }
     return describeFor;
 }
 public BindingBuilder Add(PropertyInfo property, LocalizedString display, LocalizedString description) {
     _memberBindings.Add( new BindingItem{
         Property = property,
         DisplayName = display,
         Description = description
     });
     return this;
 }
Beispiel #6
0
 public DescribeFor For(string category, LocalizedString name) {
     DescribeFor describeFor;
     if (!_describes.TryGetValue(category, out describeFor)) {
         describeFor = new DescribeFor(category, name);
         _describes[category] = describeFor;
     }
     return describeFor;
 }
Beispiel #7
0
        public IHtmlString DateTime(DateTime DateTimeUtc, LocalizedString CustomFormat) {
            //using a LocalizedString forces the caller to use a localizable format

            if (CustomFormat == null || String.IsNullOrWhiteSpace(CustomFormat.Text)) {
                return new MvcHtmlString(_dateServices.ConvertToLocalString(DateTimeUtc, _dateTimeLocalization.LongDateTimeFormat, null));
            }

            return new MvcHtmlString(_dateServices.ConvertToLocalString(DateTimeUtc, CustomFormat.Text, null));
        }
Beispiel #8
0
        public IHtmlString DateTime(DateTime DateTimeUtc, LocalizedString CustomFormat) {
            //using a LocalizedString forces the caller to use a localizable format

            if (CustomFormat == null || String.IsNullOrWhiteSpace(CustomFormat.Text)) {
                return DateTime(DateTimeUtc, T("MMM d yyyy h:mm tt"));
            }

            return new MvcHtmlString(ConvertToDisplayTime(DateTimeUtc).ToString(CustomFormat.Text));
        }
        public virtual void DescribeGraph(string name, LocalizedString displayName, IEnumerable<string> contentTypes, Func<IGraphDescriptor, IGraphServices> graphServicesFactory)
        {
            if (String.IsNullOrEmpty(name) || displayName == null || String.IsNullOrEmpty(displayName.Text))
            {
                throw new ArgumentException("Associativy graphs should have their Name and DisplayName set properly.");
            }

            _descriptors.Add(new GraphDescriptor(name, displayName, contentTypes, graphServicesFactory));
        }
 public ImpulseDescriptor Impulse(string name, LocalizedString caption=null, LocalizedString description=null) {
     if (!Impulses.ContainsKey(name)) {
         Impulses[name] = new ImpulseDescriptor(name);
     }
     var impulse = Impulses[name];
     if (caption != null) impulse.Caption = caption;
     if (description != null) impulse.Description = description;
     return impulse;
 }
        public IHtmlString DateTime(DateTime DateTimeUtc, LocalizedString CustomFormat) {
            //using a LocalizedString forces the caller to use a localizable format

            if (CustomFormat == null || String.IsNullOrWhiteSpace(CustomFormat.Text)) {
                return DateTime(DateTimeUtc, _dateTimeLocalization.LongDateTimeFormat);
            }

            return new MvcHtmlString(ConvertToDisplayTime(DateTimeUtc).ToString(CustomFormat.Text, _cultureInfo.Value));
        }
        public static void Error(this Controller controller,
            Exception exception,
            LocalizedString localizedString,
            ILogger logger,
            INotifier notifier) {

            logger.Error(exception, localizedString.ToString());
            notifier.Error(localizedString);

            for (Exception innerException = exception; innerException != null ; innerException = innerException.InnerException) {
                notifier.Error(new LocalizedString(innerException.Message));
            }
        }
 public ElementDescriptor(Type elementType, string typeName, LocalizedString displayText, LocalizedString description, string category) {
     ElementType = elementType;
     TypeName = typeName;
     DisplayText = displayText;
     Description = description;
     Category = category;
     GetDrivers = Enumerable.Empty<IElementDriver>;
     CreatingDisplay = context => { };
     Displaying = context => {};
     Editor = context => { };
     UpdateEditor = context => { };
     StateBag = new Dictionary<string, object>();
 }
 public void SendMessage(FeedbackLevel level, LocalizedString message)
 {
     switch (level)
     {
         case FeedbackLevel.Info:
             Logger.Information(message.ToString());
             return;
         case FeedbackLevel.Warn:
             Logger.Information(message.ToString());
             return;
         case FeedbackLevel.Error:
             Logger.Information(message.ToString());
             return;
     }
 }
        public NavigationBuilder Add(LocalizedString caption, string position, Action<NavigationItemBuilder> itemBuilder, IEnumerable<string> classes = null) {
            var childBuilder = new NavigationItemBuilder();
            
            childBuilder.Caption(caption);
            childBuilder.Position(position);
            itemBuilder(childBuilder);
            Contained.AddRange(childBuilder.Build());

            if (classes != null) {
                foreach (var className in classes) 
                    childBuilder.AddClass(className);
            }

            return this;
        }
        public void OnResultExecuting(ResultExecutingContext filterContext) {
            var viewResult = filterContext.Result as ViewResultBase;

            // if it's not a view result, a redirect for example
            if (viewResult == null)
                return;

            var messages = Convert.ToString(viewResult.TempData[TempDataMessages]);
            if (string.IsNullOrEmpty(messages))
                return;// nothing to do, really

            var messageEntries = new List<NotifyEntry>();
            foreach (var line in messages.Split(new[] { System.Environment.NewLine + "-" + System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
                var delimiterIndex = line.IndexOf(':');
                if (delimiterIndex != -1) {
                    var type = (NotifyType)Enum.Parse(typeof(NotifyType), line.Substring(0, delimiterIndex));
                    var message = new LocalizedString(line.Substring(delimiterIndex + 1));
                    if (!messageEntries.Any(ne => ne.Message.TextHint == message.TextHint)) {
                        messageEntries.Add(new NotifyEntry {
                            Type = type,
                            Message = message
                        });
                    }
                }
                else {
                    var message = new LocalizedString(line.Substring(delimiterIndex + 1));
                    if (!messageEntries.Any(ne => ne.Message.TextHint == message.TextHint)) {
                        messageEntries.Add(new NotifyEntry {
                            Type = NotifyType.Information,
                            Message = message
                        });
                    }
                }
            }

            if (!messageEntries.Any())
                return;

            var messagesZone = _workContextAccessor.GetContext(filterContext).Layout.Zones["Messages"];
            foreach(var messageEntry in messageEntries)
                messagesZone = messagesZone.Add(_shapeFactory.Message(messageEntry));

            //todo: (heskew) probably need to keep duplicate messages from being pushed into the zone like the previous behavior
            //baseViewModel.Messages = baseViewModel.Messages == null ? messageEntries .Messages.Union(messageEntries).ToList();
            //baseViewModel.Zones.AddRenderPartial("content:before", "Messages", baseViewModel.Messages);
        }
Beispiel #17
0
        public bool Authorize(Permission permission, IContent content, LocalizedString message) {
            if (_authorizationService.TryCheckAccess(permission, _workContextAccessor.GetContext().CurrentUser, content))
                return true;

            if (message != null) {
                if (_workContextAccessor.GetContext().CurrentUser == null) {
                    _notifier.Error(T("{0}. Anonymous users do not have {1} permission.",
                                      message, permission.Name));
                }
                else {
                    _notifier.Error(T("{0}. Current user, {2}, does not have {1} permission.",
                                      message, permission.Name, _workContextAccessor.GetContext().CurrentUser.UserName));
                }
            }

            return false;
        }
        public bool Authorize(Permission permission, IContent content, LocalizedString message)
        {
            // creates a user for the active directory user if one doesn't already
            // exist. If one does already exists then that user from the database
            // is returned by the method.
            var user = CreateUserForActiveDirectoryUserIfNotExists(new ActiveDirectoryUser());

            // attempts to authorize the active directory user based on their roles
            // and the permissions that their associated roles have.
            if (_authorizationService.TryCheckAccess(permission, user, content))
                return true;

            if (message != null) {
                _notifier.Error(T("{0}. Current user, {2}, does not have {1} permission.",
                                    message, permission.Name, user.UserName));
            }

            return false;
        }
 public void GetNavigation(NavigationBuilder builder)
 {
     var menuItems = _adminMenuItemRepository.Table;
     foreach (var menuItem in menuItems) {
         var item = menuItem;
         if (string.IsNullOrWhiteSpace(item.ItemGroup)) {
             var label = new LocalizedString(HttpUtility.HtmlEncode(item.Text));
             builder.Add(label,
                 item.Position,
                 itemBuilder => itemBuilder.Add(label, "0", subItem => subItem.Url(item.Url)));
         }
         else {
             builder.Add(
                 new LocalizedString(HttpUtility.HtmlEncode(item.ItemGroup)),
                 item.GroupPosition,
                 menu => menu.Add(
                     new LocalizedString(HttpUtility.HtmlEncode(item.Text)),
                     item.Position,
                     itemBuilder => itemBuilder.Url(item.Url)));
         }
     }
 }
        public bool Authorize(Permission permission, IContent content, LocalizedString message)
        {
            // gets the current active directory user.
            var user = new ActiveDirectoryUser();

            // attempts to authorize the active directory user based on their roles
            // and the permissions that their associated roles have.
            if (_authorizationService.TryCheckAccess(permission, user, content))
            {
                if (!_attemptedToSaveUser)
                    CreateUserForActiveDirectoryUserIfNotExists(user);

                return true;
            }

            if (message != null) {
                _notifier.Error(T("{0}. Current user, {2}, does not have {1} permission.",
                                    message, permission.Name, user.UserName));
            }

            return false;
        }
        public DescribeFor Event(
            IAuditTrailEventProvider provider, 
            string eventName, 
            LocalizedString name, 
            LocalizedString description, 
            bool enableByDefault = false, 
            bool isMandatory = false) {

            _events.Add(new AuditTrailEventDescriptor {
                CategoryDescriptor = new AuditTrailCategoryDescriptor {
                    Category = Category,
                    Name = Name,
                    Events = Events
                }, 
                Event = EventNameExtensions.GetFullyQualifiedEventName(provider.GetType(), eventName), 
                Name = name, 
                Description = description, 
                IsEnabledByDefault = enableByDefault,
                IsMandatory = isMandatory
            });

            return this;
        }
 public DescribeMembersContext Member(string storageName, Type storageType, LocalizedString displayName, LocalizedString description) {
     _processMember(storageName, storageType, displayName, description);
     return this;
 }
 public DescribeMembersContext Member(string storageName, Type storageType, LocalizedString displayName) {
     return Member(storageName, storageType, displayName, null);
 }
 public NavigationBuilder Add(LocalizedString caption, IEnumerable<string> classes = null) {
     return Add(caption, null, x => { }, classes);
 }
 public NavigationBuilder Add(LocalizedString caption, Action<NavigationItemBuilder> itemBuilder, IEnumerable<string> classes = null) {
     return Add(caption, null, itemBuilder, classes);
 }
Beispiel #26
0
 public void AddModelError(string key, Orchard.Localization.LocalizedString errorMessage)
 {
     this.AddModelError(key, errorMessage);
 }
Beispiel #27
0
 void IUpdateModel.AddModelError(string key, Orchard.Localization.LocalizedString errorMessage)
 {
     ModelState.AddModelError(key, errorMessage.ToString());
 }
Beispiel #28
0
 public bool Authorize(Permission permission, LocalizedString message)
 {
     return Authorize(permission, null, message);
 }
Beispiel #29
0
        private void OutputException(TextWriter output, LocalizedString title, Exception exception) {
            // Display header
            output.WriteLine();
            output.WriteLine(T("{0}", title));

            // Push exceptions in a stack so we display from inner most to outer most
            var errors = new Stack<Exception>();
            for (var scan = exception; scan != null; scan = scan.InnerException) {
                errors.Push(scan);
            }

            // Display inner most exception details
            exception = errors.Peek();
            output.WriteLine(T("--------------------------------------------------------------------------------"));
            output.WriteLine();
            output.WriteLine(T("{0}", exception.Message));
            output.WriteLine();

            if (!((exception is OrchardException ||
                exception is OrchardCoreException) &&
                exception.InnerException == null)) {

                output.WriteLine(T("Exception Details: {0}: {1}", exception.GetType().FullName, exception.Message));
                output.WriteLine();
                output.WriteLine(T("Stack Trace:"));
                output.WriteLine();

                // Display exceptions from inner most to outer most
                foreach (var error in errors) {
                    output.WriteLine(T("[{0}: {1}]", error.GetType().Name, error.Message));
                    output.WriteLine(T("{0}", error.StackTrace));
                    output.WriteLine();
                }
            }

            // Display footer
            output.WriteLine("--------------------------------------------------------------------------------");
            output.WriteLine();
        }
 public bool Authorize(Permission permission, IContent content, LocalizedString message) {
     return true;
 }
 public OrchardSecurityException(LocalizedString message, Exception innerException) : base(message, innerException) { }
 public OrchardSecurityException(LocalizedString message) : base(message) { }