public VaultInteraction(VaultSession vaultSession) {
this.vaultNISession = vaultSession;
}
public void start() {
Console console = System.console();
if (console == null) {
System.err.println("No console.");
System.exit(1);
}
Scanner in = new Scanner(System.in);
while (true) {
String commandStr = "Please enter a Digit:: 0: Store a secured attribute " + " 1: Check whether a secured attribute exists "
+ " 2: Exit";
System.out.println(commandStr);
int choice = in.nextInt();
switch (choice) {
case 0:
System.out.println("Task: Store a secured attribute");
char[] attributeValue = VaultInteractiveSession.getSensitiveValue("Please enter secured attribute value (such as password)");
String vaultBlock = null;
while (vaultBlock == null || vaultBlock.length() == 0) {
vaultBlock = console.readLine("Enter Vault Block:");
}
String attributeName = null;
while (attributeName == null || attributeName.length() == 0) {
attributeName = console.readLine("Enter Attribute Name:");
}
try {
vaultNISession.addSecuredAttributeWithDisplay(vaultBlock, attributeName, attributeValue);
} catch (Exception e) {
System.out.println("Exception occurred:" + e.getLocalizedMessage());
}
break;
case 1:
System.out.println("Task: Verify whether a secured attribute exists");
try {
vaultBlock = null;
while (vaultBlock == null || vaultBlock.length() == 0) {
vaultBlock = console.readLine("Enter Vault Block:");
}
attributeName = null;
while (attributeName == null || attributeName.length() == 0) {
attributeName = console.readLine("Enter Attribute Name:");
}
if (!vaultNISession.checkSecuredAttribute(vaultBlock, attributeName))
System.out.println("No value has been store for (" + vaultBlock + ", " + attributeName + ")");
else
System.out.println("A value exists for (" + vaultBlock + ", " + attributeName + ")");