Example #1
0
    /// <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 IFileEngine CreateFileEngine(Identity identity)
    {
        // If the profile hasn't been created, do that first.
        if (profile == null)
        {
            profile = CreateFileProfile(appInfo);
        }

        var configuredFunctions = new Dictionary <FunctionalityFilterType, bool>();

        configuredFunctions.Add(FunctionalityFilterType.DoubleKeyProtection, true);


        // 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 FileEngineSettings(identity.Email, authDelegate, "", "en-US")
        {
            // Provide the identity for service discovery.
            Identity = identity,
            ConfiguredFunctionality = configuredFunctions
        };

        // Add the IFileEngine to the profile and return.
        var engine = Task.Run(async() => await profile.AddEngineAsync(engineSettings)).Result;

        return(engine);
    }
Example #2
0
        /// <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 IFileEngine CreateFileEngine(Identity identity)
        {
            try
            {
                // If the profile hasn't been created, do that first.
                if (profile == null)
                {
                    profile = CreateFileProfile(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 FileEngineSettings("", "", "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);
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Initializes a new IFileEngine using the provided username, custom client data string, and locale.
        /// Stores result in _fileEngine.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="clientData"></param>
        /// <param name="locale"></param>
        private void CreateFileEngine(string username, string clientData, string locale)
        {
            try
            {
                var engineSettings = new FileEngineSettings(username, clientData, locale);
                engineSettings.ProtectionCloudEndpointBaseUrl = "https://api.aadrm.com";
                _fileEngine = Task.Run(async() => await _fileProfile.AddEngineAsync(engineSettings)).Result;
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Initializes a new IFileEngine using the provided username, custom client data string, and locale.
        /// Stores result in _fileEngine.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="clientData"></param>
        /// <param name="locale"></param>
        private void CreateFileEngine(string username, string clientData, string locale)
        {
            try
            {
                Identity id             = new Identity(username);
                var      engineSettings = new FileEngineSettings(username, _authDelegate, clientData, locale)
                {
                    Identity = id
                };

                fileEngine = Task.Run(async() => await fileProfile.AddEngineAsync(engineSettings)).Result;
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult InvokeMIP()
        {
            string          name      = User.Identity.Name;
            ClaimsPrincipal principal = ClaimsPrincipal.Current;
            var             tenantId  = principal.FindFirst(c => c.Type == "http://schemas.microsoft.com/identity/claims/tenantid").Value;

            // Set path to bins folder.
            var path = Path.Combine(
                Directory.GetParent(Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath)).FullName,
                Environment.Is64BitProcess ? "bin\\x64" : "bin\\x86");

            //Initialize Wrapper for File API operations
            MIP.Initialize(MipComponent.File, path);

            //Create ApplicationInfo, setting the clientID from Azure AD App Registration as the ApplicationId
            ApplicationInfo appInfo = new ApplicationInfo()
            {
                ApplicationId      = clientId,
                ApplicationName    = appName,
                ApplicationVersion = appVersion
            };

            //Instatiate the AuthDelegateImpl object, passing in AppInfo.
            AuthDelegateImplementation authDelegate = new AuthDelegateImplementation(appInfo, tenantId);

            //Initialize and instantiate the File Profile
            //Create the FileProfileSettings object
            var profileSettings = new FileProfileSettings(mipPath, false, authDelegate, new ConsentDelegateImplementation(), appInfo, LogLevel.Trace);

            //Load the Profile async and wait for the result
            var fileProfile = Task.Run(async() => await MIP.LoadFileProfileAsync(profileSettings)).Result;

            //Create a FileEngineSettings object, then use that to add an engine to the profile
            var engineSettings = new FileEngineSettings(name, "", "en-US");

            engineSettings.Identity = new Identity(name);

            var fileEngine = Task.Run(async() => await fileProfile.AddEngineAsync(engineSettings)).Result;

            // Just a test code to check if all the custom labels are populated or not
            foreach (var label in fileEngine.SensitivityLabels)
            {
                string labelName = label.Name;
            }

            //Set paths and label ID. You can paas file input stream too
            string filePath       = Server.MapPath(@"~/App_Data/DemoAIPDoc.docx");
            string outputFilePath = @"D:\Test2.docx";

            var stream = System.IO.File.OpenRead(filePath);

            //Create a file handler for that file
            //Note: the 2nd inputFilePath is used to provide a human-readable content identifier for admin auditing.
            var handler = Task.Run(async() => await fileEngine.CreateFileHandlerAsync(stream, filePath, true)).Result;

            LabelingOptions labelingOptions = new LabelingOptions()
            {
                AssignmentMethod     = AssignmentMethod.Privileged, //important as we are removing the label
                IsDowngradeJustified = true,
                JustificationMessage = "Lowering label"
            };

            //remove the label
            handler.DeleteLabel(labelingOptions);

            // Commit changes, save as outputFilePath.  You can also generate output stream
            var result = Task.Run(async() => await handler.CommitAsync(outputFilePath)).Result;

            return(RedirectToAction("Index"));
        }