Skip to content

Commit ee0708a

Browse files
committed
Merge branch 'JIRA-WDT-753-saml2-create-discover' into 'main'
Discover and create/update SAML2 initialization files See merge request weblogic-cloud/weblogic-deploy-tooling!1476
2 parents 6311d25 + 02fb53a commit ee0708a

File tree

6 files changed

+214
-5
lines changed

6 files changed

+214
-5
lines changed

core/src/main/python/wlsdeploy/logging/platform_logger.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""
2-
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import java.lang.Object as JObject
6+
import java.lang.String as JString
67
import java.lang.System as JSystem
78
import java.lang.Thread as JThread
89
import java.lang.Throwable as Throwable
@@ -315,7 +316,8 @@ def _get_args_as_java_array(*args):
315316
if isinstance(arg, unicode) or isinstance(arg, str):
316317
result.add(arg)
317318
elif isinstance(arg, JObject):
318-
result.add(arg.toString())
319+
# support Java objects with multiple toString signatures
320+
result.add(JString.valueOf(arg))
319321
else:
320322
result.add(str_helper.to_string(arg))
321323
else:

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
from wlsdeploy.tool.util.credential_map_helper import CredentialMapHelper
9393
from wlsdeploy.tool.util.default_authenticator_helper import DefaultAuthenticatorHelper
9494
from wlsdeploy.tool.util.library_helper import LibraryHelper
95+
from wlsdeploy.tool.util.saml2_security_helper import Saml2SecurityHelper
9596
from wlsdeploy.tool.util.target_helper import TargetHelper
9697
from wlsdeploy.tool.util.targeting_types import TargetingType
9798
from wlsdeploy.tool.util.topology_profiles import TopologyProfile
@@ -180,10 +181,11 @@ def create(self):
180181
self.__deploy_after_update()
181182
self.__create_boot_dot_properties()
182183
self.__create_credential_mappings()
184+
self.__install_saml2_security_files()
183185

184186
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
185187

186-
#Override
188+
# Override
187189
def _set_attributes(self, location, model_nodes):
188190
model_type, model_name = self.aliases.get_model_type_and_name(location)
189191
if model_type == CLUSTER:
@@ -1514,6 +1516,13 @@ def __create_credential_mappings(self):
15141516
credential_map_helper = CredentialMapHelper(self.model_context, ExceptionType.CREATE)
15151517
credential_map_helper.create_default_init_file(default_nodes)
15161518

1519+
def __install_saml2_security_files(self):
1520+
"""
1521+
Install SAML2 security files from model archive.
1522+
"""
1523+
saml2_security_helper = Saml2SecurityHelper(self._domain_home, ExceptionType.CREATE)
1524+
saml2_security_helper.extract_initialization_files(self.archive_helper)
1525+
15171526
def __configure_opss_secrets(self):
15181527
_method_name = '__configure_opss_secrets'
15191528

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2022, Oracle and/or its affiliates.
2+
Copyright (c) 2017, 2023, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
from wlsdeploy.aliases.location_context import LocationContext
@@ -21,6 +21,7 @@
2121
from wlsdeploy.tool.deploy import deployer_utils
2222
from wlsdeploy.tool.deploy.deployer import Deployer
2323
from wlsdeploy.tool.util.library_helper import LibraryHelper
24+
from wlsdeploy.tool.util.saml2_security_helper import Saml2SecurityHelper
2425
from wlsdeploy.tool.util.target_helper import TargetHelper
2526
from wlsdeploy.tool.util.topology_helper import TopologyHelper
2627
from wlsdeploy.util import dictionary_utils
@@ -49,7 +50,8 @@ def __init__(self, model, model_context, aliases, wlst_mode=WlstModes.OFFLINE):
4950

5051
self.target_helper = TargetHelper(self.model, self.model_context, self.aliases, self._exception_type,
5152
self.logger)
52-
#Override
53+
54+
# Override
5355
def set_attributes(self, location, model_nodes, excludes=None):
5456
model_type, model_name = self.aliases.get_model_type_and_name(location)
5557
if model_type == CLUSTER:
@@ -126,6 +128,10 @@ def update(self):
126128
self.library_helper.extract_custom_files()
127129
self.library_helper.install_domain_scripts()
128130

131+
domain_home = self.model_context.get_domain_home()
132+
saml2_security_helper = Saml2SecurityHelper(domain_home, self._exception_type)
133+
saml2_security_helper.extract_initialization_files(self.archive_helper)
134+
129135
def update_machines_clusters_and_servers(self, delete_now=True):
130136
"""
131137
Update the main topology components, the components that are used as targets

core/src/main/python/wlsdeploy/tool/discover/topology_discoverer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from wlsdeploy.logging.platform_logger import PlatformLogger
2525
from wlsdeploy.tool.discover import discoverer
2626
from wlsdeploy.tool.discover.discoverer import Discoverer
27+
from wlsdeploy.tool.util.saml2_security_helper import Saml2SecurityHelper
2728
from wlsdeploy.tool.util.variable_injector import VARIABLE_SEP
2829
from wlsdeploy.tool.util.wlst_helper import WlstHelper
2930
from wlsdeploy.util import dictionary_utils
@@ -132,6 +133,9 @@ def discover(self):
132133
if current_tree is not None:
133134
current_tree()
134135

136+
saml2_security_helper = Saml2SecurityHelper(self._model_context.get_domain_home(), ExceptionType.DISCOVER)
137+
saml2_security_helper.discover_initialization_files(self._model_context.get_archive_file(), self)
138+
135139
_logger.exiting(class_name=_class_name, method_name=_method_name)
136140
return self._dictionary
137141

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
"""
2+
Copyright (c) 2023, 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+
import os.path
6+
7+
from oracle.weblogic.deploy.util import WLSDeployArchive
8+
9+
from wlsdeploy.logging.platform_logger import PlatformLogger
10+
from wlsdeploy.util import dictionary_utils
11+
from wlsdeploy.util import string_utils
12+
13+
DOMAIN_SECURITY_FOLDER = 'security'
14+
IDP_FILE_PREFIX = 'saml2idppartner'
15+
IDP_PARTNERS_KEY = 'saml2.idp.partners'
16+
SP_FILE_PREFIX = 'saml2sppartner'
17+
SP_PARTNERS_KEY = 'saml2.sp.partners'
18+
19+
20+
class Saml2SecurityHelper(object):
21+
"""
22+
Supports discover and create/deploy/update of SAML2 security initialization data files
23+
"""
24+
_class_name = 'Saml2SecurityHelper'
25+
26+
def __init__(self, domain_home, exception_type):
27+
"""
28+
Initialize an instance of Saml2SecurityHelper.
29+
:param domain_home: used locate security files
30+
:param exception_type: the type of exception to be thrown
31+
"""
32+
self._domain_home = domain_home
33+
self._domain_security_directory = os.path.join(self._domain_home, DOMAIN_SECURITY_FOLDER)
34+
self._exception_type = exception_type
35+
self._logger = PlatformLogger('wlsdeploy.tool.util')
36+
37+
def extract_initialization_files(self, archive_helper):
38+
"""
39+
Extract initialization files from the archive to the security directory.
40+
:param archive_helper: used to find initialization files in archive
41+
"""
42+
self._extract_initialization_files(IDP_FILE_PREFIX, IDP_PARTNERS_KEY, archive_helper)
43+
self._extract_initialization_files(SP_FILE_PREFIX, SP_PARTNERS_KEY, archive_helper)
44+
45+
def _extract_initialization_files(self, prefix, partners_key, archive_helper):
46+
"""
47+
Extract initialization files for a specific prefix.
48+
Don't install any files if the <prefix>initialized file exists in the security directory
49+
:param prefix: the prefix of the "initialized" and "properties" file names
50+
:param partners_key: the key in the properties file that contains the partner IDs
51+
:param archive_helper: used to find initialization files
52+
"""
53+
_method_name = '_install_initialization_files'
54+
55+
properties_file_name = prefix + '.properties'
56+
properties_path = WLSDeployArchive.getSaml2DataArchivePath(properties_file_name)
57+
if archive_helper and archive_helper.contains_file(properties_path):
58+
# if the "initialized" file is present, don't extract files
59+
initialized_file = properties_file_name + '.initialized'
60+
initialized_path = os.path.join(self._domain_security_directory, initialized_file)
61+
if os.path.isfile(initialized_path):
62+
self._logger.info('WLSDPLY-23000', properties_file_name, initialized_file,
63+
class_name=self._class_name, method_name=_method_name)
64+
else:
65+
# extract the properties file, the read it to determine metadata files
66+
self._logger.info('WLSDPLY-23001', properties_file_name, class_name=self._class_name,
67+
method_name=_method_name)
68+
archive_helper.extract_file(properties_path, self._domain_security_directory)
69+
self._extract_metadata_files(properties_file_name, partners_key, archive_helper)
70+
71+
def _extract_metadata_files(self, properties_file_name, partners_key, archive_helper):
72+
"""
73+
Extract metadata files specified in the properties file.
74+
:param properties_file_name: the name of the properties file containing the metadata file names
75+
:param partners_key: the key in the properties file that contains the partner IDs
76+
:param archive_helper: used to find metadata files
77+
"""
78+
_method_name = '_install_metadata_files'
79+
80+
properties_file = os.path.join(self._domain_security_directory, properties_file_name)
81+
metadata_file_names = self._get_metadata_file_names(properties_file, partners_key)
82+
for metadata_file_name in metadata_file_names:
83+
metadata_file = WLSDeployArchive.getSaml2DataArchivePath(metadata_file_name)
84+
85+
if archive_helper.contains_file(metadata_file):
86+
self._logger.info('WLSDPLY-23002', metadata_file_name, class_name=self._class_name,
87+
method_name=_method_name)
88+
archive_helper.extract_file(metadata_file, self._domain_security_directory)
89+
else:
90+
self._logger.severe('WLSDPLY-23003', metadata_file_name, properties_file,
91+
class_name=self._class_name, method_name=_method_name)
92+
93+
def discover_initialization_files(self, archive, discoverer):
94+
"""
95+
Add initialization files from the security directory to the archive.
96+
:param archive: WLSDeployArchive instance used to add files
97+
:param discoverer: used to collect remote files when no archive is specified
98+
"""
99+
self._discover_initialization_files(IDP_FILE_PREFIX, IDP_PARTNERS_KEY, archive, discoverer)
100+
self._discover_initialization_files(SP_FILE_PREFIX, SP_PARTNERS_KEY, archive, discoverer)
101+
102+
def _discover_initialization_files(self, prefix, partners_key, archive, discoverer):
103+
"""
104+
Add initialization files for a specific prefix to the archive.
105+
:param prefix: the prefix of the "properties" file name
106+
:param partners_key: the key in the properties file that contains the partner IDs
107+
:param archive: WLSDeployArchive instance used to add files
108+
:param discoverer: used to collect remote files when no archive is specified
109+
"""
110+
_method_name = '_discover_initialization_files'
111+
112+
properties_file_name = prefix + '.properties'
113+
properties_file = os.path.join(self._domain_security_directory, properties_file_name)
114+
if os.path.isfile(properties_file):
115+
if archive:
116+
self._logger.info('WLSDPLY-23005', properties_file_name, class_name=self._class_name,
117+
method_name=_method_name)
118+
archive.addSaml2DataFile(properties_file, True)
119+
else:
120+
# if -skip_archive or -remote, add to the remote map for manual addition
121+
discoverer.add_to_remote_map(properties_file,
122+
WLSDeployArchive.getSaml2DataArchivePath(properties_file_name),
123+
WLSDeployArchive.ArchiveEntryType.SAML2_DATA.name())
124+
125+
# check for metadata files, even if archive not specified
126+
self._discover_metadata_files(properties_file, partners_key, archive, discoverer)
127+
128+
def _discover_metadata_files(self, properties_file_name, partners_key, archive, discoverer):
129+
"""
130+
Add metadata files specified in the properties file to the archive.
131+
:param properties_file_name: the name of the "properties" file
132+
:param partners_key: the key in the properties file that contains the partner IDs
133+
:param archive: WLSDeployArchive instance used to add files
134+
:param discoverer: used to collect remote files when no archive is specified
135+
"""
136+
_method_name = '_discover_metadata_files'
137+
138+
properties_file = os.path.join(self._domain_security_directory, properties_file_name)
139+
metadata_file_names = self._get_metadata_file_names(properties_file, partners_key)
140+
for metadata_file_name in metadata_file_names:
141+
metadata_file = os.path.join(self._domain_security_directory, metadata_file_name)
142+
if not os.path.isfile(metadata_file):
143+
self._logger.severe('WLSDPLY-23007', metadata_file_name, properties_file_name,
144+
class_name=self._class_name, method_name=_method_name)
145+
elif archive:
146+
self._logger.info('WLSDPLY-23006', metadata_file_name, class_name=self._class_name,
147+
method_name=_method_name)
148+
archive.addSaml2DataFile(metadata_file, True)
149+
else:
150+
# if -skip_archive or -remote, add to the remote map for manual addition
151+
discoverer.add_to_remote_map(metadata_file,
152+
WLSDeployArchive.getSaml2DataArchivePath(metadata_file_name),
153+
WLSDeployArchive.ArchiveEntryType.SAML2_DATA.name())
154+
155+
def _get_metadata_file_names(self, properties_file, partners_key):
156+
"""
157+
Get the metadata files names from the specified properties file.
158+
:param properties_file: the properties file to be examined
159+
:param partners_key: the key in the properties file that contains the partner IDs
160+
:return: a list of metadata file names
161+
"""
162+
_method_name = '_get_metadata_file_names'
163+
164+
metadata_file_names = []
165+
properties = string_utils.load_properties(properties_file, self._exception_type)
166+
partners_text = dictionary_utils.get_element(properties, partners_key)
167+
if partners_text:
168+
partner_ids = partners_text.split(',')
169+
for partner_id in partner_ids:
170+
metadata_key = partner_id.strip() + '.metadata.file'
171+
metadata_file_name = dictionary_utils.get_element(properties, metadata_key)
172+
if metadata_file_name:
173+
metadata_file_names.append(metadata_file_name)
174+
else:
175+
self._logger.severe('WLSDPLY-23004', metadata_key, properties_file, class_name=self._class_name,
176+
method_name=_method_name)
177+
return metadata_file_names

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,17 @@ WLSDPLY-21003=Issue Log for {0} version {1} running WebLogic version {2} {3} mod
18261826

18271827
WLSDPLY-22000={0} has been deprecated and will be removed in a future release, please use {1} instead
18281828

1829+
# wlsdeploy/tool/util/saml2_security_helper.py
1830+
1831+
WLSDPLY-23000=Skipping deployment of SAML2 initialization file {0} because {1} is present in the domain
1832+
WLSDPLY-23001=Extracting SAML2 initialization file {0}
1833+
WLSDPLY-23002=Extracting SAML2 initialization metadata file {0}
1834+
WLSDPLY-23003=Unable to extract SAML2 initialization metadata file {0} specified in properties file {1}
1835+
WLSDPLY-23004=Metadata key {0} was not found in SAML2 initialization file {1}
1836+
WLSDPLY-23005=Adding SAML2 initialization file {0} to archive
1837+
WLSDPLY-23006=Adding SAML2 initialization metadata file {0} to archive
1838+
WLSDPLY-23007=SAML2 initialization metadata file {0} specified in properties file {1} was not found
1839+
18291840
####################################################################
18301841
# Message number 30000 - 30999 Archive Helper #
18311842
####################################################################

0 commit comments

Comments
 (0)