-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathApp.java
More file actions
110 lines (87 loc) · 4.29 KB
/
App.java
File metadata and controls
110 lines (87 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
*
* Copyright (c) Microsoft Corporation.
* All rights reserved.
*
* This code is licensed under the MIT License.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.microsoft.mipsdksample;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.concurrent.ExecutionException;
import com.microsoft.informationprotection.ApplicationInfo;
import com.microsoft.informationprotection.AssignmentMethod;
import com.microsoft.informationprotection.DataState;
public class App {
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
// ApplicationInfo is used to store the application name, clientId, and version.
ApplicationInfo appInfo = new ApplicationInfo();
FileOptions options = new FileOptions();
appInfo.setApplicationId("7dc8a6a5-1798-427f-8b13-088de27760c1");
appInfo.setApplicationName("MIP SDK Java Sample");
appInfo.setApplicationVersion("1.14");
System.out.print("Enter a username: ");
String userName = reader.readLine();
Action action = new Action(appInfo, userName);
// Fetch the list of labels for the authenticated user and display.
action.ListLabels();
// Copy a label Id from the output and paste into the prompt.
System.out.print("Enter a label Id: ");
options.LabelId = reader.readLine();
// Provide an input file that should be labeled.
System.out.print("Enter an input file full path: ");
options.InputFilePath = reader.readLine();
// Provide the output path for the file. The original file remains intact and a
// copy is created.
System.out.print("Enter an output file full path: ");
options.OutputFilePath = reader.readLine();
System.out.println("Applying label to file...");
// The privileged AssignmentMethod is used when users label files, and can
// override STANDARD.
options.AssignmentMethod = AssignmentMethod.PRIVILEGED;
// Information on datastate is used to populate audit information. This field
// doesn't impact the SDK behavior.
options.DataState = DataState.REST;
// Sets whether the sample should generate an audit event.
options.IsAuditDiscoveryEnabled = true;
// Apply the chosen label to the input file.
boolean result = action.SetLabel(options);
if (result) {
// This section attempts to read the label from the file, if one was applied.
System.out.println("Reading label from file...");
options.InputFilePath = options.OutputFilePath;
System.out.println("File Name: " + options.InputFilePath);
System.out.println("File Label: " + action.GetLabel(options).label.getName());
System.out.println("Reading owner from file...");
System.out.println("File Label: " + action.GetProtection(options).getOwner());
}
else
{
System.out.println("No changes were written to the input file.");
}
System.out.println("Press enter to quit.");
reader.readLine();
}
}