Skip to content

Commit 5dd3fd7

Browse files
jshum2479ddsharpe
authored andcommitted
Fix stdin entries to avoid closing stdin stream when encryption util is run in non console mode. (#423)
1 parent 9729168 commit 5dd3fd7

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

core/src/main/java/oracle/weblogic/deploy/util/CLAUtils.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import java.io.BufferedReader;
88
import java.io.IOException;
9+
import java.io.InputStream;
910
import java.io.InputStreamReader;
10-
import java.io.Reader;
1111
import java.util.Arrays;
1212

1313
import oracle.weblogic.deploy.exception.ExceptionHelper;
@@ -65,9 +65,7 @@ public static synchronized char[] getPasswordInput(String messageKey, Object...
6565
if (System.console() != null) {
6666
result = System.console().readPassword();
6767
} else {
68-
try (BufferedReader stdinReader = new BufferedReader(new InputStreamReader(System.in, UTF_8))){
69-
result = readPasswordFromStdin(stdinReader);
70-
}
68+
result = readPasswordFromStdin(System.in);
7169
}
7270
return result;
7371
}
@@ -76,7 +74,7 @@ private static void promptInTerminalWindow(String messageKey, Object... args) {
7674
System.out.print(ExceptionHelper.getMessage(messageKey, args) + PROMPT_ENDING);
7775
}
7876

79-
private static char[] readPasswordFromStdin(Reader stdinReader) throws IOException {
77+
private static char[] readPasswordFromStdin(InputStream stdinReader) throws IOException {
8078
char[] result = new char[MAX_PASSWORD_LENGTH];
8179

8280
boolean eolFound = false;

core/src/main/python/encrypt.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from java.io import IOException
1111
from java.lang import IllegalArgumentException
12-
from java.lang import String
12+
from java.lang import String, System
1313

1414
from oracle.weblogic.deploy.encrypt import EncryptionException
1515
from oracle.weblogic.deploy.util import CLAException
@@ -155,6 +155,14 @@ def __process_passphrase_arg(optional_arg_map):
155155
if passphrase == passphrase2:
156156
got_matching_passphrases = True
157157
optional_arg_map[CommandLineArgUtil.PASSPHRASE_SWITCH] = String(passphrase)
158+
else:
159+
# if it is script mode do not prompt again
160+
if System.console() is None:
161+
ex = exception_helper.create_cla_exception('WLSDPLY-04213')
162+
ex.setExitCode(CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
163+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
164+
raise ex
165+
158166
return
159167

160168

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ WLSDPLY-04209={0} encrypted {1} variables and wrote them to file {2}
360360
WLSDPLY-04210={0} encrypted {1} model attributes and wrote them to file {2}
361361
WLSDPLY-04211={0} failed to write encrypted model to file {1}: {2}
362362
WLSDPLY-04212={0} failed to encrypt the password: {1}
363+
WLSDPLY-04213="Encryption password does not match"
363364

364365
###############################################################################
365366
# Validate Messages (05000 - 05999) #

0 commit comments

Comments
 (0)