Skip to content

Commit dac8b70

Browse files
committed
feat: flex-linux-setup
1 parent cbfd6a1 commit dac8b70

File tree

3 files changed

+227
-0
lines changed

3 files changed

+227
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
authserver.clientId=%(role_based_client_id)s
2+
authserver.clientSecret=%(role_based_client_pw)s
3+
authserver.authzBaseUrl=https://%(hostname)s/jans-auth/authorize.htm
4+
authserver.scope=openid+profile+email+user_name
5+
authserver.redirectUrl=https://%(hostname)s/admin
6+
authserver.frontChannelLogoutUrl=https://%(hostname)s/admin/logout
7+
authserver.postLogoutRedirectUri=https://%(hostname)s/admin
8+
authserver.tokenEndpoint=https://%(hostname)s/jans-auth/restv1/token
9+
authserver.introspectionEndpoint=https://%(hostname)s/jans-auth/restv1/introspection
10+
authserver.userInfoEndpoint=https://%(hostname)s/jans-auth/restv1/userinfo
11+
authserver.endSessionEndpoint=https://%(hostname)s/jans-auth/restv1/end_session
12+
13+
tokenServer.clientId=%(role_based_client_id)s
14+
tokenServer.clientSecret=%(role_based_client_pw)s
15+
tokenServer.authzBaseUrl=https://%(hostname)s/jans-auth/authorize.htm
16+
tokenServer.scope=openid+profile+email+user_name
17+
tokenServer.redirectUrl=https://%(hostname)s/admin
18+
tokenServer.logoutUrl=https://%(hostname)s/admin
19+
tokenServer.tokenEndpoint=https://%(hostname)s/jans-auth/restv1/token
20+
tokenServer.introspectionEndpoint=https://%(hostname)s/jans-auth/restv1/introspection
21+
tokenServer.userInfoEndpoint=https://%(hostname)s/jans-auth/restv1/userinfo
22+
23+
24+
## licenseSpring details
25+
26+
licenseSpring.apiKey=
27+
licenseSpring.productCode=
28+
licenseSpring.sharedKey=
29+
licenseSpring.managementKey=
30+
licenseSpring.enabled=false

flex-linux-setup/flex-plugin.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import sys
2+
import os
3+
import time
4+
import glob
5+
import json
6+
import shutil
7+
import readline
8+
from collections import OrderedDict
9+
10+
mydir = os.getcwd()
11+
dirs = glob.glob('/opt/jans/jans-setup/output/gluu-admin-ui*')
12+
run_cmd = '/bin/su node -c "PATH=$PATH:/opt/jre/bin:/opt/node/bin {}"'
13+
14+
for d in dirs:
15+
if os.path.exists(os.path.join(d, '.env')):
16+
uid_admin_dir = d
17+
break
18+
else:
19+
print("Admin UI installation directory not found.")
20+
sys.exit()
21+
22+
os.chdir(uid_admin_dir)
23+
plugin_json_fn = os.path.join(uid_admin_dir, 'plugins.config.json')
24+
25+
def read_plugins():
26+
with open(plugin_json_fn) as f:
27+
plugins = json.load(f, object_pairs_hook=OrderedDict)
28+
return plugins
29+
30+
plugins = read_plugins()
31+
32+
def print_plugins():
33+
print("Available Plugins")
34+
for i, p in enumerate(plugins):
35+
e = '\033[92m*\033[0m' if p.get('enabled') else ' '
36+
print('{} {} {}'.format(e, i+1, p.get('title') or p.get('key')))
37+
print()
38+
39+
40+
def exec_command(cmd):
41+
print("\033[1mExecuting {}\033[0m".format(cmd))
42+
os.system(run_cmd.format(cmd))
43+
44+
45+
def build_copy():
46+
exec_command('npm run build:prod')
47+
admin_dir = '/var/www/html/admin'
48+
if os.path.exists(admin_dir):
49+
os.rename(admin_dir, admin_dir + '.' + time.ctime())
50+
51+
print("Copying admin ui files to apache directory")
52+
shutil.copytree(os.path.join(uid_admin_dir, 'dist'), admin_dir)
53+
54+
55+
while True:
56+
print_plugins()
57+
user_input = input('Add/Remove/Finish/Quit [a/r/f/q]: ')
58+
if user_input:
59+
choice = user_input.lower()[0]
60+
if choice == 'q':
61+
print("Exiting without modification.")
62+
break
63+
64+
elif choice == 'f':
65+
build_copy()
66+
break
67+
68+
elif choice == 'r':
69+
plugin_number = input('Enter plugin number to remove :')
70+
if plugin_number.isdigit() and int(plugin_number) <= len(plugins):
71+
pn = int(plugin_number) - 1
72+
for i, p in enumerate(plugins):
73+
if i == pn:
74+
exec_command('npm run plugin:remove {}'.format(p['key']))
75+
plugins = read_plugins()
76+
break
77+
elif choice == 'a':
78+
plugin_fn = input('Enter path of plugin: ')
79+
if plugin_fn.lower().endswith('.zip'):
80+
exec_command('npm run plugin:add {}'.format(plugin_fn))
81+
plugins = read_plugins()
82+
else:
83+
print("Can't find \033[31m{}\033[0m".format(plugin_metadata_fn))
84+
print()

flex-linux-setup/flex-setup.py

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/usr/bin/python3
2+
3+
import sys
4+
import os
5+
import zipfile
6+
import argparse
7+
from urllib.parse import urljoin
8+
9+
jans_setup_dir = '/opt/jans/jans-setup'
10+
sys.path.append(jans_setup_dir)
11+
12+
if not (os.path.join(jans_setup_dir) and ('/etc/jans/conf/jans.properties')):
13+
print("Please install Jans server then execute this script.")
14+
sys.exit()
15+
16+
17+
from setup_app import paths
18+
paths.LOG_FILE = os.path.join(jans_setup_dir, 'logs/flex-setup.log')
19+
paths.LOG_ERROR_FILE = os.path.join(jans_setup_dir, 'logs/flex-setup-error.log')
20+
from setup_app import static
21+
from setup_app.utils import base
22+
23+
from setup_app.utils.package_utils import packageUtils
24+
from setup_app.config import Config
25+
from setup_app.utils.collect_properties import CollectProperties
26+
from setup_app.installers.node import NodeInstaller
27+
from setup_app.installers.httpd import HttpdInstaller
28+
from setup_app.installers.config_api import ConfigApiInstaller
29+
30+
parser = argparse.ArgumentParser(description="This script downloads Gluu Admin UI components and installs")
31+
parser.add_argument('--setup-branch', help="Jannsen setup github branch", default='main')
32+
argsp = parser.parse_args()
33+
34+
# initialize config object
35+
Config.init(paths.INSTALL_DIR)
36+
Config.determine_version()
37+
38+
collectProperties = CollectProperties()
39+
collectProperties.collect()
40+
41+
maven_base_url = 'https://maven.jans.io/maven/io/jans/'
42+
app_versions = {
43+
"SETUP_BRANCH": argsp.setup_branch,
44+
"JANS_APP_VERSION": "1.0.0",
45+
"JANS_BUILD": "-SNAPSHOT",
46+
"ADMIN_UI_FRONTEND_BRANCH": "main",
47+
"NODE_VERSION": "v14.18.2"
48+
}
49+
50+
node_installer = NodeInstaller()
51+
httpdInstaller = HttpdInstaller()
52+
configApiInstaller = ConfigApiInstaller()
53+
54+
if not node_installer.installed():
55+
node_fn = 'node-{0}-linux-x64.tar.xz'.format(app_versions['NODE_VERSION'])
56+
node_path = os.path.join(Config.distAppFolder, node_fn)
57+
if not os.path.exists(node_path):
58+
print("Downloading", node_fn)
59+
base.download('https://nodejs.org/dist/{0}/node-{0}-linux-x64.tar.xz'.format(app_versions['NODE_VERSION']), node_path)
60+
print("Installing node")
61+
node_installer.install()
62+
63+
64+
gluu_admin_ui_source_path = os.path.join(Config.distJansFolder, 'gluu-admin-ui.zip')
65+
log4j2_adminui_path = os.path.join(Config.distJansFolder, 'log4j2-adminui.xml')
66+
log4j2_path = os.path.join(Config.distJansFolder, 'log4j2.xml')
67+
admin_ui_plugin_source_path = os.path.join(Config.distJansFolder, 'admin-ui-plugin-distribution.jar')
68+
admin_ui_config_properties_path = os.path.join(Config.distJansFolder, 'auiConfiguration.properties')
69+
70+
print("Downloading components")
71+
base.download(urljoin(maven_base_url, 'admin-ui-plugin/{0}{1}/admin-ui-plugin-{0}{1}-distribution.jar'.format(app_versions['JANS_APP_VERSION'], app_versions['JANS_BUILD'])), admin_ui_plugin_source_path)
72+
base.download('https://raw.githubusercontent.com/JanssenProject/jans-config-api/master/server/src/main/resources/log4j2.xml', log4j2_path)
73+
base.download('https://raw.githubusercontent.com/JanssenProject/jans-config-api/master/plugins/admin-ui-plugin/config/log4j2-adminui.xml', log4j2_adminui_path)
74+
base.download('https://github.com/GluuFederation/gluu-admin-ui/archive/refs/heads/{}.zip'.format(app_versions['ADMIN_UI_FRONTEND_BRANCH']), gluu_admin_ui_source_path)
75+
base.download('https://raw.githubusercontent.com/JanssenProject/jans/{}/flex-linux-setup/auiConfiguration.properties'.format(app_versions['SETUP_BRANCH']), admin_ui_config_properties_path)
76+
77+
78+
print("Installing Gluu Admin UI Frontend")
79+
package_zip = zipfile.ZipFile(gluu_admin_ui_source_path, "r")
80+
package_par_dir = package_zip.namelist()[0]
81+
source_dir = os.path.join(Config.outputFolder, package_par_dir)
82+
83+
print("Extracting", gluu_admin_ui_source_path)
84+
package_zip.extractall(Config.outputFolder)
85+
86+
configApiInstaller.renderTemplateInOut(os.path.join(source_dir, '.env.tmp'), source_dir, source_dir)
87+
configApiInstaller.copyFile(os.path.join(source_dir, '.env.tmp'), os.path.join(source_dir, '.env'))
88+
configApiInstaller.run([paths.cmd_chown, '-R', 'node:node', source_dir])
89+
cmd_path = 'PATH=$PATH:{}/bin:{}/bin'.format(Config.jre_home, Config.node_home)
90+
91+
for cmd in ('npm install @openapitools/openapi-generator-cli', 'npm run api', 'npm install', 'npm run build:prod'):
92+
print("Executing `{}`".format(cmd))
93+
run_cmd = '{} {}'.format(cmd_path, cmd)
94+
configApiInstaller.run(['/bin/su', 'node','-c', run_cmd], source_dir)
95+
96+
target_dir = os.path.join(httpdInstaller.server_root, 'admin')
97+
print("Copying files to", target_dir)
98+
configApiInstaller.copyTree(os.path.join(source_dir, 'dist'), target_dir)
99+
100+
configApiInstaller.check_clients([('role_based_client_id', '2000.')])
101+
configApiInstaller.renderTemplateInOut(admin_ui_config_properties_path, Config.distJansFolder, configApiInstaller.custom_config_dir)
102+
admin_ui_plugin_path = os.path.join(configApiInstaller.libDir, os.path.basename(admin_ui_plugin_source_path))
103+
configApiInstaller.web_app_xml_fn = os.path.join(configApiInstaller.jetty_base, configApiInstaller.service_name, 'webapps/jans-config-api.xml')
104+
configApiInstaller.copyFile(admin_ui_plugin_source_path, configApiInstaller.libDir)
105+
configApiInstaller.add_extra_class(admin_ui_plugin_path)
106+
107+
for logfn in (log4j2_adminui_path, log4j2_path):
108+
configApiInstaller.copyFile(logfn, configApiInstaller.custom_config_dir)
109+
110+
print("Restarting Janssen Config Api")
111+
configApiInstaller.restart()
112+
113+
print("Installation was completed. Browse https://{}/admin".format(Config.hostname))

0 commit comments

Comments
 (0)