using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Threading.Tasks; using Microsoft.InformationProtection; using Microsoft.InformationProtection.Policy; using Microsoft.InformationProtection.Policy.Actions; using Serilog; using Serilog.Core; namespace AipGateway.AIP { public class PolicyManager : AbstractManager { private IPolicyProfile _profile = null; private IPolicyEngine _engine = null; public PolicyManager(Logger logger, string clientId) : base(logger, clientId) { } ~PolicyManager() => this.Dispose(false); public override void Dispose() { this.Dispose(true); GC.SuppressFinalize((object)this); } protected virtual void Dispose(bool disposing) { lock (this) { if (_profile != null && _engine != null) { //_profile.UnloadEngineAsync(_engine.Settings.Id).Wait(); _profile.Dispose(); _engine.Dispose(); } _engine = null; _profile = null; } } public override bool CreateProfile(ref MipContext mipContext) { try { var profileSettings = new PolicyProfileSettings(mipContext, //CacheStorageType.OnDiskEncrypted CacheStorageType.InMemory ); // IFileProfile은 특정 애플리케이션에 대한 모든 SDK 작업의 루트입니다. _profile = Task.Run(async () => await MIP.LoadPolicyProfileAsync(profileSettings)).Result; } catch (Exception e) { SetError(1, "PolicyManager::CreateProfile Failed.", e.Message); return false; } return _profile != null; } public override bool CreateEngine(ref Identity identity, ref AuthDelegateImplementation authDelegate) { try { authDelegate.ResetError(); var engineSettings = new PolicyEngineSettings(identity.Email, authDelegate, string.Empty, "en-US") { // Provide the identity for service discovery. Identity = identity }; _engine = Task.Run(async () => await _profile.AddEngineAsync(engineSettings)).Result; } catch (Exception e) { if (authDelegate.LastErrNo != 0) { SetError(authDelegate.LastErrNo, "PolicyManager::CreateEngine Failed.", authDelegate.LastErrMsg); } else { SetError(2, "PolicyManager::CreateEngine Failed.", e.Message); } return false; } return _engine != null; } public IEnumerable