Forked from msiddiqi/AzManAccessControlChecker.cs
Last active
August 29, 2015 14:11
-
-
Save petarvucetin/1dca7a26da4aa2423456 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace AzManWrapperLib | |
{ | |
using AZROLESLib; | |
using System; | |
using System.Runtime.InteropServices; | |
using System.Security.Principal; | |
public class AzManAccessControlChecker : IAccessControlChecker, IDisposable | |
{ | |
#region Private Fields | |
private readonly IAzApplication _application; | |
#endregion Private Fields | |
// @"msxml://C:\Examples\AzMan\AzManXmlStore\AzManStore.xml" | |
// "TradeExecutionApp" | |
public AzManAccessControlChecker(string connectionString, string applicationName) | |
{ | |
var azAuthorizationStore = new AzAuthorizationStore(); | |
azAuthorizationStore.Initialize(0, connectionString, null); | |
azAuthorizationStore.UpdateCache(null); | |
_application = azAuthorizationStore.OpenApplication(applicationName, null); | |
} | |
public bool IsAllowedAccess(Operation operation, IIdentity identity) | |
{ | |
string operationName = Enum.GetName(typeof(Operation), operation); | |
IAzClientContext3 context = (IAzClientContext3)_application.InitializeClientContextFromName(identity.Name); | |
bool ret = false; | |
try | |
{ | |
ret = context.AccessCheck2(operationName, string.Empty, (int)operation) == 0; | |
} | |
catch | |
{ | |
// Log failure for administrator | |
} | |
return ret; | |
} | |
#region IDisposable Implementation | |
public void Dispose() | |
{ | |
Marshal.ReleaseComObject(_application); | |
} | |
#endregion IDisposable Implementation | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment