// Use Execution State to compute policy actions /// <summary> /// Constructor for Action class. Pass in AppInfo to simplify passing settings to AuthDelegate. /// </summary> /// <param name="appInfo"></param> public Action(ApplicationInfo appInfo) { this.appInfo = appInfo; // Initialize AuthDelegateImplementation using AppInfo. authDelegate = new AuthDelegateImplementation(this.appInfo); // Initialize SDK DLLs. If DLLs are missing or wrong type, this will throw an exception MIP.Initialize(MipComponent.Policy); // This method in AuthDelegateImplementation triggers auth against Graph so that we can get the user ID. var id = authDelegate.GetUserIdentity(); // Create profile. profile = CreatePolicyProfile(appInfo, ref authDelegate); // Create engine providing Identity from authDelegate to assist with service discovery. engine = CreatePolicyEngine(id); }
/// <summary> /// Creates a file engine, associating the engine with the specified identity. /// File engines are generally created per-user in an application. /// IFileEngine implements all operations for fetching labels and sensitivity types. /// IFileHandlers are added to engines to perform labeling operations. /// </summary> /// <param name="identity"></param> /// <returns></returns> private IPolicyEngine CreatePolicyEngine(Identity identity) { // If the profile hasn't been created, do that first. if (profile == null) { profile = CreatePolicyProfile(appInfo, ref authDelegate); } // Create file settings object. Passing in empty string for the first parameter, engine ID, will cause the SDK to generate a GUID. // Locale settings are supported and should be provided based on the machine locale, particular for client applications. var engineSettings = new PolicyEngineSettings("", "", "en-US") { // Provide the identity for service discovery. Identity = identity }; // Add the IFileEngine to the profile and return. var engine = Task.Run(async() => await profile.AddEngineAsync(engineSettings)).Result; return(engine); }