-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathflex_setup.py
More file actions
858 lines (670 loc) · 35.7 KB
/
flex_setup.py
File metadata and controls
858 lines (670 loc) · 35.7 KB
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
#!/usr/bin/python3
import sys
import os
import zipfile
import argparse
import time
import glob
import code
import configparser
import subprocess
import shutil
import tempfile
import json
import uuid
from pathlib import Path
from urllib import request
from urllib.parse import urljoin
from xml.etree import ElementTree
argsp = None
cur_dir = os.path.dirname(__file__)
jans_installer_downloaded = bool(os.environ.get('JANS_INSTALLER'))
flex_installer_downloaded = False
install_py_path = os.path.join(cur_dir, 'jans_install.py')
installed_components = {'admin_ui': False, 'casa': False}
jans_config_properties = '/etc/jans/conf/jans.properties'
app_versions = {
"JANS_APP_VERSION": "1.9.0",
"JANS_BUILD": "",
"NODE_VERSION": "v18.16.0"
}
os.environ["FLEX_PRE_JANS"] = "True"
if '--remove-flex' in sys.argv and '--flex-non-interactive' not in sys.argv:
print('\033[31m')
print("This process is irreversible.")
print("Gluu Flex Components will be removed")
print('\033[0m')
print()
while True:
print('\033[31m \033[1m')
response = input("Are you sure to uninstall Gluu Flex? [yes/N] ")
print('\033[0m')
if response.strip().lower() in ('yes', 'n', 'no'):
if response.lower() != 'yes':
sys.exit()
else:
break
else:
print("Please type \033[1m yes \033[0m to uninstall")
def get_flex_setup_parser():
parser = argparse.ArgumentParser(description="This script downloads Gluu Admin UI components and installs")
parser.add_argument('--jans-setup-branch', help="Jannsen setup github branch", default='main')
parser.add_argument('--flex-branch', help="Jannsen flex setup github branch", default='main')
parser.add_argument('--jans-branch', help="Jannsen github branch", default='main')
parser.add_argument('--node-modules-branch', help="Node modules branch. Default to flex setup github branch")
parser.add_argument('--flex-non-interactive', help="Non interactive setup mode", action='store_true')
parser.add_argument('--install-admin-ui', help="Installs Gluu Flex Admin UI", action='store_true')
parser.add_argument('--update-admin-ui', help="Updates Gluu Flex Admin UI", action='store_true')
parser.add_argument('--adminui_authentication_mode', help="Set authserver.acrValues", default='basic',
choices=['basic', 'agama_io.jans.casa.authn.main'])
parser.add_argument('--install-casa', help="Installs casa", action='store_true')
parser.add_argument('--remove-flex', help="Removes flex components", action='store_true')
parser.add_argument('--no-restart-services',
help="Do not restart services, useful when you are both uninstalling flex and Jans",
action='store_true')
parser.add_argument('--gluu-passwurd-cert', help="Creates Gluu Passwurd API keystore", action='store_true')
parser.add_argument('-download-exit', help="Downloads files and exits", action='store_true')
parser.add_argument('--jans-app-verison', help="Jannsen applications version",
default=app_versions['JANS_APP_VERSION'])
parser.add_argument('--jans-app-build', help="Jannsen build", default=app_versions['JANS_BUILD'])
parser.add_argument('--node-version', help="Node version", default=app_versions['NODE_VERSION'])
return parser
__STATIC_SETUP_DIR__ = '/opt/jans/jans-setup/'
profile = None
profile_fn = os.path.join(__STATIC_SETUP_DIR__, 'profile')
if os.path.exists(profile_fn):
with open(profile_fn) as f:
profile = f.read().strip()
print("Profile was detected as \033[1m{}\033[0m.".format(profile))
if os.path.join(__STATIC_SETUP_DIR__, 'flex/flex-linux-setup') == cur_dir:
jans_installer_downloaded = True
flex_installer_downloaded = True
if not jans_installer_downloaded and os.path.exists(__STATIC_SETUP_DIR__):
print("Backing up old Janssen setup directory")
os.system(
'mv {} {}-{}'.format(__STATIC_SETUP_DIR__, __STATIC_SETUP_DIR__.rstrip('/'), time.ctime().replace(' ', '_')))
else:
sys.path.append(__STATIC_SETUP_DIR__)
def download_jans_install_py(setup_branch):
print("Downloading", os.path.basename(install_py_path))
install_url = 'https://raw.githubusercontent.com/JanssenProject/jans/{}/jans-linux-setup/jans_setup/install.py'.format(
setup_branch)
request.urlretrieve(install_url, install_py_path)
if not (jans_installer_downloaded or os.path.exists(jans_config_properties)):
argsp, nargs = get_flex_setup_parser().parse_known_args()
print("Unable to locate jans-setup, installing ...")
setup_branch = argsp.jans_setup_branch or 'main'
download_jans_install_py(setup_branch)
install_cmd = '{} {} --setup-branch={}'.format(sys.executable, install_py_path, setup_branch)
if argsp.download_exit:
nargs.append('--download-exit')
argsp.flex_non_interactive = True
if argsp.flex_non_interactive:
nargs.append('-n')
install_cmd += ' -yes'
if nargs:
install_cmd += ' --args="{}"'.format(subprocess.list2cmdline(nargs))
print("Executing", install_cmd)
os.system(install_cmd)
jans_installer_downloaded = True
def set_app_versions_from_arguments(brgsp):
if hasattr(argparse, 'jans_versions_done'):
return
argparse.jans_versions_done = True
app_versions['JANS_APP_VERSION'] = brgsp.jans_app_verison
app_versions['JANS_BUILD'] = brgsp.jans_app_build
app_versions['NODE_VERSION'] = brgsp.node_version
app_versions['SETUP_BRANCH'] = brgsp.jans_setup_branch
app_versions['FLEX_BRANCH'] = brgsp.flex_branch
app_versions['JANS_BRANCH'] = brgsp.jans_branch
app_versions['NODE_MODULES_BRANCH'] = brgsp.node_modules_branch or brgsp.flex_branch
app_versions['jans_version'] = app_versions['JANS_APP_VERSION'] + app_versions['JANS_BUILD']
if not argsp:
argsp, nargs = get_flex_setup_parser().parse_known_args()
set_app_versions_from_arguments(argsp)
if not jans_installer_downloaded:
jans_archive_url = 'https://github.com/JanssenProject/jans/archive/refs/heads/{}.zip'.format(argsp.jans_branch)
with tempfile.TemporaryDirectory() as tmp_dir:
jans_zip_file = os.path.join(tmp_dir, os.path.basename(jans_archive_url))
try:
print("Trying /refs/heads url")
print("Downloading {} as {}".format(jans_archive_url, jans_zip_file))
request.urlretrieve(jans_archive_url, jans_zip_file)
except Exception as e:
print(f"Failed to download from {jans_archive_url}, trying tags URL. Error: {e}")
jans_archive_url = 'https://github.com/JanssenProject/jans/archive/refs/tags/{}.zip'.format(
argsp.jans_branch)
jans_zip_file = os.path.join(tmp_dir, os.path.basename(jans_archive_url))
request.urlretrieve(jans_archive_url, jans_zip_file)
if argsp.download_exit:
dist_dir = '/opt/dist/jans/'
if not os.path.exists(dist_dir):
os.makedirs(dist_dir)
shutil.copyfile(jans_zip_file, os.path.join(dist_dir, 'jans.zip'))
print("Extracting jans-setup package")
jans_zip = zipfile.ZipFile(jans_zip_file)
parent_dir = jans_zip.filelist[0].orig_filename
unpack_dir = os.path.join(tmp_dir, 'unpacked')
shutil.unpack_archive(jans_zip_file, unpack_dir)
shutil.copytree(os.path.join(unpack_dir, parent_dir, 'jans-linux-setup/jans_setup'), __STATIC_SETUP_DIR__)
jans_zip.close()
if profile:
print("Writing profile \033[1m{}\033[0m to file {}.".format(profile, profile_fn))
with open(profile_fn, 'w') as w:
w.write(profile)
sys.path.append(__STATIC_SETUP_DIR__)
from setup_app import downloads
from setup_app.utils import base
from setup_app.utils import arg_parser
base.argsp = arg_parser.get_parser()
set_app_versions_from_arguments(base.argsp)
downloads.base.current_app.app_info = base.readJsonFile(os.path.join(__STATIC_SETUP_DIR__, 'app_info.json'))
downloads.download_sqlalchemy()
downloads.download_cryptography()
downloads.download_pyjwt()
install_components = {
'admin_ui': argsp.install_admin_ui,
'casa': argsp.install_casa
}
logs_dir = os.path.join(__STATIC_SETUP_DIR__, 'logs')
if not os.path.exists(logs_dir):
os.makedirs(logs_dir)
if __STATIC_SETUP_DIR__ not in sys.path:
sys.path.append(__STATIC_SETUP_DIR__)
from setup_app import paths
paths.LOG_FILE = os.path.join(logs_dir, 'flex-setup.log')
paths.LOG_ERROR_FILE = os.path.join(logs_dir, 'flex-setup-error.log')
print()
print("Log Files:")
print('\033[1m')
print(paths.LOG_FILE)
print(paths.LOG_ERROR_FILE)
print('\033[0m')
parser = get_flex_setup_parser()
from setup_app.utils import arg_parser
arg_parser.add_to_me(parser)
installed = False
if not (os.path.exists(jans_config_properties) or argsp.download_exit):
installed = True
try:
from jans_setup import jans_setup
except ImportError:
import jans_setup
jans_setup.main()
argsp = arg_parser.get_parser()
set_app_versions_from_arguments(argsp)
del_msg = " - Deleting"
from setup_app import static
from setup_app.utils import base
profile_fn = os.path.join(base.par_dir, 'profile')
if os.path.exists(profile_fn):
with open(profile_fn) as f:
profile = f.read().strip()
else:
profile = 'jans'
os.environ['JANS_PROFILE'] = profile
base.current_app.profile = profile
base.current_app.app_info.update(app_versions)
base.argsp = argsp
sys.path.insert(0, base.pylib_dir)
from setup_app.pylib.jproperties import Properties
from setup_app.pylib import jwt
from setup_app.pylib.ldif4.ldif import LDIFWriter
from setup_app.utils.package_utils import packageUtils
from setup_app.config import Config
from setup_app.utils.collect_properties import CollectProperties
from setup_app.installers.node import NodeInstaller
from setup_app.installers.httpd import HttpdInstaller
from setup_app.installers.config_api import ConfigApiInstaller
from setup_app.installers.jetty import JettyInstaller
from setup_app.installers.jans_auth import JansAuthInstaller
from setup_app.installers.jans import JansInstaller
from setup_app.installers.jans_cli import JansCliInstaller
from setup_app.installers.jans_casa import CasaInstaller
from setup_app.utils.properties_utils import propertiesUtils
from setup_app.utils.ldif_utils import myLdifParser, create_client_ldif
Config.outputFolder = os.path.join(__STATIC_SETUP_DIR__, 'output')
if not os.path.exists(Config.outputFolder):
os.makedirs(Config.outputFolder)
if not installed:
# initialize config object
Config.init(paths.INSTALL_DIR)
if not argsp.download_exit:
collectProperties = CollectProperties()
collectProperties.collect()
else:
from setup_app.utils import arg_parser
if not hasattr(base, 'argsp'):
base.argsp = arg_parser.get_parser()
set_app_versions_from_arguments(base.argsp)
maven_base_url = 'https://jenkins.jans.io/maven/io/jans/'
node_installer = NodeInstaller()
httpd_installer = HttpdInstaller()
jans_installer = JansInstaller()
config_api_installer = ConfigApiInstaller()
jansAuthInstaller = JansAuthInstaller()
jans_cli_installer = JansCliInstaller()
jans_casa_installer = CasaInstaller()
setup_properties = base.read_properties_file(argsp.f) if argsp.f else {}
class flex_installer(JettyInstaller):
def __init__(self):
self.jans_auth_dir = os.path.join(Config.jetty_base, jansAuthInstaller.service_name)
self.jans_auth_custom_lib_dir = os.path.join(self.jans_auth_dir, 'custom/libs')
self.admin_ui_log_dir = '/var/log/adminui'
self.gluu_admin_ui_source_path = os.path.join(Config.dist_jans_dir, 'gluu-admin-ui.zip')
self.log4j2_adminui_path = os.path.join(Config.dist_jans_dir, 'log4j2-adminui.xml')
self.log4j2_path = os.path.join(Config.dist_jans_dir, 'log4j2.xml')
self.admin_ui_plugin_source_path = os.path.join(Config.dist_jans_dir, 'gluu-flex-admin-ui-plugin.jar')
self.flex_path = os.path.join(Config.dist_jans_dir, 'flex.zip')
self.source_dir = os.path.join(Config.install_dir, 'flex')
self.flex_setup_dir = os.path.join(self.source_dir, 'flex-linux-setup')
self.templates_dir = os.path.join(self.flex_setup_dir, 'templates')
self.admin_ui_config_properties_path = os.path.join(self.templates_dir, 'auiConfiguration.json')
self.adimin_ui_bin_url = 'https://jenkins.gluu.org/npm/admin_ui/main/built/admin-ui-main-built.tar.gz'
if not argsp.download_exit:
self.dbUtils.bind(force=True)
self.admin_ui_dn = 'ou=admin-ui,ou=configuration,o=jans'
Config.templateRenderingDict['admin_ui_apache_root'] = os.path.join(httpd_installer.server_root, 'admin')
self.simple_auth_scr_inum = 'A51E-76DA'
self.admin_ui_plugin_path = os.path.join(config_api_installer.libDir,
os.path.basename(self.admin_ui_plugin_source_path))
self.admin_ui_web_hook_ldif_fn = os.path.join(self.templates_dir, 'aui_webhook.ldif')
if not flex_installer_downloaded and os.path.exists(self.source_dir):
os.rename(self.source_dir, self.source_dir + '-' + time.ctime().replace(' ', '_'))
self.source_files = []
def download_files(self, force=False):
print("Downloading Gluu Flex components")
download_url, target = (
'https://github.com/GluuFederation/flex/archive/refs/heads/{}.zip'.format(app_versions['FLEX_BRANCH']),
self.flex_path)
if not flex_installer_downloaded:
base.download(download_url, target, verbose=True)
print("Extracting", self.flex_path)
base.extract_from_zip(self.flex_path, 'flex-linux-setup/flex_linux_setup', self.flex_setup_dir)
if install_components['admin_ui'] or argsp.download_exit or argsp.update_admin_ui:
self.source_files += [
('https://nodejs.org/dist/{0}/node-{0}-linux-x64.tar.xz'.format(app_versions['NODE_VERSION']),
os.path.join(Config.dist_app_dir, 'node-{0}-linux-x64.tar.xz'.format(app_versions['NODE_VERSION']))),
(urljoin(maven_base_url,
'jans-config-api/plugins/admin-ui-plugin/{0}{1}/admin-ui-plugin-{0}{1}-distribution.jar'.format(
app_versions['JANS_APP_VERSION'], app_versions['JANS_BUILD'])),
self.admin_ui_plugin_source_path),
(
'https://raw.githubusercontent.com/JanssenProject/jans/{}/jans-config-api/server/src/main/resources/log4j2.xml'.format(
app_versions['JANS_BRANCH']), self.log4j2_path),
(
'https://raw.githubusercontent.com/JanssenProject/jans/{}/jans-config-api/plugins/admin-ui-plugin/config/log4j2-adminui.xml'.format(
app_versions['JANS_BRANCH']), self.log4j2_adminui_path),
(self.adimin_ui_bin_url, os.path.join(Config.dist_jans_dir, os.path.basename(self.adimin_ui_bin_url))),
]
if argsp.update_admin_ui:
self.source_files.pop(0)
for download_url, target in self.source_files:
if force or not os.path.exists(target):
base.download(download_url, target, verbose=True)
if argsp.download_exit:
sys.exit()
def add_apache_directive(self, check_str, template):
print("Updating apache configuration")
apache_directive_template_text = self.readFile(os.path.join(self.templates_dir, template))
apache_directive_text = self.fomatWithDict(apache_directive_template_text, Config.templateRenderingDict)
https_jans_text = self.readFile(httpd_installer.https_jans_fn)
if check_str not in https_jans_text:
https_jans_list = https_jans_text.splitlines()
n = 0
for i, l in enumerate(https_jans_list):
if l.strip() == '</LocationMatch>':
n = i
https_jans_list.insert(n + 1, '\n' + apache_directive_text + '\n')
self.writeFile(httpd_installer.https_jans_fn, '\n'.join(https_jans_list))
self.enable_apache_mod_dir()
def enable_apache_mod_dir(self):
# Enable mod_dir for apache
cmd_a2enmod = shutil.which('a2enmod')
if base.clone_type == 'deb':
httpd_installer.run([cmd_a2enmod, 'dir'])
elif base.os_type == 'suse':
httpd_installer.run([cmd_a2enmod, 'dir'])
cmd_a2enflag = shutil.which('a2enflag')
httpd_installer.run([cmd_a2enflag, 'SSL'])
else:
base_mod_path = Path('/etc/httpd/conf.modules.d/00-base.conf')
mod_load_content = base_mod_path.read_text().splitlines()
modified = False
for i, l in enumerate(mod_load_content[:]):
ls = l.strip()
if ls.startswith('#') and ls.endswith('mod_dir.so'):
mod_load_content[i] = ls.lstrip('#')
modified = True
if modified:
base_mod_path.write_text('\n'.join(mod_load_content))
def rewrite_cli_ini(self):
print(" - Rewriting Jans CLI init file for plugins")
cli_config = Path(jans_cli_installer.config_ini_fn)
if cli_config.exists():
config = configparser.ConfigParser()
config.read_file(cli_config.open())
plugins = config_api_installer.get_plugins()
config['DEFAULT']['jca_plugins'] = ','.join(plugins)
config.write(cli_config.open('w'))
cli_config.chmod(0o600)
def unpack_gluu_admin_ui_archive(self):
admin_ui_bin_archive = os.path.basename(self.adimin_ui_bin_url)
if os.path.exists(Config.templateRenderingDict['admin_ui_apache_root']):
print("Backing up previous installation")
os.rename(
Config.templateRenderingDict['admin_ui_apache_root'],
Config.templateRenderingDict['admin_ui_apache_root'] + '.back-' + time.ctime().replace(' ', '_')
)
print("Extracting", admin_ui_bin_archive)
shutil.unpack_archive(
os.path.join(Config.dist_jans_dir, admin_ui_bin_archive),
httpd_installer.server_root
)
os.rename(
os.path.join(httpd_installer.server_root, 'dist'),
Config.templateRenderingDict['admin_ui_apache_root']
)
config_api_installer.renderTemplateInOut(
os.path.join(self.templates_dir, 'env-config.js'),
self.templates_dir,
Config.templateRenderingDict['admin_ui_apache_root']
)
def get_scope_dn_by_id(self, jansid):
scope_search_result = self.dbUtils.search('ou=scopes,o=jans', search_filter=f'(&(jansId={jansid})(objectClass=jansScope))')
return scope_search_result['dn']
def install_gluu_admin_ui(self):
print("Installing Gluu Admin UI Frontend")
self.unpack_gluu_admin_ui_archive()
aui_config_template_vars = base.readJsonFile(self.admin_ui_config_properties_path)
print("Creating Gluu Flex Admin UI Web Client")
client_check_result = config_api_installer.check_clients([('admin_ui_client_id', '2001.')])
if client_check_result['2001.'] == -1:
client_tmp_fn = os.path.join(self.source_dir, 'admin_ui_web_client.ldif')
admin_ui_client_scopes = []
for scope in aui_config_template_vars['oidcConfig']['auiWebClient']['scopes']:
scope_id = self.get_scope_dn_by_id(scope)
admin_ui_client_scopes.append(scope_id)
create_client_ldif(
ldif_fn=client_tmp_fn,
client_id=Config.admin_ui_client_id,
encoded_pw=Config.admin_ui_client_encoded_pw,
scopes=admin_ui_client_scopes,
redirect_uri=[f'https://{Config.hostname}/admin', 'http://localhost:4100'],
display_name='Admin UI Web Client',
authorization_methods=['none'],
other_props={'jansAttrs': ['{"tlsClientAuthSubjectDn":"","runIntrospectionScriptBeforeJwtCreation":false,"keepClientAuthorizationAfterExpiration":false,"allowSpontaneousScopes":false,"spontaneousScopes":[],"spontaneousScopeScriptDns":[],"updateTokenScriptDns":[],"backchannelLogoutUri":[],"backchannelLogoutSessionRequired":false,"additionalAudience":[],"postAuthnScripts":[],"consentGatheringScripts":[],"introspectionScripts":[],"rptClaimsScripts":[],"parLifetime":600,"requirePar":false,"jansAuthSignedRespAlg":null,"jansAuthEncRespAlg":null,"jansAuthEncRespEnc":null}'],
'jansAccessTknAsJwt': ['TRUE'],
'jansSignedRespAlg': ['RS256'],
'jansPostLogoutRedirectURI': [f'https://{Config.hostname}/admin', 'http://localhost:4100'],
'jansLogoutURI': [f'http://{Config.hostname}:4100/logout', f'https://{Config.hostname}/admin/logout'],
'jansAccessTknLife':['2592000']
}
)
print("\033[1mAdmin UI Web Client ID:\033[0m", Config.admin_ui_client_id)
print("\033[1mAdmin UI Web Client Secret:\033[0m", Config.admin_ui_client_pw)
self.dbUtils.import_ldif([client_tmp_fn])
client_check_result = config_api_installer.check_clients([('admin_ui_web_client_id', '2002.')])
if client_check_result['2002.'] == -1:
admin_ui_web_client_tmp_fn = os.path.join(self.source_dir, 'admin_ui_backend_api_client.ldif')
admin_ui_backend_client_scopes = []
for scope in aui_config_template_vars['oidcConfig']['auiBackendApiClient']['scopes']:
scope_id = self.get_scope_dn_by_id(scope)
admin_ui_backend_client_scopes.append(scope_id)
print("\033[1mAdmin UI Backend API Client ID:\033[0m", Config.admin_ui_web_client_id)
print("\033[1mAdmin UI Backend API Secret:\033[0m", Config.admin_ui_web_client_encoded_pw)
create_client_ldif(
ldif_fn=admin_ui_web_client_tmp_fn,
client_id=Config.admin_ui_web_client_id,
encoded_pw=Config.admin_ui_web_client_encoded_pw,
redirect_uri=None,
display_name='Admin UI Backend API Client',
grant_types=['client_credentials'],
response_types=['token'],
scopes=admin_ui_backend_client_scopes,
authorization_methods=['client_secret_basic'],
trusted_client='FALSE',
other_props={
'jansAttrs': ['{"tlsClientAuthSubjectDn":"","runIntrospectionScriptBeforeJwtCreation":false,"keepClientAuthorizationAfterExpiration":false,"allowSpontaneousScopes":false,"spontaneousScopes":[],"spontaneousScopeScriptDns":[],"updateTokenScriptDns":["inum=2D3E.5A04,ou=scripts,o=jans"],"backchannelLogoutUri":[],"backchannelLogoutSessionRequired":false,"additionalAudience":[],"postAuthnScripts":[],"consentGatheringScripts":[],"introspectionScripts":[],"rptClaimsScripts":[],"parLifetime":600,"requirePar":false,"jansAuthSignedRespAlg":null,"jansAuthEncRespAlg":null,"jansAuthEncRespEnc":null}'],
'jansAccessTknLife':['2592000'],
},
unset_props=('jansLogoutURI', 'jansPostLogoutRedirectURI', 'jansRedirectURI', 'jansSignedRespAlg')
)
self.dbUtils.import_ldif([admin_ui_web_client_tmp_fn])
self.add_apache_directive(Config.templateRenderingDict['admin_ui_apache_root'], 'admin_ui_apache_directive')
Config.templateRenderingDict['ssa'] = ''
Config.templateRenderingDict['op_host'] = ''
Config.templateRenderingDict['oidc_client_id'] = ''
Config.templateRenderingDict['oidc_client_secret'] = ''
Config.templateRenderingDict['license_hardware_key'] = ''
Config.templateRenderingDict['scan_license_api_hostname'] = Config.templateRenderingDict['op_host'].replace(
'account', 'cloud')
Config.templateRenderingDict['adminui_authentication_mode'] = argsp.adminui_authentication_mode
config_api_installer.renderTemplateInOut(self.admin_ui_config_properties_path, self.templates_dir,
self.source_dir)
admin_ui_jans_conf_app = config_api_installer.readFile(
os.path.join(self.source_dir, os.path.basename(self.admin_ui_config_properties_path)))
config_api_installer.dbUtils.set_configuration('jansConfApp', admin_ui_jans_conf_app, self.admin_ui_dn)
self.install_config_api_plugin()
print("Removing DUO Script")
config_api_installer.dbUtils.delete_dn('inum=5018-F9CF,ou=scripts,o=jans')
self.rewrite_cli_ini()
print(f"Copying admin-ui command line utility to {Config.jansOptBinFolder}")
config_api_installer.copyFile(
os.path.join(self.flex_setup_dir, 'admin-ui'),
Config.jansOptBinFolder
)
config_api_installer.run([base.paths.cmd_chmod, '+x', os.path.join(Config.jansOptBinFolder, 'admin-ui')])
def install_config_api_plugin(self):
old_plugin = os.path.join(config_api_installer.libDir, 'admin-ui-plugin.jar')
if os.path.exists(old_plugin):
print("Old plugin {} was detected. Removing...".format(old_plugin))
os.remove(old_plugin)
config_api_installer.copyFile(self.admin_ui_plugin_source_path, config_api_installer.libDir, backup=False)
config_api_installer.add_extra_class(self.admin_ui_plugin_path)
config_api_installer.copyFile(self.log4j2_path, config_api_installer.custom_config_dir)
log4j2_adminui_path_target_path = os.path.join(
config_api_installer.custom_config_dir,
os.path.basename(self.log4j2_adminui_path)
)
print("Reading XML", self.log4j2_adminui_path)
tree = ElementTree.parse(self.log4j2_adminui_path)
root = tree.getroot()
for appenders in root.findall('Appenders'):
for child in appenders:
if child.tag == 'RollingFile' and child.get('name') in ('ADMINUI-AUDIT', 'ADMINUI-LOG'):
for prop in ('fileName', 'filePattern'):
file_name = child.get(prop)
if file_name:
file_base_name = os.path.basename(file_name)
new_file_path = os.path.join(self.admin_ui_log_dir, file_base_name)
child.set(prop, new_file_path)
print("Writing XML", log4j2_adminui_path_target_path)
tree.write(log4j2_adminui_path_target_path, encoding='utf-8', xml_declaration=True)
if not os.path.exists(self.admin_ui_log_dir):
os.makedirs(self.admin_ui_log_dir)
config_api_installer.chown(self.admin_ui_log_dir, Config.jetty_user, Config.jetty_group)
config_api_installer.set_class_path(glob.glob(os.path.join(config_api_installer.libDir, '*.jar')))
self.rewrite_cli_ini()
def install_casa(self):
Config.install_casa = True
jans_casa_installer.calculate_selected_aplications_memory()
jans_installer.order_services()
jans_casa_installer.start_installation()
jans_casa_installer.enable()
def save_properties(self):
fn = Config.savedProperties
print("Saving properties", fn)
if os.path.exists(fn):
p = Properties()
with open(fn, 'rb') as f:
p.load(f, 'utf-8')
for prop in ('admin_ui_client_id', 'admin_ui_client_pw'):
if Config.get(prop):
p[prop] = Config.get(prop)
with open(fn, 'wb') as f:
p.store(f, encoding="utf-8")
else:
propertiesUtils.save_properties()
def remove_apache_directive(self, directive):
https_jans_current = self.readFile(httpd_installer.https_jans_fn)
tmp_ = directive.lstrip('<').rstrip('>').strip()
dir_name, dir_arg = tmp_.split()
dir_fname = '/' + dir_name
https_jans_list = []
append_c = 2
for l in https_jans_current.splitlines():
if dir_name in l and dir_arg in l:
append_c = 0
elif append_c == 0 and dir_fname in l:
append_c = 1
if append_c > 1:
https_jans_list.append(l)
if append_c == 1:
append_c = 2
self.writeFile(httpd_installer.https_jans_fn, '\n'.join(https_jans_list))
def uninstall_admin_ui(self):
print("Uninstalling Gluu Admin-UI")
client_check_result = config_api_installer.check_clients([('admin_ui_client_id', '2001.')])
if client_check_result['2001.'] == 1:
print(" - Deleting Gluu Flex Admin UI Web Client ", Config.admin_ui_client_id)
self.dbUtils.delete_dn('inum={},ou=clients,o=jans'.format(Config.admin_ui_client_id))
client_check_result = config_api_installer.check_clients([('admin_ui_web_client_id', '2002.')])
if client_check_result['2002.'] == 1:
print(" - Deleting Gluu Flex Admin UI Backend API Client ", Config.admin_ui_web_client_id)
self.dbUtils.delete_dn('inum={},ou=clients,o=jans'.format(Config.admin_ui_web_client_id))
self.dbUtils.set_configuration("jansConfApp", None, self.admin_ui_dn)
print(" - Removing Admin UI directives from apache configuration")
self.remove_apache_directive('<Directory "{}">'.format(Config.templateRenderingDict['admin_ui_apache_root']))
if os.path.exists(self.admin_ui_plugin_path):
print(del_msg, self.admin_ui_plugin_path)
self.run(['rm', '-f', self.admin_ui_plugin_path])
write_config_api_xml = False
config_api_plugins = config_api_installer.get_plugins(paths=True)
if self.admin_ui_plugin_path in config_api_plugins:
print(" - Removing plugin {} from Jans Config API Configuration".format(self.admin_ui_plugin_path))
config_api_plugins.remove(self.admin_ui_plugin_path)
write_config_api_xml = True
if write_config_api_xml:
config_api_installer.set_class_path(config_api_plugins)
for s_path in (self.log4j2_adminui_path, self.log4j2_path):
f_path = os.path.join(
config_api_installer.custom_config_dir,
os.path.basename(s_path)
)
if os.path.exists(f_path):
print(del_msg, f_path)
self.run(['rm', '-f', f_path])
self.rewrite_cli_ini()
if os.path.exists(Config.templateRenderingDict['admin_ui_apache_root']):
print(del_msg, Config.templateRenderingDict['admin_ui_apache_root'])
self.run(['rm', '-f', '-r', Config.templateRenderingDict['admin_ui_apache_root']])
def generate_gluu_passwurd_api_keystore(self):
print("Generating Gluu Passwurd API Keystore")
suffix = 'passwurd_api'
keystore_pw = jansAuthInstaller.getPW()
keystore_pw_fn = os.path.join(Config.certFolder, 'passwurd_api.json')
key_fn, csr_fn, crt_fn = jansAuthInstaller.gen_cert(suffix, 'changeit', user='jetty')
passwurd_api_keystore_fn = os.path.join(Config.certFolder, 'passwurdAKeystore.pcks12')
self.import_key_cert_into_keystore(
suffix=suffix,
keystore_fn=passwurd_api_keystore_fn,
keystore_pw=keystore_pw,
in_key=key_fn,
in_cert=crt_fn,
store_type='PKCS12'
)
keystore_pw_data = {'keyStoreSecret': keystore_pw}
jansAuthInstaller.writeFile(keystore_pw_fn, json.dumps(keystore_pw_data))
jansAuthInstaller.chown(keystore_pw_fn, Config.jetty_user, Config.root_user)
jansAuthInstaller.run([base.paths.cmd_chmod, '640', keystore_pw_fn])
def prompt_for_installation():
if not os.path.exists(os.path.join(httpd_installer.server_root, 'admin')):
prompt_admin_ui_install = input("Install Admin UI [Y/n]: ")
if not prompt_admin_ui_install.strip().lower().startswith('n'):
install_components['admin_ui'] = True
else:
print("Admin UI is allready installed on this system")
install_components['admin_ui'] = False
if not jans_casa_installer.installed():
prompt_casa_install = input("Install Jans Casa [Y/n]: ")
if not prompt_casa_install.strip().lower().startswith('n'):
install_components['casa'] = True
else:
print("Jans Casa is allready installed on this system")
install_components['casa'] = False
if not (install_components['casa'] or install_components['admin_ui'] or argsp.gluu_passwurd_cert):
print("Nothing to install. Exiting ...")
sys.exit()
def install_post_setup():
if install_components['casa']:
print("Starting Casa")
jans_casa_installer.start()
print("Installation was completed.")
if install_components['admin_ui']:
print("Browse https://{}/admin".format(Config.hostname))
if install_components['casa']:
print("Browse https://{}/jans-casa".format(Config.hostname))
def prepare_for_installation():
if not (argsp.flex_non_interactive or argsp.download_exit):
prompt_for_installation()
def get_components_from_setup_properties():
if argsp.f:
if not argsp.gluu_passwurd_cert:
argsp.gluu_passwurd_cert = base.as_bool(setup_properties.get('gluu-passwurd-cert'))
if not (argsp.install_admin_ui or install_components['admin_ui']):
install_components['admin_ui'] = base.as_bool(setup_properties.get('install-admin-ui'))
if not (argsp.install_casa or install_components['casa']):
install_components['casa'] = base.as_bool(setup_properties.get('install-casa'))
if 'adminui-authentication-mode' in setup_properties:
argsp.adminui_authentication_mode = setup_properties['adminui-authentication-mode']
def restart_services():
print("Restarting Apache")
httpd_installer.restart()
print("Restarting Jans Auth")
config_api_installer.restart('jans-auth')
print("Restarting Janssen Config Api")
config_api_installer.restart()
def main(uninstall):
get_components_from_setup_properties()
installer_obj = flex_installer()
if argsp.update_admin_ui:
if os.path.exists(os.path.join(httpd_installer.server_root, 'admin')):
installer_obj.download_files(force=True)
installer_obj.install_config_api_plugin()
installer_obj.unpack_gluu_admin_ui_archive()
restart_services()
else:
print("Gluu Flex Admin UI was not installed on this system. Update not possible.")
sys.exit()
elif not uninstall:
prepare_for_installation()
if uninstall:
installer_obj.uninstall_admin_ui()
print("Disabling script", installer_obj.simple_auth_scr_inum)
installer_obj.dbUtils.enable_script(installer_obj.simple_auth_scr_inum, enable=False)
else:
if not flex_installer_downloaded or argsp.download_exit:
installer_obj.download_files(argsp.download_exit)
print("Enabling script", installer_obj.simple_auth_scr_inum)
installer_obj.dbUtils.enable_script(installer_obj.simple_auth_scr_inum)
if install_components['admin_ui']:
if not node_installer.installed():
print("Installing node")
node_installer.install()
installer_obj.install_gluu_admin_ui()
if install_components['casa']:
installer_obj.install_casa()
installer_obj.save_properties()
if argsp.gluu_passwurd_cert:
installer_obj.generate_gluu_passwurd_api_keystore()
if not argsp.no_restart_services:
restart_services()
if not uninstall:
install_post_setup()
if __name__ == "__main__":
if argsp.shell:
code.interact(local=locals())
sys.exit()
else:
main(uninstall=argsp.remove_flex)