-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jans-linux-setup): gluu/flex casa installer (#5590)
* feat(jans-linux-setup): gluu/flex casa installer * fix(docs): add link and casa install options * fix(docs): update vm install options
- Loading branch information
1 parent
0fb05b3
commit 2ce1152
Showing
19 changed files
with
366 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
jans-linux-setup/jans_setup/setup_app/installers/casa.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import os | ||
import re | ||
import glob | ||
import ssl | ||
import time | ||
import json | ||
|
||
from xml.etree import ElementTree | ||
|
||
from setup_app import paths | ||
from setup_app.config import Config | ||
from setup_app.pylib.ldif4.ldif import LDIFWriter | ||
from setup_app.static import AppType, InstallOption, SetupProfiles | ||
from setup_app.utils import base | ||
from setup_app.utils.properties_utils import propertiesUtils | ||
from setup_app.utils.ldif_utils import myLdifParser | ||
from setup_app.installers.jetty import JettyInstaller | ||
|
||
Config.casa_web_port = '8080' | ||
CASA_GIT = 'https://raw.githubusercontent.com/GluuFederation/flex/main/casa' | ||
|
||
|
||
class CasaInstaller(JettyInstaller): | ||
|
||
client_id_prefix = '3000.' | ||
casa_dist_dir = os.path.join(Config.dist_jans_dir, 'casa') | ||
source_files = [ | ||
(os.path.join(casa_dist_dir, 'casa.war'), os.path.join(base.current_app.app_info['GLUU_MAVEN'], 'maven/org/gluu/casa/{0}/casa-{0}.war').format(base.current_app.app_info['CASA_VERSION'])), | ||
(os.path.join(casa_dist_dir, 'casa-config.jar'), os.path.join(base.current_app.app_info['GLUU_MAVEN'], 'maven/org/gluu/casa-config/{0}/casa-config-{0}.jar').format(base.current_app.app_info['CASA_VERSION'])), | ||
(os.path.join(casa_dist_dir, 'twillo.jar'), os.path.join(base.current_app.app_info['TWILIO_MAVEN'], '{0}/twilio-{0}.jar'.format(base.current_app.app_info['TWILIO_VERSION']))), | ||
(os.path.join(casa_dist_dir, 'jans-fido2-client.jar'), (os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-fido2-client/{0}{1}/jans-fido2-client-{0}{1}.jar'.format(base.current_app.app_info['JANS_APP_VERSION'], base.current_app.app_info['JANS_BUILD'])))), | ||
(os.path.join(casa_dist_dir, 'casa_web_resources.xml'), os.path.join(CASA_GIT, 'extras/casa_web_resources.xml')), | ||
] | ||
|
||
casa_python_libs = ['Casa.py', 'casa-external_fido2.py', 'casa-external_otp.py', 'casa-external_super_gluu.py', 'casa-external_twilio_sms.py'] | ||
|
||
casa_script_files = [] | ||
|
||
for plib in casa_python_libs: | ||
casa_script_files.append(( | ||
os.path.join(casa_dist_dir, 'pylib', plib), | ||
os.path.join(CASA_GIT, 'extras', plib) | ||
)) | ||
|
||
def __init__(self): | ||
setattr(base.current_app, self.__class__.__name__, self) | ||
self.service_name = 'casa' | ||
self.app_type = AppType.SERVICE | ||
self.install_type = InstallOption.OPTONAL | ||
self.install_var = 'install_casa' | ||
self.register_progess() | ||
|
||
self.source_files += self.casa_script_files | ||
self.jetty_service_dir = os.path.join(self.jetty_base, self.service_name) | ||
self.jetty_service_webapps = os.path.join(self.jetty_service_dir, 'webapps') | ||
self.output_folder = os.path.join(Config.output_dir, self.service_name) | ||
self.templates_dir = os.path.join(Config.templateFolder, self.service_name) | ||
self.ldif_config_fn = os.path.join(self.output_folder, 'configuration.ldif') | ||
self.ldif_client_fn = os.path.join(self.output_folder, 'client.ldif') | ||
self.ldif_auth_script_fn = os.path.join(self.output_folder, 'person_authentication_script.ldif') | ||
self.config_json_fn = os.path.join(self.output_folder, 'casa-config.json') | ||
self.ldif_person_authentication_script_fn = os.path.join(self.output_folder, 'person_authentication_script.ldif') | ||
self.scopes_fn = os.path.join(self.templates_dir, 'scopes.json') | ||
self.pylib_dir = os.path.join(Config.jansOptPythonFolder, 'libs') | ||
|
||
|
||
def install(self): | ||
|
||
self.installJettyService(self.jetty_app_configuration[self.service_name], True) | ||
self.copyFile(self.source_files[0][0], self.jetty_service_webapps) | ||
self.copyFile(self.source_files[4][0], self.jetty_service_webapps) | ||
|
||
self.casa_scopes = self.create_scopes() | ||
self.add_plugins() | ||
self.enable() | ||
|
||
def add_plugins(self): | ||
jans_auth_web_app_xml = self.readFile(base.current_app.JansAuthInstaller.web_app_xml_fn) | ||
|
||
for plugin,_ in self.source_files[1:4]: | ||
plugin_name = os.path.basename(plugin) | ||
if plugin_name not in jans_auth_web_app_xml: | ||
self.logIt("Adding plugin {} to jans-auth".format(plugin_name)) | ||
self.copyFile(plugin, base.current_app.JansAuthInstaller.custom_lib_dir) | ||
plugin_class_path = os.path.join(base.current_app.JansAuthInstaller.custom_lib_dir, plugin_name) | ||
base.current_app.JansAuthInstaller.add_extra_class(plugin_class_path) | ||
self.chown(plugin_class_path, Config.jetty_user, Config.jetty_group) | ||
|
||
def copy_static(self): | ||
for fn in glob.glob(os.path.join(self.casa_dist_dir, 'pylib/*.py')): | ||
self.copyFile(fn, self.pylib_dir) | ||
|
||
|
||
def generate_configuration(self): | ||
self.casa_scopes = self.create_scopes() | ||
|
||
self.check_clients([('casa_client_id', self.client_id_prefix)]) | ||
|
||
if not Config.get('casa_client_pw'): | ||
Config.casa_client_pw = self.getPW() | ||
Config.casa_client_encoded_pw = self.obscure(Config.jca_client_pw) | ||
|
||
def render_import_templates(self): | ||
|
||
Config.templateRenderingDict['casa_redirect_uri'] = 'https://{}/casa'.format(Config.hostname) | ||
Config.templateRenderingDict['casa_redirect_logout_uri'] = 'https://{}/casa/bye.zul'.format(Config.hostname) | ||
Config.templateRenderingDict['casa_frontchannel_logout_uri'] = 'https://{}/casa/autologout'.format(Config.hostname) | ||
|
||
# prepare casa scipt ldif | ||
base64_script_file = self.generate_base64_file(self.casa_script_files[0][0], 1) | ||
Config.templateRenderingDict['casa_person_authentication_script'] = base64_script_file | ||
self.renderTemplateInOut(self.ldif_auth_script_fn, self.templates_dir, self.output_folder) | ||
|
||
self.renderTemplateInOut(self.config_json_fn, self.templates_dir, self.output_folder) | ||
Config.templateRenderingDict['casa_config_base64'] = self.generate_base64_file(self.config_json_fn, 1) | ||
|
||
|
||
self.renderTemplateInOut(self.ldif_client_fn, self.templates_dir, self.output_folder) | ||
self.renderTemplateInOut(self.ldif_config_fn, self.templates_dir, self.output_folder) | ||
|
||
casa_client_ldif_parser = myLdifParser(self.ldif_client_fn) | ||
casa_client_ldif_parser.parse() | ||
|
||
casa_client_ldif_parser.entries[0][1]['jansScope'] += self.casa_scopes | ||
with open(self.ldif_client_fn, 'wb') as w: | ||
casa_client_ldif_writer = LDIFWriter(w) | ||
casa_client_ldif_writer.unparse(casa_client_ldif_parser.entries[0][0], casa_client_ldif_parser.entries[0][1]) | ||
|
||
self.dbUtils.import_ldif([self.ldif_client_fn, self.ldif_config_fn, self.ldif_auth_script_fn]) | ||
|
||
|
||
def create_folders(self): | ||
self.createDirs(self.pylib_dir) | ||
for cdir in ('plugins', 'static'): | ||
self.createDirs(os.path.join(self.jetty_service_dir, cdir)) | ||
|
||
def create_scopes(self): | ||
self.logIt("Creating Casa client scopes") | ||
scopes = base.readJsonFile(self.scopes_fn) | ||
casa_scopes_ldif_fn = os.path.join(self.output_folder, 'scopes.ldif') | ||
self.createDirs(self.output_folder) | ||
scope_ldif_fd = open(casa_scopes_ldif_fn, 'wb') | ||
scopes_list = [] | ||
|
||
ldif_scopes_writer = LDIFWriter(scope_ldif_fd, cols=1000) | ||
|
||
for scope in scopes: | ||
scope_dn = 'inum={},ou=scopes,o=jans'.format(scope['inum']) | ||
scopes_list.append(scope_dn) | ||
ldif_dict = { | ||
'objectClass': ['top', 'jansScope'], | ||
'description': [scope['description']], | ||
'displayName': [scope['displayName']], | ||
'inum': [scope['inum']], | ||
'jansDefScope': [str(scope['jansDefScope'])], | ||
'jansId': [scope['jansId']], | ||
'jansScopeTyp': [scope['jansScopeTyp']], | ||
'jansAttrs': [json.dumps({"spontaneousClientId":None, "spontaneousClientScopes":[], "showInConfigurationEndpoint": False})], | ||
} | ||
ldif_scopes_writer.unparse(scope_dn, ldif_dict) | ||
|
||
scope_ldif_fd.close() | ||
|
||
self.dbUtils.import_ldif([casa_scopes_ldif_fn]) | ||
|
||
return scopes_list | ||
|
||
def service_post_setup(self): | ||
self.chown(self.pylib_dir, Config.jetty_user, Config.jetty_group, recursive=True) | ||
self.chown(self.jetty_service_dir, Config.jetty_user, Config.jetty_group, recursive=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.