Exemplo n.º 1
0
        private static void AddEditablesDefinedOnProperties <T>(Type exploredType, ICollection <T> attributes) where T : IUniquelyNamed
        {
            foreach (PropertyInfo propertyOnItem in exploredType.GetProperties())
            {
                foreach (T editableOnProperty in propertyOnItem.GetCustomAttributes(typeof(T), false))
                {
                    editableOnProperty.Name = propertyOnItem.Name;

                    if (editableOnProperty is ISecurable)
                    {
#pragma warning disable 618
                        foreach (DetailAuthorizedRolesAttribute rolesAttribute in propertyOnItem.GetCustomAttributes(typeof(DetailAuthorizedRolesAttribute), false))
#pragma warning restore 618
                        {
                            ISecurable s = editableOnProperty as ISecurable;
                            s.AuthorizedRoles = rolesAttribute.Roles;
                        }
                    }

                    if (attributes.Contains(editableOnProperty))
                    {
                        continue;
                    }

                    attributes.Add(editableOnProperty);
                }
            }
        }
 // Methods
 protected override void AddAccessResultToCache(ISecurable entity, Account account, AccessRight accessRight, AccessResult accessResult, PropagationType propagationType)
 {
     if (accessRight.Name != "adoption:change")
     {
         base.AddAccessResultToCache(entity, account, accessRight, accessResult, propagationType);
     }
 }
Exemplo n.º 3
0
        protected override AccessResult GetAccessCore(ISecurable entity, Sitecore.Security.Accounts.Account oAccount, AccessRight oAccessRight)
        {
            #region VARIABLES

            AccessResult      oAccesResult;
            AccessExplanation oAccessExplanation;
            string            sAccessExplanationText;

            #endregion

            //Sitecore.Diagnostics.Log.Info(string.Format("GenSqlServerAuthorizationProvider.GetAccessCore, entity{0}", entity.GetUniqueId()), this);

            switch (oAccessRight.Name)
            {
            case "item:read":
            case "field:read":
            case "language:read":
            case "site:enter":
                oAccessExplanation = new AccessExplanation(string.Format("{0} acces right granted for entity {1}", oAccessRight.Name, entity.GetUniqueId()), new object[0]);
                oAccesResult       = new AccessResult(AccessPermission.Allow, oAccessExplanation);
                break;

            default:
                sAccessExplanationText = string.Format("Access right {0} is unavailable in this instance layer", oAccessRight.Name);
                oAccessExplanation     = new AccessExplanation(sAccessExplanationText, new object[0]);
                oAccesResult           = new AccessResult(AccessPermission.Deny, oAccessExplanation);
                Sitecore.Diagnostics.Log.Debug(sAccessExplanationText, this);
                break;
            }

            //Sitecore.Diagnostics.Log.Info(string.Format("GenSqlServerAuthorizationProvider.GetAccessCore, AccessResult:{0}", oAccesResult.Permission), this);

            return(oAccesResult);
        }
Exemplo n.º 4
0
        public SetSecureLevelGump(Mobile owner, ISecurable info)
            : base(50, 50)
        {
            m_Info = info;

            AddPage(0);

            AddBackground(0, 0, 220, 180, 5054);

            AddImageTiled(10, 10, 200, 20, 5124);
            AddImageTiled(10, 40, 200, 20, 5124);
            AddImageTiled(10, 70, 200, 100, 5124);

            AddAlphaRegion(10, 10, 200, 160);

            AddHtmlLocalized(10, 10, 200, 20, 1061276, 32767, false, false);               // <CENTER>SET ACCESS</CENTER>
            AddHtmlLocalized(10, 40, 100, 20, 1041474, 32767, false, false);               // Owner:

            AddLabel(110, 40, 1152, owner == null ? "" : owner.Name);

            AddButton(10, 70, GetFirstID(SecureLevel.Owner), 4007, 1, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 70, 150, 20, 1061277, GetColor(SecureLevel.Owner), false, false);                 // Owner Only

            AddButton(10, 90, GetFirstID(SecureLevel.CoOwners), 4007, 2, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 90, 150, 20, 1061278, GetColor(SecureLevel.CoOwners), false, false);                 // Co-Owners

            AddButton(10, 110, GetFirstID(SecureLevel.Friends), 4007, 3, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 110, 150, 20, 1061279, GetColor(SecureLevel.Friends), false, false);                 // Friends

            AddButton(10, 150, GetFirstID(SecureLevel.Anyone), 4007, 4, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 150, 150, 20, 1061626, GetColor(SecureLevel.Anyone), false, false);                 // Anyone
        }
        public SetSecureLevelGump( Mobile owner, ISecurable info )
            : base(50, 50)
        {
            m_Info = info;

            AddPage( 0 );

            AddBackground( 0, 0, 220, 160, 5054 );

            AddImageTiled( 10, 10, 200, 20, 5124 );
            AddImageTiled( 10, 40, 200, 20, 5124 );
            AddImageTiled( 10, 70, 200, 80, 5124 );

            AddAlphaRegion( 10, 10, 200, 140 );

            AddHtmlLocalized( 10, 10, 200, 20, 1061276, 32767, false, false ); // <CENTER>SET ACCESS</CENTER>
            AddHtmlLocalized( 10, 40, 100, 20, 1041474, 32767, false, false ); // Owner:

            AddLabel( 110, 40, 1152, owner == null ? "" : owner.Name );

            AddButton( 10, 70, GetFirstID( SecureLevel.Owner ), 4007, 1, GumpButtonType.Reply, 0 );
            AddHtmlLocalized( 45, 70, 150, 20, 1061277, GetColor( SecureLevel.Owner ), false, false ); // Owner Only

            AddButton( 10, 90, GetFirstID( SecureLevel.CoOwners ), 4007, 2, GumpButtonType.Reply, 0 );
            AddHtmlLocalized( 45, 90, 150, 20, 1061278, GetColor( SecureLevel.CoOwners ), false, false ); // Co-Owners

            AddButton( 10, 110, GetFirstID( SecureLevel.Friends ), 4007, 3, GumpButtonType.Reply, 0 );
            AddHtmlLocalized( 45, 110, 150, 20, 1061279, GetColor( SecureLevel.Friends ), false, false ); // Friends

            AddButton( 10, 130, GetFirstID( SecureLevel.Anyone ), 4007, 4, GumpButtonType.Reply, 0 );
            AddHtmlLocalized( 45, 130, 150, 20, 1061626, GetColor( SecureLevel.Anyone ), false, false ); // Anyone
        }
Exemplo n.º 6
0
        /// <summary>
        /// Define a user actor for a <see cref="ISecurable">securable</see>
        /// </summary>
        /// <param name="securable"><see cref="ISecurable"/> to secure</param>
        /// <returns>The <see cref="UserSecurityActor"/></returns>
        public static UserSecurityActor User(this ISecurable securable)
        {
            var actor = new UserSecurityActor(Configure.Instance.Container.Get <ICanResolvePrincipal>());

            securable.AddActor(actor);
            return(actor);
        }
Exemplo n.º 7
0
        void Application_BeginRequest(object sender, EventArgs e)
        {
            string securableName = GetSecurableNameForCurrentRequestPath();

            if (String.IsNullOrEmpty(securableName))
            {
                return;
            }

            ISecurable relevantSecurable = Placeholder.GetSecurable(securableName);

            if (relevantSecurable == null)
            {
                return;
            }

            if (relevantSecurable.AllowAnonymous)
            {
                return;
            }

            if (!ConnectGadgetCache.IsAuthenticated)
            {
                // Redirect to the login page with the current URL as the return URL
                Response.Redirect(LOGIN_PAGE_URL + "?ReturnUrl=" + HttpUtility.UrlEncode(Request.Url.ToString()), true);
            }

            if (!relevantSecurable.IsAuthorized(ConnectGadgetCache.CurrentUser))
            {
                throw (new UnauthorizedAccessException("You do not have access to this resource"));
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Define a user actor for a <see cref="ISecurable">securable</see>
        /// </summary>
        /// <param name="securable"><see cref="ISecurable"/> to secure</param>
        /// <returns>The <see cref="UserSecurityActor"/></returns>
        public static UserSecurityActor User(this ISecurable securable)
        {
            var actor = new UserSecurityActor();

            securable.AddActor(actor);
            return(actor);
        }
Exemplo n.º 9
0
        internal SecurityEditor(ISecurable securable, string name, IEnumerable <AccessEntry> accessEntries)
        {
            List <SiAccess> accesses;

            _securable = securable;
            _name      = name;

            accesses = new List <SiAccess>();

            foreach (var entry in accessEntries)
            {
                if (entry.Mask != 0)
                {
                    accesses.Add(new SiAccess()
                    {
                        Guid  = IntPtr.Zero,
                        Mask  = entry.Mask,
                        Flags = (entry.General ? SiAccessFlags.General : 0) | (entry.Specific ? SiAccessFlags.Specific : 0),
                        Name  = this.AllocateStringFromPool(entry.Name)
                    });
                }
            }

            _accessRights     = this.AllocateStructArray <SiAccess>(accesses.ToArray());
            _accessRightCount = accesses.Count;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Define a user actor for a <see cref="ISecurable">securable</see>
        /// </summary>
        /// <param name="securable"><see cref="ISecurable"/> to secure</param>
        /// <param name="principalResolver">Resolves the <see cref="IPrincipal" /></param>
        /// <returns>The <see cref="ISecurable"/> chain</returns>
        public static UserSecurityActor UserFrom(this ISecurable securable, ICanResolvePrincipal principalResolver)
        {
            var actor = new UserSecurityActor(principalResolver);

            securable.AddActor(actor);
            return(actor);
        }
Exemplo n.º 11
0
        private static bool IsAccessibleToEveryone(ISecurable content)
        {
            var visitorPrinciple = new System.Security.Principal.GenericPrincipal(
                new System.Security.Principal.GenericIdentity("visitor"),
                new[] { "Everyone" });

            return(content.GetSecurityDescriptor().HasAccess(visitorPrinciple, AccessLevel.Read));
        }
Exemplo n.º 12
0
        public static string ToLocalString(this ISecurable securable, DateTime date, bool includeGmt)
        {
            TimeZoneInfo timeZoneInfo;
            var          local = ToLocal(securable, date, out timeZoneInfo);

            var fecha = string.Format("{0} {1}", local.ToShortDateString(), local.ToShortTimeString());

            return(includeGmt && timeZoneInfo != null?string.Concat(fecha, string.Format(" ({0})", timeZoneInfo.DisplayName)) : fecha);
        }
        protected override void AddAccessResultToCache(ISecurable entity, Account account, AccessRight accessRight, AccessResult accessResult, PropagationType propagationType)
        {
            if (accessRight.Name == BucketRights.MakeABucket)
            {
                return;
            }

            base.AddAccessResultToCache(entity, account, accessRight, accessResult, propagationType);
        }
        protected override void AddAccessResultToCache(ISecurable entity, Account account, AccessRight accessRight, AccessResult accessResult, PropagationType propagationType)
        {
            if (accessRight.Name == BucketRights.MakeABucket)
            {
                return;
            }

            base.AddAccessResultToCache(entity, account, accessRight, accessResult, propagationType);
        }
        public FakeAuthorizationProviderTest()
        {
            this.provider = new FakeAuthorizationProvider();

            this.localProvider = Substitute.For <AuthorizationProvider>();
            this.helper        = Substitute.For <ItemAuthorizationHelper>();

            this.entity = Substitute.For <ISecurable>();
            this.item   = ItemHelper.CreateInstance();
            this.rules  = new AccessRuleCollection();
        }
Exemplo n.º 16
0
        public override AccessRuleCollection GetAccessRules(ISecurable entity)
        {
            if (this.IsLocalProviderSet())
            {
                return(this.LocalProvider.Value.GetAccessRules(entity));
            }

            var item = entity as Item;

            return(item != null?this.itemHelper.GetAccessRules(item) : new AccessRuleCollection());
        }
 protected override void AddAccessResultToCache(ISecurable entity, Account account, AccessRight accessRight, AccessResult accessResult, PropagationType propagationType)
 {
     //
     //Do not cache the access result because the result depends
     //on the value that is currently set on the item.
     if (accessRight.Name == BucketRights.AddComments)
     {
         return;
     }
     base.AddAccessResultToCache(entity, account, accessRight, accessResult, propagationType);
 }
    public FakeAuthorizationProviderTest()
    {
      this.provider = new FakeAuthorizationProvider();

      this.localProvider = Substitute.For<AuthorizationProvider>();
      this.helper = Substitute.For<ItemAuthorizationHelper>();

      this.entity = Substitute.For<ISecurable>();
      this.item = ItemHelper.CreateInstance();
      this.rules = new AccessRuleCollection();
    }
        public FakeAuthorizationProviderTest()
        {
            this.localProvider = Substitute.For <AuthorizationProvider>();
            this.helper        = Substitute.For <ItemAuthorizationHelper>(
                Substitute.For <BaseAccessRightManager>(),
                Substitute.For <BaseRolesInRolesManager>(),
                Substitute.For <BaseItemManager>());
            this.provider = new FakeAuthorizationProvider(helper);

            this.entity = Substitute.For <ISecurable>();
            this.item   = ItemHelper.CreateInstance();
            this.rules  = new AccessRuleCollection();
        }
        protected override AccessResult GetAccessCore(ISecurable oEntity, Account oAccount, AccessRight oAccessRight)
        {
            Item oItem;
            GenAuthorizationHelper oGenAuthorizationHelper;
            AccessResult           oItemAccessResult;
            AccessExplanation      oItemAccessExplanation;
            string sAccessExplanationText;

            oItemAccessResult = null;
            //Validates that internal tasks have access to sitecore content
            //Specially required for sitecore events Sitecore:Item:Write (Sitecore Cache Update Event)
            //This is needed because we bypass Sitecore Authorization with the Custom Authorization process for GFWM
            if (Sitecore.Context.IsBackgroundThread)
            {
                oItemAccessExplanation = new AccessExplanation(string.Format("{0} access right granted for Internal Task", oAccessRight.Name), new object[0]);

                oItemAccessResult = new AccessResult(AccessPermission.Allow, oItemAccessExplanation);
            }
            else
            {
                switch (oAccessRight.Name)
                {
                case "item:read":
                    oGenAuthorizationHelper = ItemHelper as GenAuthorizationHelper;
                    if (oGenAuthorizationHelper != null)
                    {
                        oItem             = oEntity as Item;
                        oItemAccessResult = oGenAuthorizationHelper.GetAccess(oItem, oAccount, oAccessRight);
                    }

                    break;

                case "field:read":
                case "language:read":
                case "site:enter":
                    oItemAccessExplanation = new AccessExplanation(string.Format("{0} acces right granted", oAccessRight.Name), new object[0]);
                    oItemAccessResult      = new AccessResult(AccessPermission.Allow, oItemAccessExplanation);
                    break;

                default:
                    sAccessExplanationText = string.Format("Access right {0} is unavailable in the web layer", oAccessRight.Name);
                    oItemAccessExplanation = new AccessExplanation(sAccessExplanationText, new object[0]);
                    oItemAccessResult      = new AccessResult(AccessPermission.Deny, oItemAccessExplanation);
                    Sitecore.Diagnostics.Log.Debug(sAccessExplanationText, this);
                    break;
                }
            }

            return(oItemAccessResult);
        }
    protected override AccessResult GetAccessCore(ISecurable entity, Account account, AccessRight accessRight)
    {
      var uniqueId = entity.GetUniqueId();

      if (string.IsNullOrEmpty(uniqueId))
      {
        return this.GetDefaultAccessResult();
      }

      var id = uniqueId.Substring(uniqueId.IndexOf("{", StringComparison.Ordinal), uniqueId.IndexOf("}", StringComparison.Ordinal) - uniqueId.IndexOf("{", StringComparison.Ordinal) + 1);
      var itemId = ID.Parse(id);
      var item = this.DataStorage.GetFakeItem(itemId);

      return this.GetPermission(item.Access, accessRight);
    }
Exemplo n.º 22
0
        public SetSecureLevelGump(Mobile owner, ISecurable info, BaseHouse house) : base(50, 50)
        {
            m_Info = info;

            AddPage(0);

            //TEST: GUILD
            //int offset = ( Guild.NewGuildSystem )? 20 : 0;
            int offset = 0;

            AddBackground(0, 0, 220, 160 + offset, 5054);

            AddImageTiled(10, 10, 200, 20, 5124);
            AddImageTiled(10, 40, 200, 20, 5124);
            AddImageTiled(10, 70, 200, 80 + offset, 5124);

            AddAlphaRegion(10, 10, 200, 140);

            AddHtmlLocalized(10, 10, 200, 20, 1061276, 32767, false, false);               // <CENTER>SET ACCESS</CENTER>
            AddHtmlLocalized(10, 40, 100, 20, 1041474, 32767, false, false);               // Owner:

            AddLabel(110, 40, 1152, owner == null ? "" : owner.Name);

            AddButton(10, 70, GetFirstID(SecureLevel.Owner), 4007, 1, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 70, 150, 20, 1061277, GetColor(SecureLevel.Owner), false, false); // Owner Only

            AddButton(10, 90, GetFirstID(SecureLevel.CoOwners), 4007, 2, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 90, 150, 20, 1061278, GetColor(SecureLevel.CoOwners), false, false); // Co-Owners

            AddButton(10, 110, GetFirstID(SecureLevel.Friends), 4007, 3, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 110, 150, 20, 1061279, GetColor(SecureLevel.Friends), false, false); // Friends

            Mobile houseOwner = house.Owner;

            //TEST: GUILD

            /*
             * if (Guild.NewGuildSystem && house != null && houseOwner != null && houseOwner.Guild != null && ((Guild)houseOwner.Guild).Leader == houseOwner)	//Only the actual House owner AND guild master can set guild secures
             * {
             *  AddButton(10, 130, GetFirstID(SecureLevel.Guild), 4007, 5, GumpButtonType.Reply, 0);
             *  AddHtmlLocalized(45, 130, 150, 20, 1063455, GetColor(SecureLevel.Guild), false, false); // Guild Members
             * }
             */

            AddButton(10, 130 + offset, GetFirstID(SecureLevel.Anyone), 4007, 4, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 130 + offset, 150, 20, 1061626, GetColor(SecureLevel.Anyone), false, false);                 // Anyone
        }
Exemplo n.º 23
0
        public SetSecureLevelGump(Mobile from, ISecurable info, BaseHouse house)
            : base(50, 50)
        {
            m_Info = info;

            Mobile owner = house.Owner;

            if (owner == null)
            {
                return;
            }

            AddPage(0);

            int offset = (Guild.NewGuildSystem) ? 20 : 0;

            AddBackground(0, 0, 220, 160 + offset, 5054);

            AddImageTiled(10, 10, 200, 20, 5124);
            AddImageTiled(10, 40, 200, 20, 5124);
            AddImageTiled(10, 70, 200, 80 + offset, 5124);

            AddAlphaRegion(10, 10, 200, 140 + offset);

            AddHtmlLocalized(10, 10, 200, 20, 1061276, 32767, false, false); // <CENTER>SET ACCESS</CENTER>
            AddHtmlLocalized(10, 40, 100, 20, 1041474, 32767, false, false); // Owner:

            AddLabel(110, 40, 1152, owner == null ? "" : owner.Name);

            AddButton(10, 70, GetFirstID(SecureLevel.Owner), 4007, 1, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 70, 150, 20, 1061277, GetColor(SecureLevel.Owner), false, false); // Owner Only

            AddButton(10, 90, GetFirstID(SecureLevel.CoOwners), 4007, 2, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 90, 150, 20, 1061278, GetColor(SecureLevel.CoOwners), false, false); // Co-Owners

            AddButton(10, 110, GetFirstID(SecureLevel.Friends), 4007, 3, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 110, 150, 20, 1061279, GetColor(SecureLevel.Friends), false, false); // Friends

            if (from != null && (Guild.NewGuildSystem && owner == from && from.Guild != null && ((PlayerMobile)from).GuildRank.Rank >= 1))
            {
                AddButton(10, 130, GetFirstID(SecureLevel.Guild), 4007, 5, GumpButtonType.Reply, 0);
                AddHtmlLocalized(45, 130, 150, 20, 1063455, GetColor(SecureLevel.Guild), false, false); // Guild Members
            }

            AddButton(10, 130 + offset, GetFirstID(SecureLevel.Anyone), 4007, 4, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 130 + offset, 150, 20, 1061626, GetColor(SecureLevel.Anyone), false, false); // Anyone
        }
Exemplo n.º 24
0
        public void SetCurrentValues(TipoDocumento tipoDocumento)
        {
            ISecurable ent = null;

            if (Coche.Get() != -1)
            {
                ent = DAOFactory.CocheDAO.FindById(Coche.Get());
            }
            else if (Empleado.Get() != -1)
            {
                ent = DAOFactory.EmpleadoDAO.FindById(Empleado.Get());
            }
            else if (Equipo.Get() != -1)
            {
                ent = DAOFactory.EquipoDAO.FindById(Equipo.Get());
            }
            else if (Transportista.Get() != -1)
            {
                ent = DAOFactory.TransportistaDAO.FindById(Transportista.Get());
            }

            var doc = new Documento();

            if (ent != null)
            {
                doc.Empresa = ent.Empresa;
                doc.Linea   = ent.Linea;
            }
            if (tipoDocumento.AplicarATransportista && Transportista.Get() != -1)
            {
                doc.Transportista = DAOFactory.TransportistaDAO.FindById(Transportista.Get());
            }
            if (tipoDocumento.AplicarAEquipo && Equipo.Get() != -1)
            {
                doc.Equipo = DAOFactory.EquipoDAO.FindById(Equipo.Get());
            }
            if (tipoDocumento.AplicarAEmpleado && Empleado.Get() != -1)
            {
                doc.Empleado = DAOFactory.EmpleadoDAO.FindById(Empleado.Get());
            }
            if (tipoDocumento.AplicarAVehiculo && Coche.Get() != -1)
            {
                doc.Vehiculo = DAOFactory.CocheDAO.FindById(Coche.Get());
            }

            Presenter.SetValores(doc);
        }
Exemplo n.º 25
0
        public override void SetAccessRules(ISecurable entity, AccessRuleCollection rules)
        {
            Assert.ArgumentNotNull(entity, "entity");
            Assert.ArgumentNotNull(rules, "rules");

            if (this.IsLocalProviderSet())
            {
                this.LocalProvider.Value.SetAccessRules(entity, rules);
            }
            else
            {
                var item = entity as Item;
                if (item != null)
                {
                    this.itemHelper.SetAccessRules(item, rules);
                }
            }
        }
Exemplo n.º 26
0
        public SetSecureLevelGump(Mobile owner, ISecurable info, BaseHouse house) : base(50, 50)
        {
            m_Info = info;

            AddPage(0);

            var offset = Guild.NewGuildSystem ? 20 : 0;

            AddBackground(0, 0, 220, 160 + offset, 5054);

            AddImageTiled(10, 10, 200, 20, 5124);
            AddImageTiled(10, 40, 200, 20, 5124);
            AddImageTiled(10, 70, 200, 80 + offset, 5124);

            AddAlphaRegion(10, 10, 200, 140);

            AddHtmlLocalized(10, 10, 200, 20, 1061276, 32767); // <CENTER>SET ACCESS</CENTER>
            AddHtmlLocalized(10, 40, 100, 20, 1041474, 32767); // Owner:

            AddLabel(110, 40, 1152, owner == null ? "" : owner.Name);

            AddButton(10, 70, GetFirstID(SecureLevel.Owner), 4007, 1);
            AddHtmlLocalized(45, 70, 150, 20, 1061277, GetColor(SecureLevel.Owner)); // Owner Only

            AddButton(10, 90, GetFirstID(SecureLevel.CoOwners), 4007, 2);
            AddHtmlLocalized(45, 90, 150, 20, 1061278, GetColor(SecureLevel.CoOwners)); // Co-Owners

            AddButton(10, 110, GetFirstID(SecureLevel.Friends), 4007, 3);
            AddHtmlLocalized(45, 110, 150, 20, 1061279, GetColor(SecureLevel.Friends)); // Friends

            var houseOwner = house.Owner;

            if (Guild.NewGuildSystem && houseOwner?.Guild != null &&
                ((Guild)houseOwner.Guild).Leader == houseOwner
                ) // Only the actual House owner AND guild master can set guild secures
            {
                AddButton(10, 130, GetFirstID(SecureLevel.Guild), 4007, 5);
                AddHtmlLocalized(45, 130, 150, 20, 1063455, GetColor(SecureLevel.Guild)); // Guild Members
            }

            AddButton(10, 130 + offset, GetFirstID(SecureLevel.Anyone), 4007, 4);
            AddHtmlLocalized(45, 130 + offset, 150, 20, 1061626, GetColor(SecureLevel.Anyone)); // Anyone
        }
Exemplo n.º 27
0
        public static void WriteToRegistry(string registryKey, string valueName, ISecurable value, RegKind regAs)
        {
            // the value should already be encrypted...
            RegistryValueKind kind;
            object            writeThis = null;

            if (regAs == RegKind.String)
            {
                writeThis = Encoding.ASCII.GetString(value.GetBytes());
                kind      = RegistryValueKind.String;
            }
            else
            {
                writeThis = value.GetBytes();
                kind      = RegistryValueKind.Binary;
            }

            Registry.SetValue(registryKey, valueName, writeThis, kind);
        }
Exemplo n.º 28
0
        public ISecurable DecryptContent(ISecurable pStr)
        {
            byte[] sBytes  = pStr.GetBytes();
            byte[] content = StringSecurer.FromBase64BytesToBytes(sBytes);
            var    cms     = new EnvelopedCms();

            cms.Decode(content);
            try
            {
                cms.Decrypt();
            }
            catch (Exception ex)
            {
                throw new ProtectedStringDecryptionException(ex);
            }
            var pts = StringSecurer.FromBase64Bytes(cms.ContentInfo.Content);

            return(pts);
        }
Exemplo n.º 29
0
        public static ISecurable ReadFromRegistry(string registryKey, string valueName)
        {
            object     regData = Registry.GetValue(registryKey, valueName, null);
            ISecurable isec    = null;

            if (regData is byte[] bytes)
            {
                isec = StringSecurer.FromBase64Bytes(bytes);
            }
            else if (regData is string strData)
            {
                isec = StringSecurer.FromBase64String(strData);
            }
            else
            {
                throw new InvalidCastException("The resulting registry data cannot be converted to a Securable object.");
            }

            return(isec); // the output is still encrypted...
        }
Exemplo n.º 30
0
        public SetSecureLevelGump(Mobile owner, ISecurable info, BaseHouse house)
            : base(50, 50)
        {
            this.m_Info = info;

            this.AddPage(0);

            int offset = (Guild.NewGuildSystem) ? 20 : 0;

            this.AddBackground(0, 0, 220, 160 + offset, 5054);

            this.AddImageTiled(10, 10, 200, 20, 5124);
            this.AddImageTiled(10, 40, 200, 20, 5124);
            this.AddImageTiled(10, 70, 200, 80 + offset, 5124);

            this.AddAlphaRegion(10, 10, 200, 140);

            this.AddHtmlLocalized(10, 10, 200, 20, 1061276, 32767, false, false); // <CENTER>SET ACCESS</CENTER>
            this.AddHtmlLocalized(10, 40, 100, 20, 1041474, 32767, false, false); // Owner:

            this.AddLabel(110, 40, 1152, owner == null ? "" : owner.Name);

            this.AddButton(10, 70, this.GetFirstID(SecureLevel.Owner), 4007, 1, GumpButtonType.Reply, 0);
            this.AddHtmlLocalized(45, 70, 150, 20, 1061277, this.GetColor(SecureLevel.Owner), false, false); // Owner Only

            this.AddButton(10, 90, this.GetFirstID(SecureLevel.CoOwners), 4007, 2, GumpButtonType.Reply, 0);
            this.AddHtmlLocalized(45, 90, 150, 20, 1061278, this.GetColor(SecureLevel.CoOwners), false, false); // Co-Owners

            this.AddButton(10, 110, this.GetFirstID(SecureLevel.Friends), 4007, 3, GumpButtonType.Reply, 0);
            this.AddHtmlLocalized(45, 110, 150, 20, 1061279, this.GetColor(SecureLevel.Friends), false, false); // Friends

            Mobile houseOwner = house.Owner;
            if (Guild.NewGuildSystem && house != null && houseOwner != null && houseOwner.Guild != null && ((Guild)houseOwner.Guild).Leader == houseOwner)	//Only the actual House owner AND guild master can set guild secures
            {
                this.AddButton(10, 130, this.GetFirstID(SecureLevel.Guild), 4007, 5, GumpButtonType.Reply, 0);
                this.AddHtmlLocalized(45, 130, 150, 20, 1063455, this.GetColor(SecureLevel.Guild), false, false); // Guild Members
            }

            this.AddButton(10, 130 + offset, this.GetFirstID(SecureLevel.Anyone), 4007, 4, GumpButtonType.Reply, 0);
            this.AddHtmlLocalized(45, 130 + offset, 150, 20, 1061626, this.GetColor(SecureLevel.Anyone), false, false); // Anyone
        }
        public SetSecureLevelGump(Mobile owner, ISecurable info, BaseHouse house) : base(50, 50)
        {
            m_Info = info;

            AddPage(0);

            int offset = (Guild.NewGuildSystem)? 20 : 0;

            AddBackground(0, 0, 220, 160 + offset, 9270);

            //AddImageTiled( 10, 10, 200, 20, 5124 );
            //AddImageTiled( 10, 40, 200, 20, 5124 );
            //AddImageTiled( 10, 70, 200, 80 + offset, 5124 );

            //AddAlphaRegion( 10, 10, 200, 140 );

            AddHtml(10, 10, 200, 20, "<CENTER>ACESSOS</CENTER>", false, false); // <CENTER>SET ACCESS</CENTER>
            AddHtml(10, 40, 100, 20, "Dono:", false, false);                    // Owner:

            AddLabel(110, 40, 1152, owner == null ? "" : owner.Name);

            AddButton(10, 70, GetFirstID(SecureLevel.Owner), 4007, 1, GumpButtonType.Reply, 0);
            AddHtml(45, 70, 150, 20, "Apenas o Dono", false, false); // Owner Only

            AddButton(10, 90, GetFirstID(SecureLevel.CoOwners), 4007, 2, GumpButtonType.Reply, 0);
            AddHtml(45, 90, 150, 20, "Sócios", false, false); // Co-Owners

            AddButton(10, 110, GetFirstID(SecureLevel.Friends), 4007, 3, GumpButtonType.Reply, 0);
            AddHtml(45, 110, 150, 20, "Amigos", false, false); // Friends

            Mobile houseOwner = house.Owner;

            if (Guild.NewGuildSystem && house != null && houseOwner != null && houseOwner.Guild != null && ((Guild)houseOwner.Guild).Leader == houseOwner)              //Only the actual House owner AND guild master can set guild secures
            {
                AddButton(10, 130, GetFirstID(SecureLevel.Guild), 4007, 5, GumpButtonType.Reply, 0);
                AddHtml(45, 130, 150, 20, "Membros da Guilda", false, false); // Guild Members
            }

            AddButton(10, 130 + offset, GetFirstID(SecureLevel.Anyone), 4007, 4, GumpButtonType.Reply, 0);
            AddHtml(45, 130 + offset, 150, 20, "Qualquer pessoa", false, false); // Anyone
        }
        public SetSecureLevelGump( Mobile owner, ISecurable info, BaseHouse house )
            : base(50, 50)
        {
            m_Info = info;

            AddPage( 0 );

            int offset = ( Guild.NewGuildSystem )? 20 : 0;

            AddBackground(0, 0, 220, 160 + offset, 9270);

            //AddImageTiled( 10, 10, 200, 20, 5124 );
            //AddImageTiled( 10, 40, 200, 20, 5124 );
            //AddImageTiled( 10, 70, 200, 80 + offset, 5124 );

            //AddAlphaRegion( 10, 10, 200, 140 );

            AddHtml(10, 10, 200, 20, "<CENTER>ACESSOS</CENTER>",false, false); // <CENTER>SET ACCESS</CENTER>
            AddHtml(10, 40, 100, 20, "Dono:", false, false); // Owner:

            AddLabel( 110, 40, 1152, owner == null ? "" : owner.Name );

            AddButton( 10, 70, GetFirstID( SecureLevel.Owner ), 4007, 1, GumpButtonType.Reply, 0 );
            AddHtml(45, 70, 150, 20, "Apenas o Dono", false, false); // Owner Only

            AddButton( 10, 90, GetFirstID( SecureLevel.CoOwners ), 4007, 2, GumpButtonType.Reply, 0 );
            AddHtml(45, 90, 150, 20, "Sócios", false, false); // Co-Owners

            AddButton( 10, 110, GetFirstID( SecureLevel.Friends ), 4007, 3, GumpButtonType.Reply, 0 );
            AddHtml(45, 110, 150, 20, "Amigos", false, false); // Friends

            Mobile houseOwner = house.Owner;
            if( Guild.NewGuildSystem && house != null && houseOwner != null && houseOwner.Guild != null && ((Guild)houseOwner.Guild).Leader == houseOwner )	//Only the actual House owner AND guild master can set guild secures
            {
                AddButton( 10, 130, GetFirstID( SecureLevel.Guild ), 4007, 5, GumpButtonType.Reply, 0 );
                AddHtml(45, 130, 150, 20, "Membros da Guilda", false, false); // Guild Members
            }

            AddButton( 10, 130 + offset, GetFirstID( SecureLevel.Anyone ), 4007, 4, GumpButtonType.Reply, 0 );
            AddHtml(45, 130 + offset, 150, 20, "Qualquer pessoa", false, false); // Anyone
        }
Exemplo n.º 33
0
        public ISecurable EncryptString(ISecurable pts)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("SecurityManager");
            }

            if (this.Certificate == null)
            {
                throw new InvalidOperationException("The encryption certificate is still not set!  Use the 'SetCertificate' method first.");
            }

            var cinfo     = new ContentInfo(pts.GetBytes());
            var cms       = new EnvelopedCms(cinfo);
            var recipient = new CmsRecipient(this.Certificate);

            cms.Encrypt(recipient);
            var base64 = StringSecurer.ToBase64Securable(cms.Encode());

            return(base64);
        }
Exemplo n.º 34
0
        // Note! This broke with CMS 8, but since we're not using the languageselector
        //       from code, we just ignore it
        //public virtual T Get<T>(ContentReference contentLink) where T : IContentData
        //{
        //    // CMS 8
        //    // LoaderOptions options  = new LoaderOptions();
        //    // options.Add(new LanguageLoaderOption() {FallbackBehaviour = LanguageBehaviour.Fallback});
        //    return this.Get<T>(contentLink, (LanguageSelector)LanguageSelector.AutoDetect(true));
        //}
        public virtual T Get <T>(ContentReference contentLink) where T : IContentData
        {
            T obj = Locate.ContentRepository().Get <T>(contentLink);

            if ((object)obj == null)
            {
                return(default(T));
            }
            AccessLevel access    = contentLink.CompareToIgnoreWorkID(this.CurrentContentLink) ? AccessLevel.Read : AccessLevel.Read;
            ISecurable  securable = (object)obj as ISecurable;

            if (securable != null && !securable.GetSecurityDescriptor().HasAccess(PrincipalInfo.CurrentPrincipal, access))
            {
                if (PrincipalInfo.CurrentPrincipal.Identity.IsAuthenticated)
                {
                    throw new AccessDeniedException();
                }
                DefaultAccessDeniedHandler.AccessDenied((object)this);
            }
            return(obj);
        }
        /// <summary>
        /// Allows editing.
        /// </summary>
        /// <returns><c>true</c> if editing is allowed, <c>false</c> otherwise.</returns>
        private bool AllowEditable()
        {
            PropertyData    innerProperty  = this.InnerProperty;
            PropertyContext currentContext = this.CurrentContext;

            if (innerProperty == null || innerProperty.IsDynamicProperty || currentContext == null)
            {
                return(false);
            }

            ISecurable securable = currentContext.PropertyContainer as ISecurable
                                   ?? currentContext.CurrentContent as ISecurable;
            bool flag = this.CurrentContent != null &&
                        this.CurrentContent.ContentLink.CompareToIgnoreWorkID(
                currentContext.CurrentContent.ContentLink) && currentContext.IsEditable() &&
                        !this.IsContainedInTemplate() &&
                        (securable == null ||
                         securable.GetSecurityDescriptor()
                         .HasAccess(PrincipalInfo.CurrentPrincipal, AccessLevel.Edit));

            return(flag);
        }
Exemplo n.º 36
0
        // Note! This broke with CMS 8, but since we're not using the languageselector
        //       from code, we just ignore it
        //public virtual T Get<T>(ContentReference contentLink) where T : IContentData
        //{
        //    // CMS 8
        //    // LoaderOptions options  = new LoaderOptions();
        //    // options.Add(new LanguageLoaderOption() {FallbackBehaviour = LanguageBehaviour.Fallback});
        //    return this.Get<T>(contentLink, (LanguageSelector)LanguageSelector.AutoDetect(true));
        //}
        public virtual T Get <T>(ContentReference contentLink) where T : IContentData
        {
            T obj = Locate.ContentRepository().Get <T>(contentLink);

            if ((object)obj == null)
            {
                return(default(T));
            }
            AccessLevel access    = contentLink.CompareToIgnoreWorkID(this.CurrentContentLink) ? AccessLevel.Read : AccessLevel.Read;
            ISecurable  securable = (object)obj as ISecurable;

            if (securable != null && !securable.GetSecurityDescriptor().HasAccess(PrincipalInfo.CurrentPrincipal, access))
            {
                if (PrincipalInfo.CurrentPrincipal.Identity.IsAuthenticated)
                {
                    throw new AccessDeniedException();
                }
                IAccessDeniedHandler handler =
                    ServiceLocator.Current.GetInstance <IAccessDeniedHandler>();
                handler.AccessDenied(new HttpContextWrapper(Context)); // Man - we really need to get rid of web forms soon!
            }
            return(obj);
        }
Exemplo n.º 37
0
        private static DateTime ToLocal(this ISecurable securable, DateTime date, out TimeZoneInfo timeZoneInfo)
        {
            timeZoneInfo = null;

            var timeZoneId = securable == null ? null
                            : securable.Linea != null ? securable.Linea.TimeZoneId
                            : securable.Empresa != null ? securable.Empresa.TimeZoneId : null;

            if (timeZoneId == null)
            {
                return(date);
            }

            try
            {
                timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);

                return(date.AddHours(timeZoneInfo.BaseUtcOffset.TotalHours));
            }
            catch
            {
                return(date);
            }
        }
 public override AccessResult GetAccess(ISecurable entity, Account account, AccessRight accessRight)
 {
   return this.CurrentProvider.GetAccess(entity, account, accessRight);
 }
 protected override AccessResult GetAccessCore(ISecurable entity, Account account, AccessRight accessRight)
 {
   throw new System.NotImplementedException();
 }
Exemplo n.º 40
0
#pragma warning disable 1591
        public void AddSecurable(ISecurable securityObject)
        {
            _securables.Add(securityObject);
        }
Exemplo n.º 41
0
            public SetSecureLevelMenu( Mobile owner, ISecurable info, BaseHouse house )
                : base("SET ACCESS", null)
            {
                m_Info = info;
                List<String> list = new List<String>();

                list.Add("Owner Only");
                list.Add("Guild Members");
                list.Add("Anyone");

                Answers = list.ToArray();
            }
Exemplo n.º 42
0
 /// <summary>
 /// The set access rules.
 /// </summary>
 /// <param name="entity">
 /// The entity.
 /// </param>
 /// <param name="rules">
 /// The rules.
 /// </param>
 public override void SetAccessRules(ISecurable entity, AccessRuleCollection rules)
 {
     this.accessRules[entity.GetUniqueId()] = rules;
 }
Exemplo n.º 43
0
 protected override AccessResult GetAccessCore(ISecurable entity, Account account, AccessRight accessRight)
 {
     return new AccessResult(AccessPermission.Allow, new AccessExplanation("fake"));
 }
Exemplo n.º 44
0
		public SetSecureLevelEntry( Item item, ISecurable securable ) : base( 6203, 6 )
		{
			m_Item = item;
			m_Securable = securable;
		}
 protected override AccessResult GetAccessCore(ISecurable entity, Account account, AccessRight accessRight)
 {
   return new AccessResult(AccessPermission.Allow, new AccessExplanation("Everything is allowed by design."));
 }
 public override AccessRuleCollection GetAccessRules(ISecurable entity)
 {
   throw new System.NotImplementedException();
 }
Exemplo n.º 47
0
 /// <summary>
 /// Instantiates an instance of <see cref="AuthorizeSecurableResult"/> for the specificed <see cref="ISecurable"/>
 /// </summary>
 /// <param name="securable"><see cref="ISecurable"/> that this <see cref="AuthorizeSecurableResult"/> pertains to.</param>
 public AuthorizeSecurableResult(ISecurable securable)
 {
     Securable = securable;
 }
Exemplo n.º 48
0
        /// <summary>
        /// The get access core.
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <param name="account">
        /// The account.
        /// </param>
        /// <param name="accessRight">
        /// The access right.
        /// </param>
        /// <returns>
        /// The <see cref="AccessResult"/>.
        /// </returns>
        protected override AccessResult GetAccessCore(ISecurable entity, Account account, AccessRight accessRight)
        {
            if (!this.accessRules.ContainsKey(entity.GetUniqueId()))
              {
            return new AccessResult(AccessPermission.Allow, new AccessExplanation(account.Name, accessRight));
              }

              AccessRuleCollection rule = this.accessRules[entity.GetUniqueId()];

              return new AccessResult(rule.Helper.GetAccessPermission(account, accessRight, PropagationType.Any), new AccessExplanation("Memory authorization provider found it correct."));
        }
Exemplo n.º 49
0
        private static bool IsAccessibleToEveryone(ISecurable content)
        {
            var visitorPrinciple = new System.Security.Principal.GenericPrincipal(
                new System.Security.Principal.GenericIdentity("visitor"),
                new[] { "Everyone" });

            return content.GetSecurityDescriptor().HasAccess(visitorPrinciple, AccessLevel.Read);
        }
 public override void SetAccessRules(ISecurable entity, AccessRuleCollection rules)
 {
   throw new NotImplementedException();
 }
 protected override AccessResult GetAccessCore(ISecurable entity, Account account, AccessRight accessRight)
 {
     return new AccessResult(AccessPermission.Allow,
         new AccessExplanation("Always allow authorization provider used"));
 }
 public override AccessRuleCollection GetAccessRules(ISecurable entity)
 {
     return new AccessRuleCollection();
 }
Exemplo n.º 53
0
 /// <summary>
 /// The get access rules.
 /// </summary>
 /// <param name="entity">
 /// The entity.
 /// </param>
 /// <returns>
 /// The <see cref="AccessRuleCollection"/>.
 /// </returns>
 public override AccessRuleCollection GetAccessRules(ISecurable entity)
 {
     return this.accessRules[entity.GetUniqueId()];
 }
Exemplo n.º 54
0
#pragma warning disable 1591
        public void AddSecurable(ISecurable securityObject)
        {
            _securables.Add(securityObject);
        }
 public override void SetAccessRules(ISecurable entity, AccessRuleCollection rules)
 {
 }