Skip to content

Commit 27391f1

Browse files
committed
Merge branch 'WDT-863' into 'main'
Adding support for Jakarta version of JAXB See merge request weblogic-cloud/weblogic-deploy-tooling!1760
2 parents 6960150 + 2fa0a84 commit 27391f1

File tree

10 files changed

+270
-26
lines changed

10 files changed

+270
-26
lines changed

core/src/main/java/oracle/weblogic/deploy/encrypt/EncryptionUtils.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
import javax.crypto.spec.GCMParameterSpec;
2323
import javax.crypto.spec.PBEKeySpec;
2424
import javax.crypto.spec.SecretKeySpec;
25-
import javax.xml.bind.DatatypeConverter;
2625

2726
import oracle.weblogic.deploy.logging.PlatformLogger;
2827
import oracle.weblogic.deploy.logging.WLSDeployLogFactory;
2928
import oracle.weblogic.deploy.util.StringUtils;
29+
import oracle.weblogic.deploy.util.JaxbDatatypeConverter;
30+
import oracle.weblogic.deploy.util.WdtJaxbException;
3031

3132
import static java.nio.charset.StandardCharsets.US_ASCII;
3233
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -165,7 +166,7 @@ public static String encryptString(String clearText, final char[] userPassphrase
165166
byte[] encrypted = cipher.doFinal(clearText.getBytes(UTF_8));
166167
result = getEncryptedString(encrypted, nonce, salt);
167168
} catch (InvalidKeyException | InvalidAlgorithmParameterException |
168-
IllegalBlockSizeException | BadPaddingException ex) {
169+
IllegalBlockSizeException | BadPaddingException | WdtJaxbException ex) {
169170

170171
EncryptionException ee =
171172
new EncryptionException("WLSDPLY-04002", ex, JAVA_VERSION, ex.getLocalizedMessage());
@@ -218,31 +219,38 @@ private static Cipher getCipher() throws EncryptionException {
218219
return cipher;
219220
}
220221

221-
private static String getEncryptedString(byte[] cipher, byte[] nonce, byte[] salt) {
222-
String cipherEncoded = DatatypeConverter.printBase64Binary(cipher);
223-
String nonceEncoded = DatatypeConverter.printBase64Binary(nonce);
224-
String saltEncoded = DatatypeConverter.printBase64Binary(salt);
222+
private static String getEncryptedString(byte[] cipher, byte[] nonce, byte[] salt) throws WdtJaxbException{
223+
String cipherEncoded = JaxbDatatypeConverter.printBase64Binary(cipher);
224+
String nonceEncoded = JaxbDatatypeConverter.printBase64Binary(nonce);
225+
String saltEncoded = JaxbDatatypeConverter.printBase64Binary(salt);
225226
String all = cipherEncoded + SEP + nonceEncoded + SEP + saltEncoded;
226-
String allEncoded = DatatypeConverter.printBase64Binary(all.getBytes(US_ASCII));
227+
String allEncoded = JaxbDatatypeConverter.printBase64Binary(all.getBytes(US_ASCII));
227228
return CIPHER_TEXT_PREFIX + allEncoded;
228229
}
229230

230231
private static List<byte[]> getCipherComponents(String text) throws EncryptionException {
231232
final String METHOD = "getCipherComponents";
233+
LOGGER.entering(CLASS, METHOD);
232234

233235
List<byte[]> result = new ArrayList<>();
234236
if (text.startsWith(CIPHER_TEXT_PREFIX) && text.length() > CIPHER_TEXT_PREFIX.length()) {
235-
String all = text.substring(CIPHER_TEXT_PREFIX.length());
236-
String allDecoded = new String(DatatypeConverter.parseBase64Binary(all), US_ASCII);
237-
String[] parts = allDecoded.split(SEP);
238-
if (parts.length != CIPHER_SECTIONS) {
239-
EncryptionException ee = new EncryptionException("WLSDPLY-04006", parts.length);
237+
try {
238+
String all = text.substring(CIPHER_TEXT_PREFIX.length());
239+
String allDecoded = new String(JaxbDatatypeConverter.parseBase64Binary(all), US_ASCII);
240+
String[] parts = allDecoded.split(SEP);
241+
if (parts.length != CIPHER_SECTIONS) {
242+
EncryptionException ee = new EncryptionException("WLSDPLY-04006", parts.length);
243+
LOGGER.throwing(CLASS, METHOD, ee);
244+
throw ee;
245+
}
246+
result.add(JaxbDatatypeConverter.parseBase64Binary(parts[PWD_POS]));
247+
result.add(JaxbDatatypeConverter.parseBase64Binary(parts[NONCE_POS]));
248+
result.add(JaxbDatatypeConverter.parseBase64Binary(parts[SALT_POS]));
249+
} catch (WdtJaxbException ex) {
250+
EncryptionException ee = new EncryptionException("WLSDPLY-04007", ex, ex.getLocalizedMessage());
240251
LOGGER.throwing(CLASS, METHOD, ee);
241252
throw ee;
242253
}
243-
result.add(DatatypeConverter.parseBase64Binary(parts[PWD_POS]));
244-
result.add(DatatypeConverter.parseBase64Binary(parts[NONCE_POS]));
245-
result.add(DatatypeConverter.parseBase64Binary(parts[SALT_POS]));
246254
}
247255
return result;
248256
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.HashSet;
2020
import java.util.Locale;
2121
import java.util.Set;
22-
import javax.xml.bind.DatatypeConverter;
2322

2423
import oracle.weblogic.deploy.exception.ExceptionHelper;
2524
import oracle.weblogic.deploy.logging.PlatformLogger;
@@ -477,7 +476,7 @@ public static void deleteDirectory(File directory) {
477476
* @throws NoSuchAlgorithmException if an error occurs obtaining the hashing algorithm
478477
* @throws IllegalArgumentException if the file is not a valid, existing file
479478
*/
480-
public static String computeHash(String fileName) throws IOException, NoSuchAlgorithmException {
479+
public static String computeHash(String fileName) throws IOException, NoSuchAlgorithmException, WdtJaxbException {
481480
final String METHOD = "computeHash";
482481

483482
LOGGER.entering(CLASS, METHOD, fileName);
@@ -497,7 +496,7 @@ public static String computeHash(String fileName) throws IOException, NoSuchAlgo
497496
* @throws NoSuchAlgorithmException if an error occurs obtaining the hashing algorithm
498497
* @throws IllegalArgumentException if the file is not a valid, existing file
499498
*/
500-
public static String computeHash(File file) throws IOException, NoSuchAlgorithmException {
499+
public static String computeHash(File file) throws IOException, NoSuchAlgorithmException, WdtJaxbException {
501500
final String METHOD = "computeHash";
502501

503502
LOGGER.entering(CLASS, METHOD, file);
@@ -516,10 +515,10 @@ public static String computeHash(File file) throws IOException, NoSuchAlgorithmE
516515
* @return the Base64-encoded hash
517516
* @throws NoSuchAlgorithmException if an error occurs obtaining the hashing algorithm
518517
*/
519-
public static String computeHash(byte[] bytes) throws NoSuchAlgorithmException {
518+
public static String computeHash(byte[] bytes) throws NoSuchAlgorithmException, WdtJaxbException {
520519
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
521520
byte[] hash = messageDigest.digest(bytes);
522-
return DatatypeConverter.printBase64Binary(hash);
521+
return JaxbDatatypeConverter.printBase64Binary(hash);
523522
}
524523

525524
/**
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates.
3+
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
*/
5+
package oracle.weblogic.deploy.util;
6+
7+
import java.lang.reflect.InvocationTargetException;
8+
import java.lang.reflect.Method;
9+
10+
import oracle.weblogic.deploy.logging.PlatformLogger;
11+
import oracle.weblogic.deploy.logging.WLSDeployLogFactory;
12+
13+
/**
14+
* A utility class that acts as an abstraction layer to JAXB classes so that
15+
* we can operate with either javax or jakarta package implementation classes.
16+
*/
17+
public class JaxbDatatypeConverter {
18+
private static final String CLASS = JaxbDatatypeConverter.class.getName();
19+
private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.util");
20+
21+
private static final String JAVAX_DATATYPE_CONVERTER_CLASS_NAME = "javax.xml.bind.DatatypeConverter";
22+
private static final String JAKARTA_DATATYPE_CONVERTER_CLASS_NAME = "jakarta.xml.bind.DatatypeConverter";
23+
24+
private static final Class<?> DATATYPE_CONVERTER_CLASS;
25+
26+
static {
27+
Class<?> datatypeConverterClass = null;
28+
try {
29+
datatypeConverterClass =
30+
JaxbDatatypeConverter.class.getClassLoader().loadClass(JAVAX_DATATYPE_CONVERTER_CLASS_NAME);
31+
} catch (ClassNotFoundException e) {
32+
LOGGER.fine("WLSDPLY-08600", JAVAX_DATATYPE_CONVERTER_CLASS_NAME, e.getLocalizedMessage());
33+
34+
try {
35+
datatypeConverterClass =
36+
JaxbDatatypeConverter.class.getClassLoader().loadClass(JAKARTA_DATATYPE_CONVERTER_CLASS_NAME);
37+
} catch (ClassNotFoundException e2) {
38+
LOGGER.fine("WLSDPLY-08600", JAKARTA_DATATYPE_CONVERTER_CLASS_NAME, e.getLocalizedMessage());
39+
40+
WdtJaxbException ex = new WdtJaxbException("WLSDPLY-08601", JAVAX_DATATYPE_CONVERTER_CLASS_NAME,
41+
JAKARTA_DATATYPE_CONVERTER_CLASS_NAME);
42+
LOGGER.throwing(CLASS, "static initializer", ex);
43+
}
44+
}
45+
DATATYPE_CONVERTER_CLASS = datatypeConverterClass;
46+
}
47+
48+
public static String printBase64Binary(byte[] val) throws WdtJaxbException {
49+
final String METHOD = "printBase64Binary";
50+
LOGGER.entering(CLASS, METHOD);
51+
52+
String result = null;
53+
try {
54+
Method method = getPrintBase64BinaryMethod();
55+
result = (String) method.invoke(null, (Object) val);
56+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) {
57+
WdtJaxbException ex = new WdtJaxbException("WLSDPLY-08603", e, METHOD, e.getLocalizedMessage());
58+
LOGGER.throwing(CLASS, METHOD, ex);
59+
throw ex;
60+
}
61+
62+
LOGGER.exiting(CLASS, METHOD, result);
63+
return result;
64+
}
65+
66+
public static byte[] parseBase64Binary(String val) throws WdtJaxbException {
67+
final String METHOD = "parseBase64Binary";
68+
LOGGER.entering(CLASS, METHOD);
69+
70+
byte[] result = new byte[] {};
71+
try {
72+
Method method = getParseBase64BinaryMethod();
73+
result = (byte[]) method.invoke(null, val);
74+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) {
75+
WdtJaxbException ex = new WdtJaxbException("WLSDPLY-08603", e, METHOD, e.getLocalizedMessage());
76+
LOGGER.throwing(CLASS, METHOD, ex);
77+
throw ex;
78+
}
79+
80+
LOGGER.exiting(CLASS, METHOD, result);
81+
return result;
82+
}
83+
84+
public static String printHexBinary(byte[] val) throws WdtJaxbException {
85+
final String METHOD = "printHexBinary";
86+
LOGGER.entering(CLASS, METHOD);
87+
88+
String result = null;
89+
try {
90+
Method method = getPrintHexBinaryMethod();
91+
result = (String) method.invoke(null, (Object) val);
92+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) {
93+
WdtJaxbException ex = new WdtJaxbException("WLSDPLY-08603", e, METHOD, e.getLocalizedMessage());
94+
LOGGER.throwing(CLASS, METHOD, ex);
95+
throw ex;
96+
}
97+
98+
LOGGER.exiting(CLASS, METHOD, result);
99+
return result;
100+
}
101+
102+
private static Method getPrintBase64BinaryMethod() throws WdtJaxbException {
103+
final String METHOD = "getPrintBase64BinaryMethod";
104+
LOGGER.entering(CLASS, METHOD);
105+
106+
Method method;
107+
try {
108+
method = DATATYPE_CONVERTER_CLASS.getMethod("printBase64Binary", byte[].class);
109+
} catch (NoSuchMethodException | SecurityException e) {
110+
WdtJaxbException ex = new WdtJaxbException("WLSDPLY-08602", e, "printBase64Binary", e.getLocalizedMessage());
111+
LOGGER.throwing(CLASS, METHOD, ex);
112+
throw ex;
113+
}
114+
LOGGER.exiting(CLASS, METHOD, method);
115+
return method;
116+
}
117+
118+
private static Method getPrintHexBinaryMethod() throws WdtJaxbException {
119+
final String METHOD = "getPrintHexBinaryMethod";
120+
LOGGER.entering(CLASS, METHOD);
121+
122+
Method method;
123+
try {
124+
method = DATATYPE_CONVERTER_CLASS.getMethod("printHexBinary", byte[].class);
125+
} catch (NoSuchMethodException | SecurityException e) {
126+
WdtJaxbException ex = new WdtJaxbException("WLSDPLY-08602", e, "printHexBinary", e.getLocalizedMessage());
127+
LOGGER.throwing(CLASS, METHOD, ex);
128+
throw ex;
129+
}
130+
LOGGER.exiting(CLASS, METHOD, method);
131+
return method;
132+
}
133+
134+
private static Method getParseBase64BinaryMethod() throws WdtJaxbException {
135+
final String METHOD = "getParseBase64BinaryMethod";
136+
LOGGER.entering(CLASS, METHOD);
137+
138+
Method method;
139+
try {
140+
method = DATATYPE_CONVERTER_CLASS.getMethod("parseBase64Binary", String.class);
141+
} catch (NoSuchMethodException | SecurityException e) {
142+
WdtJaxbException ex = new WdtJaxbException("WLSDPLY-08602", e, "parseBase64Binary", e.getLocalizedMessage());
143+
LOGGER.throwing(CLASS, METHOD, ex);
144+
throw ex;
145+
}
146+
LOGGER.exiting(CLASS, METHOD, method);
147+
return method;
148+
}
149+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ public String getFileHash(String path) throws WLSDeployArchiveIOException {
933933
String result;
934934
try {
935935
result = FileUtils.computeHash(fileBytes);
936-
} catch (NoSuchAlgorithmException e) {
936+
} catch (NoSuchAlgorithmException | WdtJaxbException e) {
937937
WLSDeployArchiveIOException aioe =
938938
new WLSDeployArchiveIOException("WLSDPLY-01407", e, getArchiveFileName(), path,
939939
e.getLocalizedMessage());
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2024, Oracle Corporation and/or its affiliates.
3+
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
*/
5+
package oracle.weblogic.deploy.util;
6+
7+
import oracle.weblogic.deploy.exception.BundleAwareException;
8+
import oracle.weblogic.deploy.exception.ExceptionHelper;
9+
10+
public class WdtJaxbException extends BundleAwareException {
11+
private static final long serialVersionUID = 1L;
12+
13+
/**
14+
* Constructs a default exception.
15+
*/
16+
public WdtJaxbException() {
17+
// default constructor
18+
}
19+
20+
/**
21+
* Constructs a new exception with the specified message id.
22+
*
23+
* @param messageID the message ID
24+
*/
25+
public WdtJaxbException(String messageID) {
26+
super(messageID);
27+
}
28+
29+
/**
30+
* Constructs a new exception with the specified message id and parameters.
31+
*
32+
* @param messageID the message ID
33+
* @param params the parameters to use to fill in the message tokens
34+
*/
35+
public WdtJaxbException(String messageID, Object... params) {
36+
super(messageID, params);
37+
}
38+
39+
/**
40+
* Constructs a new exception with the specified message id and cause.
41+
*
42+
* @param messageID the message ID
43+
* @param cause the exception that triggered the creation of this exception
44+
*/
45+
public WdtJaxbException(String messageID, Throwable cause) {
46+
super(messageID, cause);
47+
}
48+
49+
/**
50+
* Constructs a new exception with passed message id, cause, and parameters.
51+
*
52+
* @param messageID the message ID
53+
* @param cause the exception that triggered the creation of this exception
54+
* @param params the parameters to use to fill in the message tokens
55+
*/
56+
public WdtJaxbException(String messageID, Throwable cause, Object... params) {
57+
super(messageID, cause, params);
58+
}
59+
60+
/**
61+
* Constructs a new exception with the specified cause.
62+
*
63+
* @param cause the exception that triggered the creation of this exception
64+
*/
65+
public WdtJaxbException(Throwable cause) {
66+
super(cause);
67+
}
68+
69+
/**
70+
* {@inheritDoc}
71+
*/
72+
@Override
73+
public String getBundleName() {
74+
return ExceptionHelper.getResourceBundleName();
75+
}
76+
}

core/src/main/python/wlsdeploy/tool/deploy/applications_online_deployer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from java.security import NoSuchAlgorithmException
1313
from oracle.weblogic.deploy.util import FileUtils
1414
from oracle.weblogic.deploy.util import PyOrderedDict as OrderedDict
15+
from oracle.weblogic.deploy.util import WdtJaxbException
1516

1617
from wlsdeploy.aliases import alias_utils
1718
from wlsdeploy.aliases.location_context import LocationContext
@@ -644,7 +645,7 @@ def __get_file_hash(self, filename):
644645
return None
645646

646647
hash_value = FileUtils.computeHash(filename)
647-
except (IOException, NoSuchAlgorithmException), e:
648+
except (IOException, NoSuchAlgorithmException, WdtJaxbException), e:
648649
ex = exception_helper.create_deploy_exception('WLSDPLY-09309', filename, e.getLocalizedMessage(), error=e)
649650
self.logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
650651
raise ex

core/src/main/python/wlsdeploy/tool/deploy/deployer_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from oracle.weblogic.deploy.util import FileUtils
1818
from oracle.weblogic.deploy.util import StringUtils
1919
from oracle.weblogic.deploy.util import PyWLSTException
20+
from oracle.weblogic.deploy.util import WdtJaxbException
2021
from oracle.weblogic.deploy.util import WLSDeployArchive
2122

2223
from oracle.weblogic.deploy.exception import BundleAwareException
@@ -475,7 +476,7 @@ def get_file_hash(file_name):
475476
_logger.entering(file_name, class_name=_class_name, method_name=_method_name)
476477
try:
477478
result = FileUtils.computeHash(file_name)
478-
except (IOException, NoSuchAlgorithmException), e:
479+
except (IOException, NoSuchAlgorithmException, WdtJaxbException), e:
479480
ex = exception_helper.create_deploy_exception('WLSDPLY-09108', file_name, e.getLocalizedMessage(), error=e)
480481
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
481482
raise ex

0 commit comments

Comments
 (0)