Skip to content

Commit

Permalink
Restore IsGranted extension method deprecated in Castle.Core
Browse files Browse the repository at this point in the history
Castler.Core deprecated CAS handling (castleproject/Core#502), this commit restores the relevant method and associated test.

castleproject#612 - Updating Windsor to support [email protected] and modern TFMs
  • Loading branch information
Jevonius committed May 14, 2022
1 parent dd4a0c9 commit 143e0af
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
38 changes: 38 additions & 0 deletions src/Castle.Windsor.Tests/Compatibility/PermissionUtilTests.cs
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions src/Castle.Windsor/Compatibility/PermissionUtil.cs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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

/// <summary>
/// Standard implementation of <see cref = "IComponentActivator" />. Handles the selection of the best constructor, fills the writable properties the component exposes, run the commission and
Expand Down
6 changes: 4 additions & 2 deletions src/Castle.Windsor/MicroKernel/DefaultKernel.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,7 +15,6 @@
namespace Castle.MicroKernel
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -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;

/// <summary>
Expand Down

0 comments on commit 143e0af

Please sign in to comment.