2
2
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
3
3
The Universal Permissive License (UPL), Version 1.0
4
4
"""
5
+ from java .lang import IllegalArgumentException , IllegalAccessException
6
+ from java .lang .reflect import InvocationTargetException
7
+ from oracle .weblogic .deploy .util import ConvertUtils
5
8
9
+ from wlsdeploy .exception import exception_helper
6
10
from wlsdeploy .tool .util .alias_helper import AliasHelper
7
11
from wlsdeploy .tool .util .wlst_helper import WlstHelper
12
+ from wlsdeploy .util .weblogic_helper import WebLogicHelper
8
13
9
14
10
15
class CustomFolderHelper (object ):
@@ -18,6 +23,7 @@ def __init__(self, aliases, logger, exception_type):
18
23
self .logger = logger
19
24
self .exception_type = exception_type
20
25
self .alias_helper = AliasHelper (aliases , self .logger , self .exception_type )
26
+ self .weblogic_helper = WebLogicHelper (self .logger )
21
27
self .wlst_helper = WlstHelper (self .logger , self .exception_type )
22
28
23
29
def update_security_folder (self , location , model_category , model_type , model_name , model_nodes ):
@@ -39,7 +45,80 @@ def update_security_folder(self, location, model_category, model_type, model_nam
39
45
self .logger .info ('WLSDPLY-12124' , model_category , model_name , model_type , location_path ,
40
46
class_name = self .__class_name , method_name = _method_name )
41
47
48
+ create_path = self .alias_helper .get_wlst_subfolders_path (location )
49
+ self .wlst_helper .cd (create_path )
50
+
51
+ # TODO for updateDomain: check for existing provider, just cd if present
52
+
42
53
# create the MBean using the model name, model_type, category
43
54
44
- # wlst.create(model_name, model_type, category)
45
- # wlst.create('RAK-SAML', 'SAMLAuthenticator', 'AuthenticationProvider')
55
+ self .wlst_helper .create (model_name , model_type , model_category )
56
+
57
+ provider_path = create_path + '/' + model_category + '/' + model_name
58
+ provider_mbean = self .wlst_helper .cd (provider_path )
59
+
60
+ interface_name = model_type + 'MBean'
61
+ bean_info = self .weblogic_helper .get_bean_info_for_interface (interface_name )
62
+ if bean_info is None :
63
+ ex = exception_helper .create_exception (self .exception_type , 'WLSDPLY-12125' , interface_name )
64
+ self .logger .throwing (ex , class_name = self .__class_name , method_name = _method_name )
65
+ raise ex
66
+
67
+ property_map = dict ()
68
+ for property_descriptor in bean_info .getPropertyDescriptors ():
69
+ self .logger .finer ('WLSDPLY-12126' , str (property_descriptor ), class_name = self .__class_name ,
70
+ method_name = _method_name )
71
+ property_map [property_descriptor .getName ()] = property_descriptor
72
+
73
+ for model_key in model_nodes :
74
+ model_value = model_nodes [model_key ]
75
+ property_descriptor = property_map .get (model_key )
76
+
77
+ if not property_descriptor :
78
+ ex = exception_helper .create_exception (self .exception_type , 'WLSDPLY-12128' , model_key )
79
+ self .logger .throwing (ex , class_name = self .__class_name , method_name = _method_name )
80
+ raise ex
81
+
82
+ # find the setter method for the attribute
83
+
84
+ method = property_descriptor .writeMethod
85
+ if not method :
86
+ # this must be a read-only attribute, just log it and continue with next attribute
87
+ self .logger .info ('WLSDPLY-12129' , str (model_key ), class_name = self .__class_name ,
88
+ method_name = _method_name )
89
+ continue
90
+
91
+ self .logger .finer ('WLSDPLY-12127' , str (model_key ), str (model_value ), class_name = self .__class_name ,
92
+ method_name = _method_name )
93
+
94
+ # determine the data type from the set method
95
+
96
+ parameter_types = method .getParameterTypes ()
97
+ parameter_count = len (parameter_types )
98
+
99
+ if parameter_count != 1 :
100
+ ex = exception_helper .create_exception (self .exception_type , 'WLSDPLY-12130' , model_key ,
101
+ parameter_count )
102
+ self .logger .throwing (ex , class_name = self .__class_name , method_name = _method_name )
103
+ raise ex
104
+
105
+ property_type = parameter_types [0 ]
106
+
107
+ # convert the model value to the target type
108
+
109
+ set_value = ConvertUtils .convertValue (model_value , property_type )
110
+ if set_value is None :
111
+ ex = exception_helper .create_exception (self .exception_type , 'WLSDPLY-12131' , str (model_value ),
112
+ str (property_type ), model_key )
113
+ self .logger .throwing (ex , class_name = self .__class_name , method_name = _method_name )
114
+ raise ex
115
+
116
+ # call the setter with the target value
117
+
118
+ try :
119
+ method .invoke (provider_mbean , [set_value ])
120
+ except (IllegalAccessException , IllegalArgumentException , InvocationTargetException ), ex :
121
+ ex = exception_helper .create_exception (self .exception_type , 'WLSDPLY-12132' , str (method ),
122
+ str (set_value ), ex .getLocalizedMessage (), error = ex )
123
+ self .logger .throwing (ex , class_name = self .__class_name , method_name = _method_name )
124
+ raise ex
0 commit comments