forked from WASdev/sample.wsadmin.websphere-traditional
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployOidc.py
275 lines (248 loc) · 10.2 KB
/
deployOidc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#
# OIDC TAI EAR deployment/uninstall script, rev 1.1 8/29/2022
#
# Written by Barbara Jensen
# Based on deployConsole.py
#
# Copyright 2006,2022 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#------------------------------------------------------------------------------
# This script is to install/uninstall the OIDC TAI EAR as an admin
# application
#
# Install:
# wsadmin.sh -f deployOidc.py install
#
# Uninstall:
# wsadmin.sh -f deployOidc.py uninstall
#
#------------------------------------------------------------------------------
import sys
#------------------------------------------------------------------------------
# Get the directory, as a string, where WAS is installed.
#------------------------------------------------------------------------------
def getWASHome(cell, node):
varMap = AdminConfig.getid("/Cell:" + cell + "/Node:" + node + "/VariableMap:/")
entries = AdminConfig.list("VariableSubstitutionEntry", varMap)
eList = entries.splitlines()
for entry in eList:
name = AdminConfig.showAttribute(entry, "symbolicName")
if name == "WAS_INSTALL_ROOT":
value = AdminConfig.showAttribute(entry, "value")
return value
#failover
return java.lang.System.getenv('WAS_HOME')
#------------------------------------------------------------------------------
# Get the WAS systemApps directory.
#
# The WAS systemApps directory is always located at <WAS_HOME>/systemApps
#------------------------------------------------------------------------------
def getSystemAppsDir(cell, node):
fileSep = getFileSep(node)
return getWASHome(cell, node) + fileSep + "systemApps"
def getInstAppsDir(cell, node):
fileSep = getFileSep(node)
return getWASHome(cell, node) + fileSep + "installableApps"
#------------------------------------------------------------------------------
# Get the directory, as a string, of the WebSphereOIDCRP.ear application.
#
# The WebSphereOIDCRP.ear is located in <WAS_HOME>/systemApps/WebSphereOIDCRP.ear
#------------------------------------------------------------------------------
def getEARDir(cell, node):
fileSep = getFileSep(node)
return getInstAppsDir(cell, node) + fileSep + "WebSphereOIDCRP.ear"
#------------------------------------------------------------------------------
# Get the file separator character
#
# This gets the file separator for the node in which we plan to install the
# console. Therefore we can't just use the value that python on Java gives
# us. Instead, check the platform of the node, and use "\" for windows and
# "/" for everything else.
#------------------------------------------------------------------------------
def getFileSep(node):
os = AdminTask.getNodePlatformOS("-nodeName " + node)
if os == 'windows':
return '\\'
else:
return '/'
#------------------------------------------------------------------------------
# updateDeploymentXml
# sharedLibBypass = true
# Console doesn't work with enableSecurityIntegration=true
# Default cookie path should be /ibm
#------------------------------------------------------------------------------
def updateDeploymentXml():
try:
print "Updating deployment.xml"
WebSphereOIDCRP = AdminConfig.getid("/Deployment:WebSphereOIDCRP_Admin/")
WebSphereOIDCRPDepObject = AdminConfig.showAttribute(WebSphereOIDCRP, "deployedObject")
prop = [['name', 'com.ibm.ws.classloader.sharedLibBypass'], ['value', 'true'], ['required', 'false']]
AdminConfig.create("Property", WebSphereOIDCRPDepObject, prop)
attr1 = ['enableSecurityIntegration', 'false']
attrs = [attr1]
sessionMgr = [['sessionManagement', attrs]]
configs = AdminConfig.showAttribute (WebSphereOIDCRPDepObject, "configs")
appConfig = configs[1:len(configs)-1]
SM = AdminConfig.showAttribute (appConfig, 'sessionManagement')
AdminConfig.modify (SM, attrs)
kuke = AdminConfig.showAttribute (SM, 'defaultCookieSettings')
kukeAttrs = [['path', '/ibm']]
AdminConfig.modify(kuke, kukeAttrs)
return 1
except:
print "Error during updateDeploymentXml():", sys.exc_info()
return 0
#------------------------------------------------------------------------------
# setupIEHSClassloader
# Set the classloader for IEHS to PARENT_LAST
#------------------------------------------------------------------------------
def setupIEHSClassloader():
print "Setting IEHS classloader to PARENT_LAST"
WebSphereOIDCRP = AdminConfig.getid("/Deployment:WebSphereOIDCRP_Admin/")
WebSphereOIDCRPDepObject = AdminConfig.showAttribute(WebSphereOIDCRP, "deployedObject")
modules = AdminConfig.list("WebModuleDeployment", WebSphereOIDCRPDepObject).splitlines()
for module in modules:
if AdminConfig.showAttribute(module, "uri") == "com.ibm.ws.security.oidc.servlet.war":
AdminConfig.modify(module, [['classloaderMode', 'PARENT_LAST']])
return 1
#return 0 for failure
return 0
#------------------------------------------------------------------------------
# setCellVar
#------------------------------------------------------------------------------
def setCellVar(cell):
try:
varMap = AdminConfig.getid("/Cell:" + cell + "/VariableMap:/")
prop = [[['symbolicName', 'WAS_CELL_NAME'], ['value', cell]]]
AdminConfig.modify(varMap, [['entries', prop]])
return 1
except:
print "Error during setCellVar(" + cell + "):", sys.exc_info()
return 0
#------------------------------------------------------------------------------
# deployAdminConsole
# Deploy the WebSphereOIDCRP.ear using the AdminApp install command, and then map it
# to the admin_host virtual host.
#------------------------------------------------------------------------------
def deployOidcEar(cell, node, server, type):
earDir = getEARDir(cell, node)
sysAppDir = getSystemAppsDir(cell, node)
try:
print "Deploying WebSphereOIDCRP.ear"
AdminApp.install(earDir, ['-node', node, '-server', server, '-appname', 'WebSphereOIDCRP_Admin', '-usedefaultbindings', '-copy.sessionmgr.servername', server, '-skipPreparation', '-installed.ear.destination', '$(WAS_INSTALL_ROOT)/systemApps'])
#Do virtual host mapping
print "Mapping WebSphereOIDCRP_Admin to admin_host"
AdminApp.edit('WebSphereOIDCRP_Admin', ['-MapWebModToVH', [['.*', '.*', 'admin_host']]])
except:
error = str(sys.exc_info()[1])
if error.count("7279E") > 0: # catch WASX7279E (app with given name already exists)
print "The OIDC TAI EAR is already installed."
else:
print "Exception occurred during deployOidcEar(" + cell +", " + node + ", " + server + "):", error
return 0
return 1
#------------------------------------------------------------------------------
# Get a tuple containing the cell, node, server name, and type
#------------------------------------------------------------------------------
def getCellNodeServer():
servers = AdminConfig.list("Server").splitlines()
for serverId in servers:
serverName = serverId.split("(")[0]
server = serverId.split("(")[1] #remove name( from id
server = server.split("/")
cell = server[1]
node = server[3]
cellId = AdminConfig.getid("/Cell:" + cell + "/")
cellType = AdminConfig.showAttribute(cellId, "cellType")
if cellType == "DISTRIBUTED":
if AdminConfig.showAttribute(serverId, "serverType") == "DEPLOYMENT_MANAGER":
return (cell, node, serverName, "DEPLOYMENT_MANAGER")
elif cellType == "STANDALONE":
if AdminConfig.showAttribute(serverId, "serverType") == "APPLICATION_SERVER":
return (cell, node, serverName, "APPLICATION_SERVER")
elif AdminConfig.showAttribute(serverId, "serverType") == "ADMIN_AGENT":
return (cell, node, serverName, "ADMIN_AGENT")
return None
#------------------------------------------------------------------------------
# Print script usage
#------------------------------------------------------------------------------
def printUsage():
print "Usage: wsadmin deployOidc.py install"
print " or: wsadmin deployOidc.py uninstall"
print ""
#------------------------------------------------------------------------------
# Install the the OIDC TAI EAR
#------------------------------------------------------------------------------
def doInstall():
topology = getCellNodeServer()
if topology == None:
sys.stderr.write("Could not find suitable server\n")
if failOnError == "true":
sys.exit(105)
else:
cell = topology[0]
node = topology[1]
server = topology[2]
type = topology[3]
retVal = deployOidcEar(cell, node, server, type)
if retVal == 1:
retVal = updateDeploymentXml()
#if retVal == 1:
# retVal = setCellVar(cell)
if retVal == 1:
retVal = setupIEHSClassloader()
if retVal == 1:
AdminConfig.save()
else:
print "Skipping Config Save"
if failOnError == "true":
sys.exit(109)
#------------------------------------------------------------------------------
# Uninstall the the OIDC TAI EAR
#------------------------------------------------------------------------------
def doRemove():
AdminApp.uninstall("WebSphereOIDCRP_Admin")
AdminConfig.save()
#------------------------------------------------------------------------------
# Main entry point
#------------------------------------------------------------------------------
failOnError = "false"
if len(sys.argv) < 1 or len(sys.argv) > 2:
sys.stderr.write("Invalid number of arguments\n")
printUsage()
sys.exit(101)
else:
if len(sys.argv) == 2:
if sys.argv[1] == "-failonerror":
failOnError = "true"
print "failonerror is enabled"
else:
sys.stderr.write("Invalid option: " + sys.argv[1] + "\n")
printUsage()
sys.exit(102)
mode = sys.argv[0]
if mode == "install":
print "Installing the OIDC TAI EAR as an Admin app"
doInstall()
elif mode == "remove":
print "Removing the OIDC TAI EAR Admin app"
doRemove()
elif mode == "uninstall":
print "Removing the OIDC TAI EAR Admin app"
doRemove()
else:
sys.stderr.write("Invalid command: " + mode + "\n")
printUsage()
if failOnError == "true":
sys.exit(103)