def add_dynamic_selfservice_enrollment(config, actions): ''' add_dynamic_actions - load the html of the dynamic tokens according to the policy definition :param actions: the allowd policy actions for the current scope :type actions: array of actions names :return: hash of {tokentype : html for tab} ''' dynanmic_actions = {} for tclass_object in set(tokenclass_registry.values()): tok = tclass_object.getClassType() if hasattr(tclass_object, 'getClassInfo'): try: selfservice = tclass_object.getClassInfo('selfservice', ret=None) # # check if we have a policy in the token definition for the enroll if selfservice.has_key('enroll') and 'enroll' + tok.upper() in actions: service = selfservice.get('enroll') tab = service.get('title') c.scope = tab.get('scope') t_file = tab.get('html') t_html = render(t_file) ''' remove empty lines ''' t_html = '\n'.join([line for line in t_html.split('\n') if line.strip() != '']) e_name = "%s.%s.%s" % (tok, 'selfservice', 'enroll') dynanmic_actions[e_name] = t_html # # check if there are other selfserive policy actions policy = tclass_object.getClassInfo('policy', ret=None) if 'selfservice' in policy: selfserv_policies = policy.get('selfservice').keys() for action in actions: if action in selfserv_policies: # # now lookup, if there is an additional section # # in the selfservice to render service = selfservice.get(action) tab = service.get('title') c.scope = tab.get('scope') t_file = tab.get('html') t_html = render(t_file) ''' remove empty lines ''' t_html = '\n'.join([line for line in t_html.split('\n') if line.strip() != '']) e_name = "%s.%s.%s" % (tok, 'selfservice', action) dynanmic_actions[e_name] = t_html except Exception as e: log.info('[_add_dynamic_actions] no policy for tokentype ' '%s found (%r)' % (unicode(tok), e)) return dynanmic_actions
def _getTokenTypeConfig(section="config"): """ _getTokenTypeConfig - retrieve from the dynamic token the tokentype section, eg. config or enroll :param section: the section of the tokentypeconfig :type section: string :return: dict with tab and page definition (rendered) :rtype: dict """ res = {} for tclass_object in set(tokenclass_registry.values()): tok = tclass_object.getClassType() if hasattr(tclass_object, "getClassInfo"): conf = tclass_object.getClassInfo(section, ret={}) # set globale render scope, so that the mako # renderer will return only a subsection from the template p_html = "" t_html = "" try: page = conf.get("page") c.scope = page.get("scope") p_html = render(os.path.sep + page.get("html")).decode("utf-8") p_html = remove_empty_lines(p_html) tab = conf.get("title") c.scope = tab.get("scope") t_html = render(os.path.sep + tab.get("html")).decode("utf-8") t_html = remove_empty_lines(t_html) except CompileException as cex: log.error( "[_getTokenTypeConfig] compile error while " "processing %r.%r:", tok, section, ) raise Exception(cex) except Exception as exx: log.debug("no config for token type %r (%r)", tok, exx) p_html = "" if len(p_html) > 0: res[tok] = {"html": p_html, "title": t_html} return res
def _getTokenTypeConfig(section='config'): ''' _getTokenTypeConfig - retrieve from the dynamic token the tokentype section, eg. config or enroll :param section: the section of the tokentypeconfig :type section: string :return: dict with tab and page definition (rendered) :rtype: dict ''' res = {} for tclass_object in set(tokenclass_registry.values()): tok = tclass_object.getClassType() if hasattr(tclass_object, 'getClassInfo'): conf = tclass_object.getClassInfo(section, ret={}) # set globale render scope, so that the mako # renderer will return only a subsection from the template p_html = '' t_html = '' try: page = conf.get('page') c.scope = page.get('scope') p_html = render(os.path.sep + page.get('html')).decode('utf-8') p_html = remove_empty_lines(p_html) tab = conf.get('title') c.scope = tab.get('scope') t_html = render(os.path.sep + tab.get('html')).decode('utf-8') t_html = remove_empty_lines(t_html) except CompileException as ex: log.exception("[_getTokenTypeConfig] compile error while " "processing %r.%r:" % (tok, section)) log.error("[_getTokenTypeConfig] %r" % ex) raise Exception(ex) except Exception as e: log.debug('no config for token type %r (%r)' % (tok, e)) p_html = '' if len(p_html) > 0: res[tok] = {'html': p_html, 'title': t_html} return res
def _getTokenTypeConfig(section='config'): ''' _getTokenTypeConfig - retrieve from the dynamic token the tokentype section, eg. config or enroll :param section: the section of the tokentypeconfig :type section: string :return: dict with tab and page definition (rendered) :rtype: dict ''' res = {} for tclass_object in set(tokenclass_registry.values()): tok = tclass_object.getClassType() if hasattr(tclass_object, 'getClassInfo'): conf = tclass_object.getClassInfo(section, ret={}) # set globale render scope, so that the mako # renderer will return only a subsection from the template p_html = '' t_html = '' try: page = conf.get('page') c.scope = page.get('scope') p_html = render(os.path.sep + page.get('html')) p_html = remove_empty_lines(p_html) tab = conf.get('title') c.scope = tab.get('scope') t_html = render(os.path.sep + tab.get('html')) t_html = remove_empty_lines(t_html) except CompileException as ex: log.exception("[_getTokenTypeConfig] compile error while " "processing %r.%r:" % (tok, section)) log.error("[_getTokenTypeConfig] %r" % ex) raise Exception(ex) except Exception as e: log.debug('no config for token type %r (%r)' % (tok, e)) p_html = '' if len (p_html) > 0: res[tok] = { 'html' : p_html, 'title' : t_html} return res
def _getTokenTypes(): ''' _getTokenTypes - retrieve the list of dynamic tokens and their title section :return: dict with token type and title :rtype: dict ''' tinfo = {} for tclass_object in set(tokenclass_registry.values()): tok = tclass_object.getClassType() if hasattr(tclass_object, 'getClassInfo'): tinfo[tok] = _(tclass_object.getClassInfo('title') or tok) return tinfo
def add_dynamic_selfservice_enrollment(config, actions): """ add_dynamic_actions - load the html of the dynamic tokens according to the policy definition :param actions: the allowd policy actions for the current scope :type actions: array of actions names :return: hash of {tokentype : html for tab} """ dynanmic_actions = {} for tclass_object in set(tokenclass_registry.values()): tok = tclass_object.getClassType() if hasattr(tclass_object, "getClassInfo"): try: selfservice = tclass_object.getClassInfo( "selfservice", ret=None ) # # check if we have a policy in the token definition for the enroll if ( "enroll" in selfservice and "enroll" + tok.upper() in actions ): service = selfservice.get("enroll") tab = service.get("title") c.scope = tab.get("scope") t_file = tab.get("html") t_html = render(t_file).decode() """ remove empty lines """ t_html = "\n".join( [ line for line in t_html.split("\n") if line.strip() != "" ] ) e_name = "%s.%s.%s" % (tok, "selfservice", "enroll") dynanmic_actions[e_name] = t_html # # check if there are other selfserive policy actions policy = tclass_object.getClassInfo("policy", ret=None) if "selfservice" in policy: selfserv_policies = list(policy.get("selfservice").keys()) for action in actions: if action in selfserv_policies: # # now lookup, if there is an additional section # # in the selfservice to render service = selfservice.get(action) tab = service.get("title") c.scope = tab.get("scope") t_file = tab.get("html") t_html = render(t_file).decode() """ remove empty lines """ t_html = "\n".join( [ line for line in t_html.split("\n") if line.strip() != "" ] ) e_name = "%s.%s.%s" % (tok, "selfservice", action) dynanmic_actions[e_name] = t_html except Exception as exx: log.info( "[_add_dynamic_actions] no policy for tokentype " "%r found (%r)", tok, exx, ) return dynanmic_actions