Skip to content

Commit 80380dc

Browse files
authored
Merge pull request #249 from oracle/Issue#164-support-custom-security-providers
Issue#164 support custom security providers
2 parents 675b47d + 8afbccc commit 80380dc

File tree

23 files changed

+763
-468
lines changed

23 files changed

+763
-468
lines changed

core/src/main/java/oracle/weblogic/deploy/aliases/TypeUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
* The Universal Permissive License (UPL), Version 1.0
44
*/
55
package oracle.weblogic.deploy.aliases;
@@ -32,7 +32,7 @@ public final class TypeUtils {
3232
private static final String CLASS = TypeUtils.class.getName();
3333
private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.util");
3434

35-
private static final String DEFAULT_STRING_LIST_DELIMITOR = ",";
35+
public static final String DEFAULT_STRING_LIST_DELIMITER = ",";
3636

3737
private TypeUtils() {
3838
// hide the constructor for this utility class
@@ -76,7 +76,7 @@ public static Object convertToType(String targetTypeName, Object value) throws A
7676
delimiter = File.pathSeparator;
7777
break;
7878
default:
79-
delimiter = DEFAULT_STRING_LIST_DELIMITOR;
79+
delimiter = DEFAULT_STRING_LIST_DELIMITER;
8080
}
8181
return convertToType(targetTypeName, value, delimiter);
8282
}
@@ -154,7 +154,7 @@ public static Object convertToType(String targetTypeName, Object value, String d
154154
* the conversion.
155155
*/
156156
public static Object convertToType(Class<?> targetType, Object value) throws AliasException {
157-
return convertToType(targetType, value, DEFAULT_STRING_LIST_DELIMITOR);
157+
return convertToType(targetType, value, DEFAULT_STRING_LIST_DELIMITER);
158158
}
159159

160160
/**
@@ -231,7 +231,7 @@ public static Object convertToType(Class<?> targetType, Object value, String del
231231
return result;
232232
}
233233

234-
private static String convertToBoolean(String strValue) {
234+
public static String convertToBoolean(String strValue) {
235235
String result;
236236
switch (strValue.toLowerCase(Locale.ENGLISH)) {
237237
case "1":
@@ -246,7 +246,7 @@ private static String convertToBoolean(String strValue) {
246246
return result;
247247
}
248248

249-
private static Character convertToCharacter(String strValue) {
249+
public static Character convertToCharacter(String strValue) {
250250
Character result = null;
251251
if (strValue.length() > 0) {
252252
result = strValue.charAt(0);
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
* The Universal Permissive License (UPL), Version 1.0
4+
*/
5+
package oracle.weblogic.deploy.util;
6+
7+
import oracle.weblogic.deploy.aliases.TypeUtils;
8+
import oracle.weblogic.deploy.exception.ExceptionHelper;
9+
10+
import java.lang.reflect.Array;
11+
import java.lang.reflect.InvocationTargetException;
12+
import java.lang.reflect.Method;
13+
import java.util.List;
14+
15+
/**
16+
* Utility methods for configuring custom MBeans.
17+
*/
18+
public final class CustomBeanUtils {
19+
20+
private CustomBeanUtils() {
21+
// hide the constructor for this utility class
22+
}
23+
24+
/**
25+
* Invoke the specified set method on the MBean with the provided value, converted to the desired type.
26+
* The conversion and invocation are done together to avoid automatic Jython data conversion.
27+
*
28+
* @param mbean the value to be converted
29+
* @param propertyType the class representing the target type
30+
* @param propertyValue the class representing the target type
31+
* @throws IllegalAccessException if method invocation fails
32+
* @throws IllegalArgumentException if the data conversion or method invocation fails
33+
* @throws InvocationTargetException if method invocation fails
34+
*/
35+
public static void callMethod(Object mbean, Method method, Class<?> propertyType, Object propertyValue)
36+
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
37+
38+
// convert the specified property value to the desired type
39+
Object setValue = CustomBeanUtils.convertValue(propertyValue, propertyType);
40+
41+
// call the setter with the target value
42+
method.invoke(mbean, setValue);
43+
}
44+
45+
/**
46+
* Convert the specified value to the specified type.
47+
* The conversions and available types are specific to user-defined custom mbeans.
48+
*
49+
* @param value the value to be converted
50+
* @param dataType the class representing the target type
51+
* @throws IllegalArgumentException if the data conversion fails
52+
* @return the value converted to the new type, or null if conversion failed
53+
*/
54+
static Object convertValue(Object value, Class<?> dataType) {
55+
// package private to allow unit test access
56+
57+
Object result;
58+
59+
if (Object[].class.isAssignableFrom(dataType)) {
60+
result = convertArrayValue(value, dataType);
61+
} else {
62+
result = convertSingleValue(value, dataType);
63+
}
64+
65+
return result;
66+
}
67+
68+
/**
69+
* Convert the specified array value to the specified type.
70+
* This may require rebuilding the array with the desired type.
71+
*
72+
* @param value the value to be converted
73+
* @param dataType the class representing the target type
74+
* @throws IllegalArgumentException if the data conversion fails
75+
* @return the value converted to the new type, or null if conversion failed
76+
*/
77+
private static Object convertArrayValue(Object value, Class<?> dataType) {
78+
Class<?> componentType = dataType.getComponentType();
79+
Object[] result;
80+
81+
if (dataType.isAssignableFrom(value.getClass())) {
82+
// the value may already match the target type
83+
result = (Object[]) value;
84+
85+
} else {
86+
// rebuild the array with the target component type and converted elements
87+
Object[] source;
88+
89+
if(Object[].class.isAssignableFrom(value.getClass())) {
90+
source = (Object[]) value;
91+
92+
} else if(value instanceof List) {
93+
// probably a python PyList from model
94+
source = ((List) value).toArray();
95+
96+
} else {
97+
String text = value.toString();
98+
source = text.split(TypeUtils.DEFAULT_STRING_LIST_DELIMITER);
99+
}
100+
101+
Object arrayObject = Array.newInstance(componentType, source.length);
102+
103+
for (int i = 0; i < source.length; i++) {
104+
Object elementValue = convertSingleValue(source[i], componentType);
105+
Array.set(arrayObject, i, elementValue);
106+
}
107+
108+
result = (Object[]) arrayObject;
109+
}
110+
111+
return result;
112+
}
113+
114+
/**
115+
* Convert the specified single value to the specified type.
116+
* This invokes the low-level alias conversion methods, with a few adjustments.
117+
*
118+
* @param value the value to be converted
119+
* @param dataType the class representing the target type
120+
* @throws IllegalArgumentException if the data type is not recognized
121+
* @return the value converted to the new type, or null if conversion failed
122+
*/
123+
private static Object convertSingleValue(Object value, Class<?> dataType) {
124+
if (value == null) {
125+
return null;
126+
}
127+
128+
String textValue;
129+
if (value instanceof char[]) {
130+
textValue = String.valueOf((char[]) value);
131+
} else {
132+
textValue = value.toString().trim();
133+
if (textValue.length() == 0) {
134+
return null;
135+
}
136+
}
137+
138+
// This block of code is similar to the conversion in TypeUtils.convertToType(), but with some differences.
139+
// Custom MBeans only allow a subset of the data types of full alias conversion, and the Java types have to
140+
// be strictly maintained to be passed the the reflected set methods. In addition, convertToType() does not
141+
// convert arrays to the proper data type, so that is handled at a more granular level in this class.
142+
143+
Object result;
144+
145+
try {
146+
if (dataType == String.class) {
147+
result = textValue;
148+
149+
} else if((dataType == Boolean.class) || (dataType == Boolean.TYPE)) {
150+
String booleanText = TypeUtils.convertToBoolean(textValue);
151+
result = Boolean.parseBoolean(booleanText);
152+
153+
} else if(dataType == Integer.class) {
154+
result = Integer.valueOf(textValue);
155+
156+
} else if(dataType == Short.class) {
157+
result = Short.valueOf(textValue);
158+
159+
} else if(dataType == Long.class) {
160+
result = Long.valueOf(textValue);
161+
162+
} else if(dataType == Float.class) {
163+
result = Float.valueOf(textValue);
164+
165+
} else if(dataType == Double.class) {
166+
result = Double.valueOf(textValue);
167+
168+
} else if(dataType == Character.class) {
169+
result = TypeUtils.convertToCharacter(textValue);
170+
171+
} else {
172+
String message = ExceptionHelper.getMessage("WLSDPLY-12132", dataType);
173+
throw new IllegalArgumentException(message);
174+
}
175+
176+
} catch(NumberFormatException nfe) {
177+
String message = ExceptionHelper.getMessage("WLSDPLY-12133", textValue, dataType);
178+
throw new IllegalArgumentException(message);
179+
}
180+
181+
return result;
182+
}
183+
}

core/src/main/python/create.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from wlsdeploy.logging.platform_logger import PlatformLogger
3434
from wlsdeploy.tool.create.domain_creator import DomainCreator
3535
from wlsdeploy.tool.create.domain_typedef import DomainTypedef
36+
from wlsdeploy.tool.create.domain_typedef import CREATE_DOMAIN
3637
from wlsdeploy.tool.util import filter_helper
3738
from wlsdeploy.tool.validate.validator import Validator
3839
from wlsdeploy.util import getcreds
@@ -44,7 +45,8 @@
4445
from wlsdeploy.util.model_translator import FileToPython
4546
from wlsdeploy.util.weblogic_helper import WebLogicHelper
4647

47-
_program_name = 'createDomain'
48+
_program_name = CREATE_DOMAIN
49+
4850
_class_name = 'create'
4951
__logger = PlatformLogger('wlsdeploy.create')
5052
__wlst_mode = WlstModes.OFFLINE

core/src/main/python/discover.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
The Universal Permissive License (UPL), Version 1.0
44
55
The entry point for the discoverDomain tool.
@@ -20,7 +20,6 @@
2020
from oracle.weblogic.deploy.util import TranslateException
2121
from oracle.weblogic.deploy.util import WLSDeployArchive
2222
from oracle.weblogic.deploy.util import WLSDeployArchiveIOException
23-
from oracle.weblogic.deploy.util import WLSDeployExit
2423
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion
2524
from oracle.weblogic.deploy.validate import ValidateException
2625

@@ -72,7 +71,8 @@
7271
CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH,
7372
CommandLineArgUtil.ADMIN_URL_SWITCH,
7473
CommandLineArgUtil.ADMIN_USER_SWITCH,
75-
CommandLineArgUtil.ADMIN_PASS_SWITCH
74+
CommandLineArgUtil.ADMIN_PASS_SWITCH,
75+
CommandLineArgUtil.TARGET_MODE_SWITCH
7676
]
7777

7878

@@ -153,6 +153,7 @@ def __process_online_args(optional_arg_map):
153153
optional_arg_map[CommandLineArgUtil.ADMIN_PASS_SWITCH] = String(password)
154154

155155
mode = WlstModes.ONLINE
156+
optional_arg_map[CommandLineArgUtil.TARGET_MODE_SWITCH] = 'online'
156157
return mode
157158

158159

core/src/main/python/update.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from wlsdeploy.exception.expection_types import ExceptionType
3434
from wlsdeploy.logging.platform_logger import PlatformLogger
3535
from wlsdeploy.tool.create.domain_typedef import DomainTypedef
36+
from wlsdeploy.tool.create.domain_typedef import UPDATE_DOMAIN
3637
from wlsdeploy.tool.deploy import deployer_utils
3738
from wlsdeploy.tool.deploy import model_deployer
3839
from wlsdeploy.tool.deploy.topology_updater import TopologyUpdater
@@ -50,7 +51,7 @@
5051
from wlsdeploy.util.weblogic_helper import WebLogicHelper
5152

5253

53-
_program_name = 'updateDomain'
54+
_program_name = UPDATE_DOMAIN
5455
_class_name = 'update'
5556
__logger = PlatformLogger('wlsdeploy.update')
5657
__wls_helper = WebLogicHelper(__logger)

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,6 @@ def __init__(self, wlst_mode=WlstModes.OFFLINE, wls_version=None):
198198
self._wls_helper = WebLogicHelper(_logger, wls_version)
199199
self._wls_version = wls_version
200200

201-
if self._wlst_mode == WlstModes.OFFLINE:
202-
self._requires_security_provider_rename = \
203-
self._wls_helper.requires_security_provider_rename_in_offline_mode()
204-
else:
205-
self._requires_security_provider_rename = False
206201
return
207202

208203
def get_dictionary_for_location(self, location, resolve=True):
@@ -664,9 +659,6 @@ def get_wlst_mbean_type_for_location(self, location):
664659
wlst_type = None
665660
elif WLST_TYPE in folder_dict:
666661
wlst_type = folder_dict[WLST_TYPE]
667-
if self._requires_security_provider_rename and alias_utils.is_security_provider_location(location) and \
668-
wlst_type in SECURITY_PROVIDER_NAME_MAP:
669-
wlst_type = SECURITY_PROVIDER_NAME_MAP[wlst_type]
670662
else:
671663
ex = exception_helper.create_alias_exception('WLSDPLY-08106', location.get_folder_path(), WLST_TYPE)
672664
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,18 @@ def is_artificial_type_folder(self, location):
271271
"""
272272
return self._alias_entries.is_location_child_folder_type(location, ChildFoldersTypes.NONE)
273273

274+
def is_custom_folder_allowed(self, location):
275+
"""
276+
Returns true if the specified location allows custom, user-defined folder types.
277+
This currently corresponds to all MULTIPLE_WITH_TYPE_SUBFOLDER entries.
278+
This will need to be refined if new custom types are added, or additional distinctions are required.
279+
:param location: the location to be checked
280+
:return: True if the location allows custom folder types, False otherwise
281+
:raises: AliasException: if an error occurs while getting the folder for the location
282+
"""
283+
return self._alias_entries.is_location_child_folder_type(location,
284+
ChildFoldersTypes.MULTIPLE_WITH_TYPE_SUBFOLDER)
285+
274286
###########################################################################
275287
# WLST Folder create-related methods #
276288
###########################################################################

0 commit comments

Comments
 (0)