diff --git a/src/Castle.Windsor.Tests/Compatibility/PermissionUtilTests.cs b/src/Castle.Windsor.Tests/Compatibility/PermissionUtilTests.cs new file mode 100644 index 000000000..3f4471acd --- /dev/null +++ b/src/Castle.Windsor.Tests/Compatibility/PermissionUtilTests.cs @@ -0,0 +1,38 @@ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#if FEATURE_SECURITY_PERMISSIONS + +namespace Castle.Windsor.Tests.Compatibility +{ + using System.Security.Permissions; + + using Castle.Windsor.Compatibility; + using NUnit.Framework; + + [TestFixture] + public class PermissionUtilTests + { + [Test] + public void Correctly_determines_permissions() + { + // Execution has to be always granted. Otherwise this code wouldn't run in the first place. + var securityPermission = new SecurityPermission(SecurityPermissionFlag.Execution); + + Assert.IsTrue(securityPermission.IsGranted()); + } + } +} + +#endif \ No newline at end of file diff --git a/src/Castle.Windsor/Compatibility/PermissionUtil.cs b/src/Castle.Windsor/Compatibility/PermissionUtil.cs new file mode 100644 index 000000000..f6d52bb60 --- /dev/null +++ b/src/Castle.Windsor/Compatibility/PermissionUtil.cs @@ -0,0 +1,35 @@ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#if FEATURE_SECURITY_PERMISSIONS + +namespace Castle.Windsor.Compatibility +{ + using System; + using System.Security; + using System.Security.Permissions; + + public static class PermissionUtil + { + public static bool IsGranted(this IPermission permission) + { + var permissionSet = new PermissionSet(PermissionState.None); + permissionSet.AddPermission(permission); + + return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet); + } + } +} + +#endif \ No newline at end of file diff --git a/src/Castle.Windsor/MicroKernel/ComponentActivator/DefaultComponentActivator.cs b/src/Castle.Windsor/MicroKernel/ComponentActivator/DefaultComponentActivator.cs index f183cfa50..d2e5c0d7f 100644 --- a/src/Castle.Windsor/MicroKernel/ComponentActivator/DefaultComponentActivator.cs +++ b/src/Castle.Windsor/MicroKernel/ComponentActivator/DefaultComponentActivator.cs @@ -1,4 +1,4 @@ -// Copyright 2004-2012 Castle Project - http://www.castleproject.org/ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,6 +26,9 @@ namespace Castle.MicroKernel.ComponentActivator using Castle.Core.Internal; using Castle.DynamicProxy; using Castle.MicroKernel.Context; +#if FEATURE_SECURITY_PERMISSIONS + using Castle.Windsor.Compatibility; +#endif /// /// Standard implementation of . Handles the selection of the best constructor, fills the writable properties the component exposes, run the commission and diff --git a/src/Castle.Windsor/MicroKernel/DefaultKernel.cs b/src/Castle.Windsor/MicroKernel/DefaultKernel.cs index ed1e75629..b112895b0 100644 --- a/src/Castle.Windsor/MicroKernel/DefaultKernel.cs +++ b/src/Castle.Windsor/MicroKernel/DefaultKernel.cs @@ -1,4 +1,4 @@ -// Copyright 2004-2012 Castle Project - http://www.castleproject.org/ +// Copyright 2004-2022 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ namespace Castle.MicroKernel { using System; - using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -44,6 +43,9 @@ namespace Castle.MicroKernel using Castle.MicroKernel.SubSystems.Conversion; using Castle.MicroKernel.SubSystems.Naming; using Castle.MicroKernel.SubSystems.Resource; +#if FEATURE_SECURITY_PERMISSIONS + using Castle.Windsor.Compatibility; +#endif using Castle.Windsor.Diagnostics; ///