Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addresses #1194, adding an IAuthorizationContext. #1195

Merged
merged 3 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/Csla.Shared/Csla.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Rules\BusinessRules.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Rules\BusinessRulesExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Rules\CommonRules.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Rules\IAuthorizationContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Rules\IAuthorizationRule.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Rules\IBusinessRule.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Rules\IBusinessRules.cs" />
Expand Down
5 changes: 1 addition & 4 deletions Source/Csla.Shared/Rules/AuthorizationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
// <summary>Context information provided to an authorization</summary>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Csla.Rules
Expand All @@ -17,7 +14,7 @@ namespace Csla.Rules
/// Context information provided to an authorization
/// rule when it is invoked.
/// </summary>
public class AuthorizationContext
public class AuthorizationContext : IAuthorizationContext
{
/// <summary>
/// Gets the rule object.
Expand Down
6 changes: 3 additions & 3 deletions Source/Csla.Shared/Rules/AuthorizationRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public AuthorizationRule(AuthorizationActions action, Csla.Core.IMemberInfo elem
/// Authorization rule implementation.
/// </summary>
/// <param name="context">Rule context object.</param>
protected abstract void Execute(AuthorizationContext context);
protected abstract void Execute(IAuthorizationContext context);


/// <summary>
Expand Down Expand Up @@ -95,12 +95,12 @@ public AuthorizationActions Action
private void CanWriteProperty(string argument)
{
if (_locked)
new ArgumentException(string.Format("{0} ({1})", Resources.PropertySetNotAllowed, argument), argument);
throw new ArgumentException(string.Format("{0} ({1})", Resources.PropertySetNotAllowed, argument), argument);
}

#region IAuthorizationRule

void IAuthorizationRule.Execute(AuthorizationContext context)
void IAuthorizationRule.Execute(IAuthorizationContext context)
{
if (!_locked)
_locked = true;
Expand Down
4 changes: 2 additions & 2 deletions Source/Csla.Shared/Rules/AuthorizationRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public IsInRole(AuthorizationActions action, Csla.Core.IMemberInfo element, para
/// Rule implementation.
/// </summary>
/// <param name="context">Rule context.</param>
protected override void Execute(AuthorizationContext context)
protected override void Execute(IAuthorizationContext context)
{
if (Csla.ApplicationContext.User != null)
{
Expand Down Expand Up @@ -147,7 +147,7 @@ public IsNotInRole(AuthorizationActions action, Csla.Core.IMemberInfo element, p
/// Rule implementation.
/// </summary>
/// <param name="context">Rule context.</param>
protected override void Execute(AuthorizationContext context)
protected override void Execute(IAuthorizationContext context)
{
context.HasPermission = true;
if (Csla.ApplicationContext.User != null)
Expand Down
40 changes: 40 additions & 0 deletions Source/Csla.Shared/Rules/IAuthorizationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//-----------------------------------------------------------------------
// <copyright file="IAuthorizationContext.cs" company="Marimer LLC">
// Copyright (c) Marimer LLC. All rights reserved.
// Website: https://cslanet.com
// </copyright>
// <summary>Interface defining an authorization context</summary>
//-----------------------------------------------------------------------
using System;

namespace Csla.Rules
{
/// <summary>
/// Implemented by objects which provide context information to an authorization
/// rule when it is invoked.
/// </summary>
public interface IAuthorizationContext
{
/// <summary>
/// Gets the rule object.
/// </summary>
IAuthorizationRule Rule { get; }

/// <summary>
/// Gets a reference to the target business object.
/// </summary>
object Target { get; }

/// <summary>
/// Gets the type of the target business class.
/// </summary>
Type TargetType { get; }

/// <summary>
/// Gets or sets a value indicating whether the
/// current user has permission to perform the requested
/// action.
/// </summary>
bool HasPermission { get; set; }
}
}
2 changes: 1 addition & 1 deletion Source/Csla.Shared/Rules/IAuthorizationRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface IAuthorizationRule
/// Authorization rule implementation.
/// </summary>
/// <param name="context">Rule context object.</param>
void Execute(AuthorizationContext context);
void Execute(IAuthorizationContext context);
/// <summary>
/// Gets the element (property/method)
/// to which this rule is associated.
Expand Down
2 changes: 1 addition & 1 deletion Source/Csla.test/Authorization/AuthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public NoAuth(AuthorizationActions action)
: base(action)
{}

protected override void Execute(AuthorizationContext context)
protected override void Execute(IAuthorizationContext context)
{
context.HasPermission = false;
}
Expand Down
2 changes: 1 addition & 1 deletion Support/Snippets/cs/DefineACslaAuthorizationRule.snippet
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

}

protected override void Execute(AuthorizationContext context)
protected override void Execute(IAuthorizationContext context)
{
// TODO: Add actual rule code here.
//if (!access_condition)
Expand Down
2 changes: 1 addition & 1 deletion Support/Snippets/vb/DefineACslaAuthorizationRule.snippet
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
' End Get
'End Property

Protected Overrides Sub Execute(context As AuthorizationContext)
Protected Overrides Sub Execute(context As IAuthorizationContext)
' TODO: Add actual rule code here.
'if (!access_condition)
'{
Expand Down
2 changes: 1 addition & 1 deletion Support/Templates/cs/Files/AuthorizationRuleClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public AuthorizationRuleClass(AuthorizationActions action)
// get { return false; }
//}

protected override void Execute(AuthorizationContext context)
protected override void Execute(IAuthorizationContext context)
{
// TODO: Add actual rule code here.
//if (!access_condition)
Expand Down
2 changes: 1 addition & 1 deletion Support/Templates/vb/Files/AuthorizationRuleClass.vb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Public Class AuthorizationRuleClass
'End Property


Protected Overrides Sub Execute(ByVal context As AuthorizationContext)
Protected Overrides Sub Execute(ByVal context As IAuthorizationContext)
' TODO: Add actual rule code here.
'if (!access_condition)
'{
Expand Down