Skip to content

Commit aa4573e

Browse files
committed
Merge branch 'password-validation-fixes' into 'main'
cleaning up password validation See merge request weblogic-cloud/weblogic-deploy-tooling!1539
2 parents 6dcd249 + 2aab8b2 commit aa4573e

File tree

20 files changed

+191
-130
lines changed

20 files changed

+191
-130
lines changed

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<parent>
1212
<artifactId>weblogic-deploy</artifactId>
1313
<groupId>com.oracle.weblogic.lifecycle</groupId>
14-
<version>3.4.1-SNAPSHOT</version>
14+
<version>3.5.0-SNAPSHOT</version>
1515
<relativePath>../pom.xml</relativePath>
1616
</parent>
1717

core/src/main/java/oracle/weblogic/deploy/validate/PasswordValidator.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
package oracle.weblogic.deploy.validate;
66

77
import java.util.HashMap;
8+
import java.util.HashSet;
89
import java.util.Map;
10+
import java.util.Set;
911

1012
import oracle.weblogic.deploy.logging.PlatformLogger;
1113
import oracle.weblogic.deploy.logging.WLSDeployLogFactory;
@@ -37,14 +39,19 @@ public class PasswordValidator {
3739
private static final char[] DISALLOWED_PASSWORD_START_CHARACTERS = { '{' };
3840

3941
private final Map<String, Object> config;
42+
private final Map<String, Object> cieDefaults;
43+
private final Set<String> notifications;
4044

4145
/**
4246
* The constructor.
4347
*
44-
* @param config a map of the configuration values
48+
* @param config a map of the configuration values from the model
49+
* @param cieDefaults a map of the default values from the aliases
4550
*/
46-
public PasswordValidator(Map<String, Object> config) {
51+
public PasswordValidator(Map<String, Object> config, Map<String, Object> cieDefaults) {
4752
this.config = config;
53+
this.cieDefaults = cieDefaults;
54+
this.notifications = new HashSet<>();
4855
}
4956

5057
/**
@@ -297,6 +304,20 @@ private int getIntegerFieldConfiguration(String fieldName) {
297304
result = (int) value;
298305
}
299306
}
307+
if (cieDefaults.containsKey(fieldName)) {
308+
Object value = cieDefaults.get(fieldName);
309+
if (Integer.class.isAssignableFrom(value.getClass())) {
310+
int cieDefault = (int) value;
311+
312+
if (cieDefault > result) {
313+
if (result != NO_RESTRICTION && !notifications.contains(fieldName)) {
314+
LOGGER.notification("WLSDPLY-05415", fieldName, result, cieDefault);
315+
notifications.add(fieldName);
316+
}
317+
result = cieDefault;
318+
}
319+
}
320+
}
300321
return result;
301322
}
302323

@@ -305,7 +326,12 @@ private boolean getBooleanFieldConfiguration(String fieldName) {
305326
if (config.containsKey(fieldName)) {
306327
Object value = config.get(fieldName);
307328
if (Boolean.class.isAssignableFrom(value.getClass())) {
308-
result = (boolean) value;
329+
result = (Boolean) value;
330+
}
331+
} else if (cieDefaults.containsKey(fieldName)) {
332+
Object value = cieDefaults.get(fieldName);
333+
if (Boolean.class.isAssignableFrom(value.getClass())) {
334+
result = (Boolean) value;
309335
}
310336
}
311337
return result;

core/src/main/python/create.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,6 @@ def main(model_context):
371371

372372
# check for any content problems in the merged, substituted model
373373
content_validator = ContentValidator(model_context, aliases)
374-
# password validation errors are fatal and will raise a CreateException if any are found.
375-
content_validator.validate_user_passwords(model_dictionary)
376374
content_validator.validate_model(model_dictionary)
377375

378376
archive_helper = None

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

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
"""
2-
Copyright (c) 2021, 2022, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2021, 2023, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
5-
import com.octetstring.vde.util.PasswordEncryptor as PasswordEncryptor
6-
import com.bea.security.xacml.cache.resource.ResourcePolicyIdUtil as ResourcePolicyIdUtil
75
from java.io import File
8-
from java.lang import String
9-
import java.util.regex.Pattern as Pattern
106

11-
import oracle.weblogic.deploy.aliases.TypeUtils as TypeUtils
7+
from com.octetstring.vde.util import PasswordEncryptor
8+
from com.bea.security.xacml.cache.resource import ResourcePolicyIdUtil
9+
from oracle.weblogic.deploy.aliases import TypeUtils
10+
from oracle.weblogic.deploy.create import CreateException
1211

1312
from wlsdeploy.aliases.model_constants import DESCRIPTION
1413
from wlsdeploy.aliases.model_constants import GROUP
@@ -69,7 +68,8 @@ def create_default_init_file(self, security_mapping_nodes):
6968
output_dir = File(self._model_context.get_domain_home(), SECURITY_SUBDIR)
7069
output_file = File(output_dir, DEFAULT_AUTH_INIT_FILE)
7170

72-
self._logger.info('WLSDPLY-01900', output_file, class_name=self._class_name, method_name=_method_name)
71+
self._logger.info('WLSDPLY-01900', output_file,
72+
class_name=self._class_name, method_name=_method_name)
7373

7474
file_template_helper.append_file_from_resource(template_path, template_hash, output_file, self._exception_type)
7575

@@ -79,6 +79,7 @@ def _build_default_template_hash(self, mapping_section_nodes):
7979
:param mapping_section_nodes: the security elements from the model
8080
:return: the template hash dictionary
8181
"""
82+
_method_name = '_build_default_template_hash'
8283
template_hash = dict()
8384

8485
group_mappings = []
@@ -92,8 +93,12 @@ def _build_default_template_hash(self, mapping_section_nodes):
9293
if USER in mapping_section_nodes.keys():
9394
user_mapping_nodes = mapping_section_nodes[USER]
9495
for name in user_mapping_nodes:
95-
mapping_hash = self._build_user_mapping_hash(user_mapping_nodes[name], name)
96-
user_mappings.append(mapping_hash)
96+
try:
97+
mapping_hash = self._build_user_mapping_hash(user_mapping_nodes[name], name)
98+
user_mappings.append(mapping_hash)
99+
except CreateException, ce:
100+
self._logger.warning('WLSDPLY-01902', name, ce.getLocalizedMessage(),
101+
error=ce, class_name=self._class_name, method_name=_method_name)
97102

98103
template_hash[GROUP_MAPPINGS] = group_mappings
99104
template_hash[USER_MAPPINGS] = user_mappings
@@ -110,7 +115,10 @@ def _build_group_mapping_hash(self, group_mapping_section, name):
110115
hash_entry[HASH_NAME] = name
111116
group_attributes = group_mapping_section
112117
description = dictionary_utils.get_element(group_attributes, DESCRIPTION)
113-
hash_entry[HASH_DESCRIPTION] = description
118+
if description is not None:
119+
hash_entry[HASH_DESCRIPTION] = description
120+
else:
121+
hash_entry[HASH_DESCRIPTION] = ''
114122
groups = dictionary_utils.get_element(group_attributes, GROUP_MEMBER_OF)
115123
group_list = []
116124
group_mappings = list()
@@ -148,12 +156,16 @@ def _build_user_mapping_hash(self, user_mapping_section, name):
148156
:param user_mapping_section: The security user section from the model
149157
:param name: name of the user for the user section
150158
:return: template hash map
159+
:raises: CreateException if the user's password cannot be encoded
151160
"""
152161
hash_entry = dict()
153162
hash_entry[HASH_NAME] = name
154163
group_attributes = user_mapping_section
155164
description = dictionary_utils.get_element(group_attributes, DESCRIPTION)
156-
hash_entry[HASH_DESCRIPTION] = description
165+
if description is not None:
166+
hash_entry[HASH_DESCRIPTION] = description
167+
else:
168+
hash_entry[HASH_DESCRIPTION] = ''
157169
groups = dictionary_utils.get_element(group_attributes, GROUP_MEMBER_OF)
158170
password = self._get_required_attribute(user_mapping_section, PASSWORD, USER, name)
159171
password = self._aliases.decrypt_password(password)
@@ -175,17 +187,15 @@ def _build_user_mapping_hash(self, user_mapping_section, name):
175187
return hash_entry
176188

177189
def _encode_password(self, user, password):
178-
pwd_pattern = '[\\!a-zA-Z]{1,}'
179-
matches = Pattern.matches(pwd_pattern, password)
180-
if len(password) < 8 or matches:
181-
self._logger.warning('WLSDPLY-01902', user)
182-
return None
190+
_method_name = '_encode_password'
183191
try:
184192
encrypted_pass = PasswordEncryptor.doSSHA256(password)
185193
encrypted_pass = "{ssha256}" + encrypted_pass
186194
except Exception, e:
187-
self._logger.warning('WLSDPLY-01901', user, e)
188-
return None
195+
ex = exception_helper.create_create_exception('WLSDPLY-01901',user, e.getLocalizedMessage(),
196+
error=e)
197+
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
198+
raise ex
189199
return encrypted_pass
190200

191201
def _get_required_attribute(self, dictionary, name, mapping_type, mapping_name):

0 commit comments

Comments
 (0)