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.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class credentialsProcessor {
|
public class credentialsProcessor {
|
||||||
public static String getCredential(String thisPrompt, int thisLength, boolean isSecret) {
|
public static String getCredential(String thisPrompt, String regexPattern, boolean isSecret) {
|
||||||
String thisReturn = null;
|
String thisValue;
|
||||||
|
String thisPatten = (regexPattern == null) ? "^.+$" : regexPattern;
|
||||||
|
|
||||||
if (isSecret)
|
if (isSecret)
|
||||||
{
|
{
|
||||||
Console console = System.console();
|
Console console = System.console();
|
||||||
char[] charValue = console.readPassword(thisPrompt);
|
char[] charValue = console.readPassword(thisPrompt + " [ " + thisPatten + " ] : ");
|
||||||
while (charValue != null && charValue.length < thisLength)
|
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
|
else
|
||||||
{
|
{
|
||||||
Scanner myObj = new Scanner(System.in);
|
Scanner myObj = new Scanner(System.in);
|
||||||
System.out.print(thisPrompt);
|
System.out.print(thisPrompt + " [ " + thisPatten + " ] : ");
|
||||||
thisReturn = myObj.nextLine();
|
thisValue = myObj.nextLine().trim();
|
||||||
while (thisReturn != null && thisReturn.toString().length() < thisLength)
|
boolean isValid = thisValue.matches(thisPatten);
|
||||||
|
|
||||||
|
while (!isValid)
|
||||||
{
|
{
|
||||||
System.out.print(thisPrompt);
|
System.out.print(thisPrompt + " [ " + thisPatten + " ] : ");;
|
||||||
thisReturn = myObj.nextLine();
|
thisValue = myObj.nextLine().trim();
|
||||||
|
isValid = thisValue.matches(thisPatten);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return thisReturn;
|
return thisValue;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -48,7 +48,8 @@ public class webService {
|
|||||||
{
|
{
|
||||||
if (varKey == null)
|
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);
|
String varToStore = encyptProcessor.encrypt(varToEncrypt, varKey, varSalt);
|
||||||
@ -89,17 +90,22 @@ public class webService {
|
|||||||
while (iterator.hasNext())
|
while (iterator.hasNext())
|
||||||
{
|
{
|
||||||
Map.Entry<Integer, Map> pair = iterator.next();
|
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();
|
System.out.println();
|
||||||
|
|
||||||
|
if (!thisFinal.get("total").equals(0))
|
||||||
|
{
|
||||||
debugProcessor.writer(true, "!! Connect User : " + thisFinal.get("user"));
|
debugProcessor.writer(true, "!! Connect User : " + thisFinal.get("user"));
|
||||||
|
}
|
||||||
|
|
||||||
debugProcessor.writer(true, "!! Total records : " + thisFinal.get("total"));
|
debugProcessor.writer(true, "!! Total records : " + thisFinal.get("total"));
|
||||||
debugProcessor.writer(true, "!! Total passed : " + thisFinal.get("passed"));
|
debugProcessor.writer(true, "!! Total passed : " + thisFinal.get("passed"));
|
||||||
debugProcessor.writer(true, "!! Total failed : " + thisFinal.get("failed"));
|
debugProcessor.writer(true, "!! Total failed : " + thisFinal.get("failed"));
|
||||||
|
|
||||||
Boolean thisResult = thisFinal.get("total") == thisFinal.get("passed");
|
boolean thisResult = thisFinal.get("total") == thisFinal.get("passed");
|
||||||
debugProcessor.writer(true, "!! WAS SUCCESSFUL : " + thisResult.toString().toUpperCase());
|
debugProcessor.writer(true, "!! WAS SUCCESSFUL : " + String.valueOf(thisResult).toUpperCase());
|
||||||
if (!thisResult)
|
if (!thisResult)
|
||||||
{
|
{
|
||||||
debugProcessor.writer(true, "!! PLEASE CHECK THE DEBUG LOG");
|
debugProcessor.writer(true, "!! PLEASE CHECK THE DEBUG LOG");
|
||||||
@ -158,15 +164,16 @@ public class webService {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean varUseSSL = Boolean.valueOf(varPropUseSSL);
|
boolean varUseSSL = Boolean.valueOf(varPropUseSSL);
|
||||||
Boolean varAuthRequired = Boolean.valueOf(varPropAuthRequired);
|
boolean varAuthRequired = Boolean.valueOf(varPropAuthRequired);
|
||||||
|
boolean varEmptyColumns = Boolean.valueOf(varPropEmptyColumns);
|
||||||
Boolean varEmptyColumns = Boolean.valueOf(varPropEmptyColumns);
|
|
||||||
|
|
||||||
String varUsername = propertyProcessor.getProperty(thisProps, "USERNAME", null);
|
String varUsername = propertyProcessor.getProperty(thisProps, "USERNAME", null);
|
||||||
|
|
||||||
|
String varFormat = propertyProcessor.getProperty(thisProps, "USERNAME_FORMAT", null);
|
||||||
if (varAuthRequired && varUsername == 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);
|
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!
|
// This is just a temporary key so that the rest of the code does not error out!
|
||||||
varKey = "ZyXwQbRH9VGrAEzN";
|
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);
|
varPasswordTemp = encyptProcessor.encrypt(varUserPW, varKey, varSalt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (varKey == null)
|
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
|
else
|
||||||
@ -223,12 +230,12 @@ public class webService {
|
|||||||
|
|
||||||
ArrayList thisCSV = userVerify.readCSV(varRoleFile, false, !varEmptyColumns);
|
ArrayList thisCSV = userVerify.readCSV(varRoleFile, false, !varEmptyColumns);
|
||||||
|
|
||||||
boolean validfile = (!thisCSV.isEmpty());
|
boolean validFile = (!thisCSV.isEmpty());
|
||||||
debugProcessor.writer(varDebug, "");
|
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());
|
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!");
|
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())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
Map.Entry<Integer, Integer> pair = it.next();
|
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())
|
for(Object key: hashMap.keySet())
|
||||||
{
|
{
|
||||||
Boolean varHasText = fileProcessor.fileHasText(varInputFile, key.toString());
|
boolean varHasText = fileProcessor.fileHasText(varInputFile, key.toString());
|
||||||
debugProcessor.writer(varDebug, "[before] " + varInputFile + " : " + key + " token exists => " + varHasText);
|
debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : " + key + " token exists in " + varInputFile + " => " + varHasText);
|
||||||
}
|
}
|
||||||
|
|
||||||
String varXML = fileProcessor.replaceInFile(varInputFile, hashMap);
|
String varXML = fileProcessor.replaceInFile(varInputFile, hashMap);
|
||||||
for(Object key: hashMap.keySet())
|
for(Object key: hashMap.keySet())
|
||||||
{
|
{
|
||||||
Boolean varHasText = fileProcessor.stringHasText(varXML, key.toString());
|
boolean varHasText = fileProcessor.stringHasText(varXML, key.toString());
|
||||||
// debugProcessor.writer(varDebug, "[after] " + varInputFile + " : " + key + " token exists => " + varHasText);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<Boolean, String> errorMap = new HashMap();
|
HashMap<Boolean, String> errorMap = new HashMap();
|
||||||
@ -282,7 +288,6 @@ public class webService {
|
|||||||
|
|
||||||
boolean varSuccess = Boolean.valueOf(response.get("success").toString());
|
boolean varSuccess = Boolean.valueOf(response.get("success").toString());
|
||||||
debugProcessor.writer(!varSuccess, "[" + varCount + " of " + thisCSV.size() + "] : SOAP call response data : " + response.get("response"));
|
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)
|
if (!varSuccess)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user