Skip to content

Commit 02bd732

Browse files
authored
Addopssencryptkey (#392)
* add opss set secret capability * complete logic for opss secret * fix _method name * refactoring
1 parent 85b1d7b commit 02bd732

File tree

10 files changed

+218
-121
lines changed

10 files changed

+218
-121
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
import java.io.IOException;
1313
import java.io.InputStream;
1414
import java.nio.file.Files;
15+
import java.nio.file.Paths;
1516
import java.security.MessageDigest;
1617
import java.security.NoSuchAlgorithmException;
1718
import java.util.ArrayList;
1819
import java.util.Arrays;
1920
import java.util.List;
2021
import java.util.Locale;
22+
import java.util.zip.ZipEntry;
23+
import java.util.zip.ZipInputStream;
2124

2225
import javax.xml.bind.DatatypeConverter;
2326

@@ -632,6 +635,56 @@ public static File writeInputStreamToFile(InputStream input, String fileName) th
632635
return file;
633636
}
634637

638+
639+
public static void extractZipFileContent(WLSDeployArchive archiveFile, String zipEntry, String extractPath) {
640+
final String METHOD = "extractZipFileContent";
641+
642+
try {
643+
644+
if (zipEntry != null) {
645+
646+
File extractDir = new File(extractPath);
647+
extractDir.mkdirs();
648+
String walletZip = archiveFile.extractFile(zipEntry,
649+
Files.createTempDirectory("tempwallet").toFile());
650+
651+
if (!Files.exists(Paths.get(extractPath))) {
652+
Files.createDirectory(Paths.get(extractPath));
653+
}
654+
655+
byte[] buffer = new byte[1024];
656+
FileInputStream fis = new FileInputStream(walletZip);
657+
ZipInputStream zis = new ZipInputStream(fis);
658+
ZipEntry ze = zis.getNextEntry();
659+
while (ze != null) {
660+
String fileName = ze.getName();
661+
File newFile = new File(extractPath + File.separator + fileName);
662+
new File(newFile.getParent()).mkdirs();
663+
FileOutputStream fos = new FileOutputStream(newFile);
664+
int len = zis.read(buffer);
665+
while (len > 0) {
666+
fos.write(buffer, 0, len);
667+
len = zis.read(buffer);
668+
}
669+
fos.close();
670+
zis.closeEntry();
671+
ze = zis.getNextEntry();
672+
673+
}
674+
zis.closeEntry();
675+
zis.close();
676+
fis.close();
677+
Files.delete(Paths.get(walletZip));
678+
}
679+
} catch (IOException | WLSDeployArchiveIOException ioe) {
680+
String message = ExceptionHelper.getMessage("WLSDPLY-01118", METHOD, CLASS, ioe.getLocalizedMessage());
681+
IllegalArgumentException iae = new IllegalArgumentException(message);
682+
LOGGER.throwing(CLASS, METHOD, iae);
683+
throw iae;
684+
685+
}
686+
687+
}
635688
///////////////////////////////////////////////////////////////////////////
636689
// Private helper methods //
637690
///////////////////////////////////////////////////////////////////////////
@@ -718,4 +771,6 @@ public boolean accept(File dir, String name) {
718771
return result;
719772
}
720773
}
774+
775+
721776
}

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

Lines changed: 100 additions & 73 deletions
Large diffs are not rendered by default.

core/src/main/python/create.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
from wlsdeploy.util import wlst_helper
4747
from wlsdeploy.util.cla_utils import CommandLineArgUtil
4848
from wlsdeploy.util.model_context import ModelContext
49-
from wlsdeploy.util.model_translator import FileToPython
5049
from wlsdeploy.util.weblogic_helper import WebLogicHelper
5150
from wlsdeploy.tool.create import atp_helper
5251

core/src/main/python/wlsdeploy/aliases/alias_entries.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ class AliasEntries(object):
185185
# the ServerGroup is not listed in this map, it will be targeted to all managed
186186
# servers in the domain.
187187
'ServerGroupTargetingLimits': 'dict',
188-
'RCUDbInfo' : 'dict'
188+
'RCUDbInfo': 'dict',
189+
'OPSSSecrets': 'string'
189190
}
190191

191192
__domain_name_token = 'DOMAIN'

core/src/main/python/wlsdeploy/aliases/model_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
APP_DIR = 'AppDir'
2020
APPLICATION = 'Application'
2121
RCU_DB_INFO = 'RCUDbInfo'
22+
OPSS_SECRETS = 'OPSSSecrets'
2223
RCU_PREFIX = 'rcu_prefix'
2324
RCU_SCHEMA_PASSWORD = 'rcu_schema_password'
2425
RCU_ADMIN_PASSWORD = 'rcu_admin_password'

core/src/main/python/wlsdeploy/tool/create/atp_helper.py

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
66
"""
77

8-
import os, re
9-
10-
from xml.dom.minidom import parse
11-
8+
import os
9+
import re
1210
from java.io import File
13-
from java.io import FileInputStream
14-
from java.io import FileOutputStream
15-
from java.util.zip import ZipInputStream
16-
import jarray
17-
11+
from oracle.weblogic.deploy.util import FileUtils
1812
from wlsdeploy.aliases import model_constants
13+
from xml.dom.minidom import parse
1914

2015

2116
def set_ssl_properties(xmlDoc, atp_creds_path, keystore_password, truststore_password):
@@ -61,34 +56,6 @@ def set_property(DOMTree, prop, name, value):
6156
newline = DOMTree.createTextNode('\n')
6257
prop.appendChild(newline)
6358

64-
65-
def unzip_atp_wallet(wallet_file, location):
66-
67-
if not os.path.exists(location):
68-
os.mkdir(location)
69-
70-
buffer = jarray.zeros(1024, "b")
71-
fis = FileInputStream(wallet_file)
72-
zis = ZipInputStream(fis)
73-
ze = zis.getNextEntry()
74-
while ze:
75-
fileName = ze.getName()
76-
newFile = File(location + File.separator + fileName)
77-
File(newFile.getParent()).mkdirs()
78-
fos = FileOutputStream(newFile)
79-
len = zis.read(buffer)
80-
while len > 0:
81-
fos.write(buffer, 0, len)
82-
len = zis.read(buffer)
83-
84-
fos.close()
85-
zis.closeEntry()
86-
ze = zis.getNextEntry()
87-
zis.closeEntry()
88-
zis.close()
89-
fis.close()
90-
91-
9259
def fix_jps_config(rcu_db_info, model_context):
9360
tns_admin = rcu_db_info.get_atp_tns_admin()
9461
keystore_password = rcu_db_info.get_keystore_password()
@@ -163,7 +130,6 @@ def extract_walletzip(model, model_context, archive_file, atp_zipentry):
163130
extract_dir = File(extract_path)
164131
extract_dir.mkdirs()
165132
wallet_zip = archive_file.extractFile(atp_zipentry, File(domain_path))
166-
unzip_atp_wallet(wallet_zip, extract_path)
167-
os.remove(wallet_zip)
133+
FileUtils.extractZipFileContent(archive_file, wallet_zip, extract_path)
168134
return extract_path
169135
# update the model to add the tns_admin

core/src/main/python/wlsdeploy/tool/create/domain_creator.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
The Universal Permissive License (UPL), Version 1.0
44
"""
55
import javaos as os
6-
from java.util import Properties
6+
import weblogic.security.internal.SerializedSystemIni as SerializedSystemIni
7+
import weblogic.security.internal.encryption.ClearOrEncryptedService as ClearOrEncryptedService
78
from java.io import FileOutputStream
9+
from java.util import Properties
810
from oracle.weblogic.deploy.create import RCURunner
11+
from oracle.weblogic.deploy.util import WLSDeployArchive, FileUtils
912
from wlsdeploy.aliases.location_context import LocationContext
1013
from wlsdeploy.aliases.model_constants import ADMIN_PASSWORD
1114
from wlsdeploy.aliases.model_constants import ADMIN_SERVER_NAME
1215
from wlsdeploy.aliases.model_constants import ADMIN_USERNAME
1316
from wlsdeploy.aliases.model_constants import APP_DIR
1417
from wlsdeploy.aliases.model_constants import ATP_ADMIN_USER
15-
from wlsdeploy.aliases.model_constants import ATP_TNS_ENTRY
1618
from wlsdeploy.aliases.model_constants import ATP_DEFAULT_TABLESPACE
1719
from wlsdeploy.aliases.model_constants import ATP_TEMPORARY_TABLESPACE
20+
from wlsdeploy.aliases.model_constants import ATP_TNS_ENTRY
1821
from wlsdeploy.aliases.model_constants import CLUSTER
1922
from wlsdeploy.aliases.model_constants import CREATE_ONLY_DOMAIN_ATTRIBUTES
2023
from wlsdeploy.aliases.model_constants import DEFAULT_ADMIN_SERVER_NAME
@@ -41,14 +44,15 @@
4144
from wlsdeploy.aliases.model_constants import MACHINE
4245
from wlsdeploy.aliases.model_constants import MIGRATABLE_TARGET
4346
from wlsdeploy.aliases.model_constants import NAME
47+
from wlsdeploy.aliases.model_constants import OPSS_SECRETS
4448
from wlsdeploy.aliases.model_constants import PARTITION
4549
from wlsdeploy.aliases.model_constants import PASSWORD
4650
from wlsdeploy.aliases.model_constants import PASSWORD_ENCRYPTED
51+
from wlsdeploy.aliases.model_constants import RCU_ADMIN_PASSWORD
4752
from wlsdeploy.aliases.model_constants import RCU_DB_CONN
4853
from wlsdeploy.aliases.model_constants import RCU_DB_INFO
4954
from wlsdeploy.aliases.model_constants import RCU_PREFIX
5055
from wlsdeploy.aliases.model_constants import RCU_SCHEMA_PASSWORD
51-
from wlsdeploy.aliases.model_constants import RCU_ADMIN_PASSWORD
5256
from wlsdeploy.aliases.model_constants import RESOURCE_GROUP
5357
from wlsdeploy.aliases.model_constants import RESOURCE_GROUP_TEMPLATE
5458
from wlsdeploy.aliases.model_constants import SECURITY
@@ -70,8 +74,8 @@
7074
from wlsdeploy.exception import exception_helper
7175
from wlsdeploy.exception.expection_types import ExceptionType
7276
from wlsdeploy.tool.create import atp_helper
73-
from wlsdeploy.tool.create.rcudbinfo_helper import RcuDbInfo
7477
from wlsdeploy.tool.create.creator import Creator
78+
from wlsdeploy.tool.create.rcudbinfo_helper import RcuDbInfo
7579
from wlsdeploy.tool.create.security_provider_creator import SecurityProviderCreator
7680
from wlsdeploy.tool.deploy import deployer_utils
7781
from wlsdeploy.tool.deploy import model_deployer
@@ -82,8 +86,6 @@
8286
from wlsdeploy.tool.util.topology_helper import TopologyHelper
8387
from wlsdeploy.util import dictionary_utils
8488
from wlsdeploy.util import model as model_helper
85-
import weblogic.security.internal.SerializedSystemIni as SerializedSystemIni
86-
import weblogic.security.internal.encryption.ClearOrEncryptedService as ClearOrEncryptedService
8789

8890

8991
class DomainCreator(Creator):
@@ -349,6 +351,7 @@ def __deploy(self):
349351
self.__set_domain_attributes()
350352
self._configure_security_configuration()
351353
self.__deploy_resources_and_apps()
354+
self.__configure_opss_secrets()
352355
self.wlst_helper.update_domain()
353356
self.wlst_helper.close_domain()
354357
return
@@ -1128,3 +1131,20 @@ def __create_boot_dot_properties(self):
11281131
ostream.close()
11291132
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
11301133
return
1134+
1135+
def __configure_opss_secrets(self):
1136+
_method_name = '__configure_opss_secrets'
1137+
self.logger.entering(class_name=self.__class_name, method_name=_method_name)
1138+
extract_path = None
1139+
domain_info = self._domain_info
1140+
if domain_info is not None:
1141+
if OPSS_SECRETS in domain_info:
1142+
opss_secret_password = domain_info[OPSS_SECRETS]
1143+
if self.model_context.get_archive_file_name() and opss_secret_password:
1144+
archive_file = WLSDeployArchive(self.model_context.get_archive_file_name())
1145+
extract_path = self._domain_home + os.sep + 'opsswallet'
1146+
zip_entry = archive_file.getOPSSWallet();
1147+
FileUtils.extractZipFileContent(archive_file, zip_entry, extract_path)
1148+
self.wlst_helper.setSharedSecretStoreWithPassword(extract_path, opss_secret_password)
1149+
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
1150+
return extract_path

core/src/main/python/wlsdeploy/tool/util/wlst_helper.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,3 +1047,18 @@ def reopen(self, model_context):
10471047
pwe.getLocalizedMessage(), error=pwe)
10481048
self.__logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
10491049
raise ex
1050+
1051+
def setSharedSecretStoreWithPassword(self, wallet_path, password):
1052+
"""
1053+
set the shared secret store opss password
1054+
:param wallet_path: opss extracted wallet dir
1055+
:param password: extract time password
1056+
"""
1057+
_method_name = 'setSharedSecretStoreWithPassword'
1058+
try:
1059+
wlst_helper.set_shared_secret_store_with_password(wallet_path, password)
1060+
except PyWLSTException, pwe:
1061+
ex = exception_helper.create_exception(self.__exception_type, 'WLSDPLY-19144',
1062+
pwe.getLocalizedMessage(), error=pwe)
1063+
self.__logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
1064+
raise ex

core/src/main/python/wlsdeploy/util/wlst_helper.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,3 +1395,16 @@ def reopen_offline(domain_home):
13951395
_logger.fine('WLSDPLY-00081', class_name=_class_name, method_name=_method_name)
13961396
read_domain(domain_home)
13971397
_logger.exiting(class_name=_class_name, method_name=_method_name)
1398+
1399+
1400+
def set_shared_secret_store_with_password(wallet_path, password):
1401+
"""
1402+
Set opss store password
1403+
:param wallet_path: opss extracted wallet
1404+
:param password: opss store extraction time password
1405+
"""
1406+
_method_name = 'set_shared_secret_store_with_password'
1407+
_logger.fine('WLSDPLY-00081', class_name=_class_name, method_name=_method_name)
1408+
wlst.setSharedSecretStoreWithPassword(wallet_path,password)
1409+
_logger.exiting(class_name=_class_name, method_name=_method_name)
1410+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ WLSDPLY-01114=Deleting the file {1} in directory {0}
128128
WLSDPLY-01115=Unable to delete file {0} from directory {1}
129129
WLSDPLY-01116=Unable to successfully delete the directory {0}
130130
WLSDPLY-01117=Model directory {0} has more than one {1} file, found {2} after previously finding {3}
131-
131+
WLSDPLY-01118=Error extracting zipentry zip file {0}
132132
# oracle.weblogic.deploy.util.ProcessHandler.java
133133
WLSDPLY-01200=Process for command {0} isRunning() unable to get an exit value: {1}
134134
WLSDPLY-01201=ProcessHandler had no registered wait handler when asked to exec() command: {0}

0 commit comments

Comments
 (0)