Add regex condition in to the getCredential method
This commit is contained in:
parent
79cb46092e
commit
f20c999933
@ -4,31 +4,41 @@ import java.io.Console;
|
||||
import java.util.*;
|
||||
|
||||
public class credentialsProcessor {
|
||||
public static String getCredential(String thisPrompt, int thisLength, boolean isSecret) {
|
||||
String thisReturn = null;
|
||||
public static String getCredential(String thisPrompt, String regexPattern, boolean isSecret) {
|
||||
String thisValue;
|
||||
String thisPatten = (regexPattern == null) ? "^.+$" : regexPattern;
|
||||
|
||||
if (isSecret)
|
||||
{
|
||||
Console console = System.console();
|
||||
char[] charValue = console.readPassword(thisPrompt);
|
||||
while (charValue != null && charValue.length < thisLength)
|
||||
char[] charValue = console.readPassword(thisPrompt + " [ " + thisPatten + " ] : ");
|
||||
thisValue = String.copyValueOf(charValue).trim();
|
||||
boolean isValid = thisValue.matches(thisPatten);
|
||||
|
||||
while (!isValid)
|
||||
{
|
||||
charValue = console.readPassword(thisPrompt);
|
||||
charValue = console.readPassword(thisPrompt + " [ " + thisPatten + " ] : ");
|
||||
thisValue = String.copyValueOf(charValue).trim();
|
||||
isValid = thisValue.matches(thisPatten);
|
||||
}
|
||||
thisReturn = String.copyValueOf(charValue);
|
||||
thisValue = String.copyValueOf(charValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Scanner myObj = new Scanner(System.in);
|
||||
System.out.print(thisPrompt);
|
||||
thisReturn = myObj.nextLine();
|
||||
while (thisReturn != null && thisReturn.toString().length() < thisLength)
|
||||
System.out.print(thisPrompt + " [ " + thisPatten + " ] : ");
|
||||
thisValue = myObj.nextLine().trim();
|
||||
boolean isValid = thisValue.matches(thisPatten);
|
||||
|
||||
while (!isValid)
|
||||
{
|
||||
System.out.print(thisPrompt);
|
||||
thisReturn = myObj.nextLine();
|
||||
System.out.print(thisPrompt + " [ " + thisPatten + " ] : ");;
|
||||
thisValue = myObj.nextLine().trim();
|
||||
isValid = thisValue.matches(thisPatten);
|
||||
}
|
||||
}
|
||||
|
||||
return thisReturn;
|
||||
return thisValue;
|
||||
|
||||
}
|
||||
}
|
@ -48,7 +48,8 @@ public class webService {
|
||||
{
|
||||
if (varKey == null)
|
||||
{
|
||||
String varKey = credentialsProcessor.getCredential("Please enter the encryption key (must be 16 characters) : ", 16, true);
|
||||
varKey = credentialsProcessor.getCredential("Please enter the encryption key (must be 16 characters)", "^(.){16}$", true);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
String varToStore = encyptProcessor.encrypt(varToEncrypt, varKey, varSalt);
|
||||
@ -89,17 +90,22 @@ public class webService {
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Map.Entry<Integer, Map> pair = iterator.next();
|
||||
debugProcessor.writer(varDebug, "!! processed " + pair.getKey() + " [" + pair.getValue().get("soap_response") + "] " + pair.getValue());
|
||||
debugProcessor.writer(varDebug, "!! [" + pair.getKey() + " of " + pair.getValue().get("csv_records") + " : " + pair.getValue().get("soap_response") + "] " + pair.getValue());
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
debugProcessor.writer(true, "!! Connect User : " + thisFinal.get("user"));
|
||||
|
||||
if (!thisFinal.get("total").equals(0))
|
||||
{
|
||||
debugProcessor.writer(true, "!! Connect User : " + thisFinal.get("user"));
|
||||
}
|
||||
|
||||
debugProcessor.writer(true, "!! Total records : " + thisFinal.get("total"));
|
||||
debugProcessor.writer(true, "!! Total passed : " + thisFinal.get("passed"));
|
||||
debugProcessor.writer(true, "!! Total failed : " + thisFinal.get("failed"));
|
||||
|
||||
Boolean thisResult = thisFinal.get("total") == thisFinal.get("passed");
|
||||
debugProcessor.writer(true, "!! WAS SUCCESSFUL : " + thisResult.toString().toUpperCase());
|
||||
boolean thisResult = thisFinal.get("total") == thisFinal.get("passed");
|
||||
debugProcessor.writer(true, "!! WAS SUCCESSFUL : " + String.valueOf(thisResult).toUpperCase());
|
||||
if (!thisResult)
|
||||
{
|
||||
debugProcessor.writer(true, "!! PLEASE CHECK THE DEBUG LOG");
|
||||
@ -158,15 +164,16 @@ public class webService {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
Boolean varUseSSL = Boolean.valueOf(varPropUseSSL);
|
||||
Boolean varAuthRequired = Boolean.valueOf(varPropAuthRequired);
|
||||
|
||||
Boolean varEmptyColumns = Boolean.valueOf(varPropEmptyColumns);
|
||||
boolean varUseSSL = Boolean.valueOf(varPropUseSSL);
|
||||
boolean varAuthRequired = Boolean.valueOf(varPropAuthRequired);
|
||||
boolean varEmptyColumns = Boolean.valueOf(varPropEmptyColumns);
|
||||
|
||||
String varUsername = propertyProcessor.getProperty(thisProps, "USERNAME", null);
|
||||
|
||||
String varFormat = propertyProcessor.getProperty(thisProps, "USERNAME_FORMAT", null);
|
||||
if (varAuthRequired && varUsername == null)
|
||||
{
|
||||
varUsername = credentialsProcessor.getCredential("Please enter your username : ", 1, false);
|
||||
varUsername = credentialsProcessor.getCredential("Please enter a username", varFormat, false);
|
||||
}
|
||||
|
||||
String varPasswordTemp = propertyProcessor.getProperty(thisProps, "PASSWORD", null);
|
||||
@ -177,13 +184,13 @@ public class webService {
|
||||
{
|
||||
// This is just a temporary key so that the rest of the code does not error out!
|
||||
varKey = "ZyXwQbRH9VGrAEzN";
|
||||
String varUserPW = credentialsProcessor.getCredential("[" + varUsername + "] Please enter your password : ", 1, true);
|
||||
String varUserPW = credentialsProcessor.getCredential("[" + varUsername + "] Please enter a password", null, true);
|
||||
varPasswordTemp = encyptProcessor.encrypt(varUserPW, varKey, varSalt);
|
||||
}
|
||||
|
||||
if (varKey == null)
|
||||
{
|
||||
String userKey = credentialsProcessor.getCredential("Please enter the encryption key (must be 16 characters) : ", 16, true);
|
||||
varKey = credentialsProcessor.getCredential("Please enter the encryption key (must be 16 characters)", "^(.){16}$", true);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -223,12 +230,12 @@ public class webService {
|
||||
|
||||
ArrayList thisCSV = userVerify.readCSV(varRoleFile, false, !varEmptyColumns);
|
||||
|
||||
boolean validfile = (!thisCSV.isEmpty());
|
||||
boolean validFile = (!thisCSV.isEmpty());
|
||||
debugProcessor.writer(varDebug, "");
|
||||
debugProcessor.writer(true, "CSV file is valid : " + validfile);
|
||||
debugProcessor.writer(true, "CSV file is valid : " + validFile);
|
||||
debugProcessor.writer(true, "CSV records to process : " + thisCSV.size());
|
||||
|
||||
if (!validfile)
|
||||
if (!validFile)
|
||||
{
|
||||
debugProcessor.writer(true, varRoleFile + " => verification failed : please verify the file with com.belkast.soap.userVerify!");
|
||||
}
|
||||
@ -246,20 +253,19 @@ public class webService {
|
||||
while (it.hasNext())
|
||||
{
|
||||
Map.Entry<Integer, Integer> pair = it.next();
|
||||
debugProcessor.writer(varDebug, "record " + varCount + " : " + pair.getKey() + " => " + pair.getValue());
|
||||
debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : " + pair.getKey() + " => " + pair.getValue());
|
||||
}
|
||||
|
||||
for(Object key: hashMap.keySet())
|
||||
{
|
||||
Boolean varHasText = fileProcessor.fileHasText(varInputFile, key.toString());
|
||||
debugProcessor.writer(varDebug, "[before] " + varInputFile + " : " + key + " token exists => " + varHasText);
|
||||
boolean varHasText = fileProcessor.fileHasText(varInputFile, key.toString());
|
||||
debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : " + key + " token exists in " + varInputFile + " => " + varHasText);
|
||||
}
|
||||
|
||||
String varXML = fileProcessor.replaceInFile(varInputFile, hashMap);
|
||||
for(Object key: hashMap.keySet())
|
||||
{
|
||||
Boolean varHasText = fileProcessor.stringHasText(varXML, key.toString());
|
||||
// debugProcessor.writer(varDebug, "[after] " + varInputFile + " : " + key + " token exists => " + varHasText);
|
||||
boolean varHasText = fileProcessor.stringHasText(varXML, key.toString());
|
||||
}
|
||||
|
||||
HashMap<Boolean, String> errorMap = new HashMap();
|
||||
@ -282,7 +288,6 @@ public class webService {
|
||||
|
||||
boolean varSuccess = Boolean.valueOf(response.get("success").toString());
|
||||
debugProcessor.writer(!varSuccess, "[" + varCount + " of " + thisCSV.size() + "] : SOAP call response data : " + response.get("response"));
|
||||
debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : SOAP call was successful : " + Boolean.valueOf(response.get("success").toString()));
|
||||
|
||||
if (!varSuccess)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user