{"version":"1.1","schema_version":"1.1.0","plugin_version":"1.1.2","url":"https://tutos-gameserver.fr/2019/05/04/gluu-bien-choisir-son-serveur-d-impression/","llm_html_url":"https://tutos-gameserver.fr/2019/05/04/gluu-bien-choisir-son-serveur-d-impression/llm","llm_json_url":"https://tutos-gameserver.fr/2019/05/04/gluu-bien-choisir-son-serveur-d-impression/llm.json","manifest_url":"https://tutos-gameserver.fr/llm-endpoints-manifest.json","language":"fr-FR","locale":"fr_FR","title":"Gluu\n\n &#8211; Bien choisir son serveur d impression","site":{"name":"Tutos GameServer","url":"https://tutos-gameserver.fr/"},"author":{"id":1,"name":"Titanfall","url":"https://tutos-gameserver.fr/author/titanfall/"},"published_at":"2019-05-04T13:20:03+00:00","modified_at":"2019-05-04T13:20:03+00:00","word_count":1034,"reading_time_seconds":311,"summary":"# Vous trouverez ci-dessous un script d&#39;authentification utilisé par le serveur Gluu pour implémenter Duo Security pour une authentification à deux facteurs (2FA). depuis org.xdi.service.cdi.util, importez CdiUtil depuis org.xdi.oxauth.security import Identity depuis org.xdi.model.custom.script.type.auth, importez PersonAuthenticationType depuis org.xdi.oxauth.service import UserService, AuthenticationService depuis org.xdi.service, importez MailService depuis org.xdi.util, importez ArrayHelper depuis org.xdi.util import StringHelper import duo_web importer [&hellip;]","summary_points":["# Vous trouverez ci-dessous un script d&#39;authentification utilisé par le serveur Gluu pour implémenter Duo Security pour une authentification à deux facteurs (2FA).","depuis org.xdi.service.cdi.util, importez CdiUtil\r\ndepuis org.xdi.oxauth.security import Identity\r\ndepuis org.xdi.model.custom.script.type.auth, importez PersonAuthenticationType\r\ndepuis org.xdi.oxauth.service import UserService, AuthenticationService\r\ndepuis org.xdi.service, importez MailService\r\ndepuis org.xdi.util, importez ArrayHelper\r\ndepuis org.xdi.util import StringHelper\r\n\r\nimport duo_web\r\nimporter json\r\n\r\nclasse PersonAuthentication (PersonAuthenticationType):\r\n    def __init __ (self, currentTimeMillis):\r\n        self.currentTimeMillis = currentTimeMillis\r\n\r\n    def init (self, configurationAttributes):\r\n        print &quot;Duo.","Initialization&quot;\r\n\r\n        duo_creds_file = configurationAttributes.get (&quot;duo_creds_file&quot;).","getValue2 ()\r\n        # Charger les informations d&#39;identification du fichier\r\n        f = open (duo_creds_file, &#39;r&#39;)\r\n        essayer:\r\n            creds = json.loads (f.read ())\r\n        sauf:\r\n            print &quot;Duo."],"topics":["Serveur d'impression"],"entities":[],"entities_metadata":[{"id":10,"name":"Serveur d'impression","slug":"serveur-dimpression","taxonomy":"category","count":3907,"url":"https://tutos-gameserver.fr/category/serveur-dimpression/"}],"tags":["Serveur d'impression"],"content_hash":"eeb1657fa8e32edf660a80f17b8e2689","plain_text":"# Vous trouverez ci-dessous un script d&#39;authentification utilisé par le serveur Gluu pour implémenter Duo Security pour une authentification à deux facteurs (2FA).\r\n\r\ndepuis org.xdi.service.cdi.util, importez CdiUtil\r\ndepuis org.xdi.oxauth.security import Identity\r\ndepuis org.xdi.model.custom.script.type.auth, importez PersonAuthenticationType\r\ndepuis org.xdi.oxauth.service import UserService, AuthenticationService\r\ndepuis org.xdi.service, importez MailService\r\ndepuis org.xdi.util, importez ArrayHelper\r\ndepuis org.xdi.util import StringHelper\r\n\r\nimport duo_web\r\nimporter json\r\n\r\nclasse PersonAuthentication (PersonAuthenticationType):\r\n    def __init __ (self, currentTimeMillis):\r\n        self.currentTimeMillis = currentTimeMillis\r\n\r\n    def init (self, configurationAttributes):\r\n        print &quot;Duo. Initialization&quot;\r\n\r\n        duo_creds_file = configurationAttributes.get (&quot;duo_creds_file&quot;). getValue2 ()\r\n        # Charger les informations d&#39;identification du fichier\r\n        f = open (duo_creds_file, &#39;r&#39;)\r\n        essayer:\r\n            creds = json.loads (f.read ())\r\n        sauf:\r\n            print &quot;Duo. Initialization. Impossible de charger les créations à partir du fichier:&quot;, duo_creds_file\r\n            retourne Faux\r\n        enfin:\r\n            f.close ()\r\n\r\n        self.ikey = str (creds[\"ikey\"])\r\n        self.skey = str (creds[\"skey\"])\r\n        self.akey = str (creds[\"akey\"])\r\n\r\n        self.use_duo_group = False\r\n        if (configurationAttributes.containsKey (&quot;groupe_duo&quot;)):\r\n            self.duo_group = configurationAttributes.get (&quot;duo_group&quot;). getValue2 ()\r\n            self.use_duo_group = True\r\n            print &quot;Duo. Initialization. Utiliser Duo uniquement si l&#39;utilisateur appartient au groupe:&quot;, self.duo_group\r\n\r\n        self.use_audit_group = False\r\n        if (configurationAttributes.containsKey (&quot;groupe_audits&quot;)):\r\n            self.audit_group = configurationAttributes.get (&quot;audit_group&quot;). getValue2 ()\r\n\r\n            if (pas configurationAttributes.containsKey (&quot;audit_group_email&quot;)):\r\n                print &quot;Duo. Initialization. La propriété audit_group_email n&#39;est pas spécifiée&quot;\r\n                retourne Faux\r\n\r\n            self.audit_email = configurationAttributes.get (&quot;audit_group_email&quot;). getValue2 ()\r\n            self.use_audit_group = True\r\n\r\n            print &quot;Duo. Initialization. Utilisation de audito group:&quot;, self.audit_group\r\n            \r\n        if (self.use_duo_group ou self.use_audit_group):\r\n            if (pas configurationAttributes.containsKey (&quot;audit_attribute&quot;)):\r\n                print &quot;Duo. Initialization. La propriété audit_attribute n&#39;est pas spécifiée&quot;\r\n                retourne Faux\r\n            autre:\r\n                self.audit_attribute = configurationAttributes.get (&quot;audit_attribute&quot;). getValue2 ()\r\n\r\n        print &quot;Duo. Initialisé avec succès&quot;\r\n        retourne True\r\n\r\n    def destroy (self, configurationAttributes):\r\n        print &quot;Duo. Destroy&quot;\r\n        print &quot;Duo. Détruit avec succès&quot;\r\n        retourne True\r\n\r\n    def getApiVersion (auto):\r\n        retour 1\r\n\r\n    def isValidAuthenticationMethod (self, usageType, configurationAttributes):\r\n        retourne True\r\n\r\n    def getAlternativeAuthenticationMethod (self, usageType, configurationAttributes):\r\n        retourner Aucun\r\n\r\n    def authenticate (self, configurationAttributes, requestParameters, step):\r\n        duo_host = configurationAttributes.get (&quot;duo_host&quot;). getValue2 ()\r\n\r\n        authenticationService = CdiUtil.bean (AuthenticationService)\r\n\r\n        identity = CdiUtil.bean (Identity)\r\n\r\n        si (étape == 1):\r\n            print &quot;Duo. Authentifiez-vous pour l&#39;étape 1&quot;\r\n\r\n            credentials = identity.getCredentials ()\r\n            nom_utilisateur = credentials.getUsername ()\r\n            mot_de_passe_utilisateur = credentials.getPassword ()\r\n\r\n            logs_in = Faux\r\n            if (StringHelper.isNotEmptyString (nom_utilisateur) et StringHelper.isNotEmptyString (mot_utilisateur_utilisateur)):\r\n                userService = CdiUtil.bean (UserService)\r\n                log_in = authenticationService.authenticate (nom d&#39;utilisateur, mot de passe utilisateur)\r\n\r\n            si (non connecté):\r\n                retourne Faux\r\n\r\n            utilisateur = authenticationService.getAuthenticatedUser ()\r\n            si (self.use_duo_group):\r\n                print &quot;Duo. Authentifiez-vous à l&#39;étape 1. Vérification de l&#39;appartenance de l&#39;utilisateur au groupe Duo&quot;\r\n                is_member_duo_group = self.isUserMemberOfGroup (utilisateur, self.audit_attribute, self.duo_group)\r\n                if (is_member_duo_group):\r\n                    print &quot;Duo. Authentifiez-vous à l&#39;étape 1. Utilisateur &#39;&quot; + utilisateur.getUserId () + &quot;&#39; membre du groupe Duo&quot;\r\n                    duo_count_login_steps = 2\r\n                autre:\r\n                    self.processAuditGroup (utilisateur)\r\n                    duo_count_login_steps = 1\r\n\r\n                identity.setWorkingParameter (&quot;duo_count_login_steps&quot;, duo_count_login_steps)\r\n\r\n            retourne True\r\n        elif (step == 2):\r\n            print &quot;Duo. Authentifiez-vous à l&#39;étape 2&quot;\r\n            utilisateur = authenticationService.getAuthenticatedUser ()\r\n            si utilisateur == Aucun:\r\n                print &quot;Duo. Authentifiez-vous à l&#39;étape 2. Echec de la détermination du nom d&#39;utilisateur&quot;\r\n                retourne Faux\r\n\r\n            nom_utilisateur = utilisateur.getUserId ()\r\n\r\n            sig_response_array = requestParameters.get (&quot;sig_response&quot;)\r\n            si ArrayHelper.isEmpty (sig_response_array):\r\n                print &quot;Duo. Authentifiez-vous à l&#39;étape 2. sig_response est vide&quot;\r\n                retourne Faux\r\n\r\n            duo_sig_response = sig_response_array[0]\r\n\r\n            print &quot;Duo. Authentifiez-vous à l&#39;étape 2. duo_sig_response:&quot; + duo_sig_response\r\n\r\n            nom_utilisateur_authentifié = duo_web.verify_response (self.ikey, self.skey, self.akey, duo_sig_response)\r\n\r\n            print &quot;Duo. Authentifiez-vous à l&#39;étape 2. nom d&#39;utilisateur authentifié:&quot; + nom d&#39;utilisateur authentifié + &quot;, nom d&#39;utilisateur attendu:&quot; + nom d&#39;utilisateur\r\n\r\n            if (non StringHelper.equals (nom d&#39;utilisateur, nom d&#39;utilisateur authentifié)):\r\n                retourne Faux\r\n\r\n            self.processAuditGroup (utilisateur)\r\n\r\n            retourne True\r\n        autre:\r\n            retourne Faux\r\n\r\n    def prepareForStep (self, configurationAttributes, requestParameters, step):\r\n        identity = CdiUtil.bean (Identity)\r\n        authenticationService = CdiUtil.bean (AuthenticationService)\r\n\r\n        duo_host = configurationAttributes.get (&quot;duo_host&quot;). getValue2 ()\r\n\r\n        si (étape == 1):\r\n            print &quot;Duo. Préparez-vous pour l&#39;étape 1&quot;\r\n\r\n            retourne True\r\n        elif (step == 2):\r\n            print &quot;Duo. Préparez-vous pour l&#39;étape 2&quot;\r\n\r\n            utilisateur = authenticationService.getAuthenticatedUser ()\r\n            si (utilisateur == aucun):\r\n                print &quot;Duo. Préparez-vous pour l&#39;étape 2. Echec de la détermination du nom d&#39;utilisateur&quot;\r\n                retourne Faux\r\n            nom_utilisateur = utilisateur.getUserId ()\r\n\r\n            duo_sig_request = duo_web.sign_request (self.ikey, self.skey, self.akey, nom d&#39;utilisateur)\r\n            print &quot;Duo. Préparez-vous pour l&#39;étape 2. duo_sig_request:&quot; + duo_sig_request\r\n            \r\n            identity.setWorkingParameter (&quot;duo_host&quot;, duo_host)\r\n            identity.setWorkingParameter (&quot;duo_sig_request&quot;, duo_sig_request)\r\n\r\n            retourne True\r\n        autre:\r\n            retourne Faux\r\n\r\n    def getExtraParametersForStep (self, configurationAttributes, step):\r\n        retourner Aucun\r\n\r\n    def getCountAuthenticationSteps (self, configurationAttributes):\r\n        identity = CdiUtil.bean (Identity)\r\n        if (identity.isSetWorkingParameter (&quot;duo_count_login_steps&quot;)):\r\n            return identity.getWorkingParameter (&quot;duo_count_login_steps&quot;)\r\n\r\n        retour 2\r\n\r\n    def getPageForStep (self, configurationAttributes, step):\r\n        si (étape == 2):\r\n            retourne &quot;/auth/duo/duologin.xhtml&quot;\r\n        revenir &quot;&quot;\r\n\r\n    def logout (self, configurationAttributes, requestParameters):\r\n        retourne True\r\n\r\n    def isUserMemberOfGroup (self, utilisateur, attribut, groupe):\r\n        is_member = False\r\n        member_of_list = user.getAttributeValues ​​(attribut)\r\n        if (member_of_list! = None):\r\n            pour member_of dans member_of_list:\r\n                si StringHelper.equalsIgnoreCase (group, member_of) ou member_of.endswith (group):\r\n                    is_member = True\r\n                    Pause\r\n\r\n        retourne_membre\r\n\r\n    def processAuditGroup (self, user):\r\n        si (self.use_audit_group):\r\n            is_member = self.isUserMemberOfGroup (utilisateur, self.audit_attribute, self.audit_group)\r\n            if (is_member):\r\n                print &quot;Duo. Authentifiez-vous pour processAuditGroup. User &#39;&quot; + user.getUserId () + &quot;&#39; membre du groupe d&#39;audit&quot;\r\n                print &quot;Duo. Authentifiez-vous pour processAuditGroup. Envoi d&#39;un courrier électronique concernant l&#39;utilisateur &#39;&quot; + user.getUserId () + &quot;&#39; se connecter à&quot;, self.audit_email\r\n                \r\n                # Envoyer un e-mail à l&#39;administrateur\r\n                user_id = user.getUserId ()\r\n                mailService = CdiUtil.bean (MailService)\r\n                subject = &quot;Connexion de l&#39;utilisateur:&quot; + user_id\r\n                body = &quot;Connexion utilisateur:&quot; + user_id\r\n                mailService.sendMail (self.audit_email, sujet, corps)    \n                            \n\nClick to rate this post!\r\n                                   \r\n                               [Total: 0  Average: 0]","paragraphs":["# Vous trouverez ci-dessous un script d&#39;authentification utilisé par le serveur Gluu pour implémenter Duo Security pour une authentification à deux facteurs (2FA).","depuis org.xdi.service.cdi.util, importez CdiUtil\ndepuis org.xdi.oxauth.security import Identity\ndepuis org.xdi.model.custom.script.type.auth, importez PersonAuthenticationType\ndepuis org.xdi.oxauth.service import UserService, AuthenticationService\ndepuis org.xdi.service, importez MailService\ndepuis org.xdi.util, importez ArrayHelper\ndepuis org.xdi.util import StringHelper","import duo_web\nimporter json","classe PersonAuthentication (PersonAuthenticationType):\n    def __init __ (self, currentTimeMillis):\n        self.currentTimeMillis = currentTimeMillis","    def init (self, configurationAttributes):\n        print &quot;Duo. Initialization&quot;","        duo_creds_file = configurationAttributes.get (&quot;duo_creds_file&quot;). getValue2 ()\n        # Charger les informations d&#39;identification du fichier\n        f = open (duo_creds_file, &#39;r&#39;)\n        essayer:\n            creds = json.loads (f.read ())\n        sauf:\n            print &quot;Duo. Initialization. Impossible de charger les créations à partir du fichier:&quot;, duo_creds_file\n            retourne Faux\n        enfin:\n            f.close ()","        self.ikey = str (creds[\"ikey\"])\n        self.skey = str (creds[\"skey\"])\n        self.akey = str (creds[\"akey\"])","        self.use_duo_group = False\n        if (configurationAttributes.containsKey (&quot;groupe_duo&quot;)):\n            self.duo_group = configurationAttributes.get (&quot;duo_group&quot;). getValue2 ()\n            self.use_duo_group = True\n            print &quot;Duo. Initialization. Utiliser Duo uniquement si l&#39;utilisateur appartient au groupe:&quot;, self.duo_group","        self.use_audit_group = False\n        if (configurationAttributes.containsKey (&quot;groupe_audits&quot;)):\n            self.audit_group = configurationAttributes.get (&quot;audit_group&quot;). getValue2 ()","            if (pas configurationAttributes.containsKey (&quot;audit_group_email&quot;)):\n                print &quot;Duo. Initialization. La propriété audit_group_email n&#39;est pas spécifiée&quot;\n                retourne Faux","            self.audit_email = configurationAttributes.get (&quot;audit_group_email&quot;). getValue2 ()\n            self.use_audit_group = True","            print &quot;Duo. Initialization. Utilisation de audito group:&quot;, self.audit_group\n            \n        if (self.use_duo_group ou self.use_audit_group):\n            if (pas configurationAttributes.containsKey (&quot;audit_attribute&quot;)):\n                print &quot;Duo. Initialization. La propriété audit_attribute n&#39;est pas spécifiée&quot;\n                retourne Faux\n            autre:\n                self.audit_attribute = configurationAttributes.get (&quot;audit_attribute&quot;). getValue2 ()","        print &quot;Duo. Initialisé avec succès&quot;\n        retourne True","    def destroy (self, configurationAttributes):\n        print &quot;Duo. Destroy&quot;\n        print &quot;Duo. Détruit avec succès&quot;\n        retourne True","    def getApiVersion (auto):\n        retour 1","    def isValidAuthenticationMethod (self, usageType, configurationAttributes):\n        retourne True","    def getAlternativeAuthenticationMethod (self, usageType, configurationAttributes):\n        retourner Aucun","    def authenticate (self, configurationAttributes, requestParameters, step):\n        duo_host = configurationAttributes.get (&quot;duo_host&quot;). getValue2 ()","        authenticationService = CdiUtil.bean (AuthenticationService)","        identity = CdiUtil.bean (Identity)","        si (étape == 1):\n            print &quot;Duo. Authentifiez-vous pour l&#39;étape 1&quot;","            credentials = identity.getCredentials ()\n            nom_utilisateur = credentials.getUsername ()\n            mot_de_passe_utilisateur = credentials.getPassword ()","            logs_in = Faux\n            if (StringHelper.isNotEmptyString (nom_utilisateur) et StringHelper.isNotEmptyString (mot_utilisateur_utilisateur)):\n                userService = CdiUtil.bean (UserService)\n                log_in = authenticationService.authenticate (nom d&#39;utilisateur, mot de passe utilisateur)","            si (non connecté):\n                retourne Faux","            utilisateur = authenticationService.getAuthenticatedUser ()\n            si (self.use_duo_group):\n                print &quot;Duo. Authentifiez-vous à l&#39;étape 1. Vérification de l&#39;appartenance de l&#39;utilisateur au groupe Duo&quot;\n                is_member_duo_group = self.isUserMemberOfGroup (utilisateur, self.audit_attribute, self.duo_group)\n                if (is_member_duo_group):\n                    print &quot;Duo. Authentifiez-vous à l&#39;étape 1. Utilisateur &#39;&quot; + utilisateur.getUserId () + &quot;&#39; membre du groupe Duo&quot;\n                    duo_count_login_steps = 2\n                autre:\n                    self.processAuditGroup (utilisateur)\n                    duo_count_login_steps = 1","                identity.setWorkingParameter (&quot;duo_count_login_steps&quot;, duo_count_login_steps)","            retourne True\n        elif (step == 2):\n            print &quot;Duo. Authentifiez-vous à l&#39;étape 2&quot;\n            utilisateur = authenticationService.getAuthenticatedUser ()\n            si utilisateur == Aucun:\n                print &quot;Duo. Authentifiez-vous à l&#39;étape 2. Echec de la détermination du nom d&#39;utilisateur&quot;\n                retourne Faux","            nom_utilisateur = utilisateur.getUserId ()","            sig_response_array = requestParameters.get (&quot;sig_response&quot;)\n            si ArrayHelper.isEmpty (sig_response_array):\n                print &quot;Duo. Authentifiez-vous à l&#39;étape 2. sig_response est vide&quot;\n                retourne Faux","            duo_sig_response = sig_response_array[0]","print &quot;Duo. Authentifiez-vous à l&#39;étape 2. duo_sig_response:&quot; + duo_sig_response","            nom_utilisateur_authentifié = duo_web.verify_response (self.ikey, self.skey, self.akey, duo_sig_response)","            print &quot;Duo. Authentifiez-vous à l&#39;étape 2. nom d&#39;utilisateur authentifié:&quot; + nom d&#39;utilisateur authentifié + &quot;, nom d&#39;utilisateur attendu:&quot; + nom d&#39;utilisateur","            if (non StringHelper.equals (nom d&#39;utilisateur, nom d&#39;utilisateur authentifié)):\n                retourne Faux","            self.processAuditGroup (utilisateur)","            retourne True\n        autre:\n            retourne Faux","    def prepareForStep (self, configurationAttributes, requestParameters, step):\n        identity = CdiUtil.bean (Identity)\n        authenticationService = CdiUtil.bean (AuthenticationService)","        duo_host = configurationAttributes.get (&quot;duo_host&quot;). getValue2 ()","        si (étape == 1):\n            print &quot;Duo. Préparez-vous pour l&#39;étape 1&quot;","            retourne True\n        elif (step == 2):\n            print &quot;Duo. Préparez-vous pour l&#39;étape 2&quot;","            utilisateur = authenticationService.getAuthenticatedUser ()\n            si (utilisateur == aucun):\n                print &quot;Duo. Préparez-vous pour l&#39;étape 2. Echec de la détermination du nom d&#39;utilisateur&quot;\n                retourne Faux\n            nom_utilisateur = utilisateur.getUserId ()","            duo_sig_request = duo_web.sign_request (self.ikey, self.skey, self.akey, nom d&#39;utilisateur)\n            print &quot;Duo. Préparez-vous pour l&#39;étape 2. duo_sig_request:&quot; + duo_sig_request\n            \n            identity.setWorkingParameter (&quot;duo_host&quot;, duo_host)\n            identity.setWorkingParameter (&quot;duo_sig_request&quot;, duo_sig_request)","            retourne True\n        autre:\n            retourne Faux","    def getExtraParametersForStep (self, configurationAttributes, step):\n        retourner Aucun","    def getCountAuthenticationSteps (self, configurationAttributes):\n        identity = CdiUtil.bean (Identity)\n        if (identity.isSetWorkingParameter (&quot;duo_count_login_steps&quot;)):\n            return identity.getWorkingParameter (&quot;duo_count_login_steps&quot;)","        retour 2","    def getPageForStep (self, configurationAttributes, step):\n        si (étape == 2):\n            retourne &quot;/auth/duo/duologin.xhtml&quot;\n        revenir &quot;&quot;","    def logout (self, configurationAttributes, requestParameters):\n        retourne True","    def isUserMemberOfGroup (self, utilisateur, attribut, groupe):\n        is_member = False\n        member_of_list = user.getAttributeValues ​​(attribut)\n        if (member_of_list! = None):\n            pour member_of dans member_of_list:\n                si StringHelper.equalsIgnoreCase (group, member_of) ou member_of.endswith (group):\n                    is_member = True\n                    Pause","        retourne_membre","    def processAuditGroup (self, user):\n        si (self.use_audit_group):\n            is_member = self.isUserMemberOfGroup (utilisateur, self.audit_attribute, self.audit_group)\n            if (is_member):\n                print &quot;Duo. Authentifiez-vous pour processAuditGroup. User &#39;&quot; + user.getUserId () + &quot;&#39; membre du groupe d&#39;audit&quot;\n                print &quot;Duo. Authentifiez-vous pour processAuditGroup. Envoi d&#39;un courrier électronique concernant l&#39;utilisateur &#39;&quot; + user.getUserId () + &quot;&#39; se connecter à&quot;, self.audit_email\n                \n                # Envoyer un e-mail à l&#39;administrateur\n                user_id = user.getUserId ()\n                mailService = CdiUtil.bean (MailService)\n                subject = &quot;Connexion de l&#39;utilisateur:&quot; + user_id\n                body = &quot;Connexion utilisateur:&quot; + user_id\n                mailService.sendMail (self.audit_email, sujet, corps)","Click to rate this post!\n                                   \n                               [Total: 0  Average: 0]"],"content_blocks":[{"id":"text-1","type":"text","heading":"","plain_text":"# Vous trouverez ci-dessous un script d&#39;authentification utilisé par le serveur Gluu pour implémenter Duo Security pour une authentification à deux facteurs (2FA).","html":"<p># Vous trouverez ci-dessous un script d&#039;authentification utilisé par le serveur Gluu pour implémenter Duo Security pour une authentification à deux facteurs (2FA).</p>"},{"id":"text-2","type":"text","heading":"","plain_text":"depuis org.xdi.service.cdi.util, importez CdiUtil\ndepuis org.xdi.oxauth.security import Identity\ndepuis org.xdi.model.custom.script.type.auth, importez PersonAuthenticationType\ndepuis org.xdi.oxauth.service import UserService, AuthenticationService\ndepuis org.xdi.service, importez MailService\ndepuis org.xdi.util, importez ArrayHelper\ndepuis org.xdi.util import StringHelper","html":"<p>depuis org.xdi.service.cdi.util, importez CdiUtil\ndepuis org.xdi.oxauth.security import Identity\ndepuis org.xdi.model.custom.script.type.auth, importez PersonAuthenticationType\ndepuis org.xdi.oxauth.service import UserService, AuthenticationService\ndepuis org.xdi.service, importez MailService\ndepuis org.xdi.util, importez ArrayHelper\ndepuis org.xdi.util import StringHelper</p>"},{"id":"text-3","type":"text","heading":"","plain_text":"import duo_web\nimporter json","html":"<p>import duo_web\nimporter json</p>"},{"id":"text-4","type":"text","heading":"","plain_text":"classe PersonAuthentication (PersonAuthenticationType):\n    def __init __ (self, currentTimeMillis):\n        self.currentTimeMillis = currentTimeMillis","html":"<p>classe PersonAuthentication (PersonAuthenticationType):\n    def __init __ (self, currentTimeMillis):\n        self.currentTimeMillis = currentTimeMillis</p>"},{"id":"text-5","type":"text","heading":"","plain_text":"    def init (self, configurationAttributes):\n        print &quot;Duo. Initialization&quot;","html":"<p>    def init (self, configurationAttributes):\n        print &quot;Duo. Initialization&quot;</p>"},{"id":"text-6","type":"text","heading":"","plain_text":"        duo_creds_file = configurationAttributes.get (&quot;duo_creds_file&quot;). getValue2 ()\n        # Charger les informations d&#39;identification du fichier\n        f = open (duo_creds_file, &#39;r&#39;)\n        essayer:\n            creds = json.loads (f.read ())\n        sauf:\n            print &quot;Duo. Initialization. Impossible de charger les créations à partir du fichier:&quot;, duo_creds_file\n            retourne Faux\n        enfin:\n            f.close ()","html":"<p>        duo_creds_file = configurationAttributes.get (&quot;duo_creds_file&quot;). getValue2 ()\n        # Charger les informations d&#039;identification du fichier\n        f = open (duo_creds_file, &#039;r&#039;)\n        essayer:\n            creds = json.loads (f.read ())\n        sauf:\n            print &quot;Duo. Initialization. Impossible de charger les créations à partir du fichier:&quot;, duo_creds_file\n            retourne Faux\n        enfin:\n            f.close ()</p>"},{"id":"text-7","type":"text","heading":"","plain_text":"        self.ikey = str (creds[\"ikey\"])\n        self.skey = str (creds[\"skey\"])\n        self.akey = str (creds[\"akey\"])","html":"<p>        self.ikey = str (creds[&quot;ikey&quot;])\n        self.skey = str (creds[&quot;skey&quot;])\n        self.akey = str (creds[&quot;akey&quot;])</p>"},{"id":"text-8","type":"text","heading":"","plain_text":"        self.use_duo_group = False\n        if (configurationAttributes.containsKey (&quot;groupe_duo&quot;)):\n            self.duo_group = configurationAttributes.get (&quot;duo_group&quot;). getValue2 ()\n            self.use_duo_group = True\n            print &quot;Duo. Initialization. Utiliser Duo uniquement si l&#39;utilisateur appartient au groupe:&quot;, self.duo_group","html":"<p>        self.use_duo_group = False\n        if (configurationAttributes.containsKey (&quot;groupe_duo&quot;)):\n            self.duo_group = configurationAttributes.get (&quot;duo_group&quot;). getValue2 ()\n            self.use_duo_group = True\n            print &quot;Duo. Initialization. Utiliser Duo uniquement si l&#039;utilisateur appartient au groupe:&quot;, self.duo_group</p>"},{"id":"text-9","type":"text","heading":"","plain_text":"        self.use_audit_group = False\n        if (configurationAttributes.containsKey (&quot;groupe_audits&quot;)):\n            self.audit_group = configurationAttributes.get (&quot;audit_group&quot;). getValue2 ()","html":"<p>        self.use_audit_group = False\n        if (configurationAttributes.containsKey (&quot;groupe_audits&quot;)):\n            self.audit_group = configurationAttributes.get (&quot;audit_group&quot;). getValue2 ()</p>"},{"id":"text-10","type":"text","heading":"","plain_text":"            if (pas configurationAttributes.containsKey (&quot;audit_group_email&quot;)):\n                print &quot;Duo. Initialization. La propriété audit_group_email n&#39;est pas spécifiée&quot;\n                retourne Faux","html":"<p>            if (pas configurationAttributes.containsKey (&quot;audit_group_email&quot;)):\n                print &quot;Duo. Initialization. La propriété audit_group_email n&#039;est pas spécifiée&quot;\n                retourne Faux</p>"},{"id":"text-11","type":"text","heading":"","plain_text":"            self.audit_email = configurationAttributes.get (&quot;audit_group_email&quot;). getValue2 ()\n            self.use_audit_group = True","html":"<p>            self.audit_email = configurationAttributes.get (&quot;audit_group_email&quot;). getValue2 ()\n            self.use_audit_group = True</p>"},{"id":"text-12","type":"text","heading":"","plain_text":"            print &quot;Duo. Initialization. Utilisation de audito group:&quot;, self.audit_group\n            \n        if (self.use_duo_group ou self.use_audit_group):\n            if (pas configurationAttributes.containsKey (&quot;audit_attribute&quot;)):\n                print &quot;Duo. Initialization. La propriété audit_attribute n&#39;est pas spécifiée&quot;\n                retourne Faux\n            autre:\n                self.audit_attribute = configurationAttributes.get (&quot;audit_attribute&quot;). getValue2 ()","html":"<p>            print &quot;Duo. Initialization. Utilisation de audito group:&quot;, self.audit_group\n            \n        if (self.use_duo_group ou self.use_audit_group):\n            if (pas configurationAttributes.containsKey (&quot;audit_attribute&quot;)):\n                print &quot;Duo. Initialization. La propriété audit_attribute n&#039;est pas spécifiée&quot;\n                retourne Faux\n            autre:\n                self.audit_attribute = configurationAttributes.get (&quot;audit_attribute&quot;). getValue2 ()</p>"},{"id":"text-13","type":"text","heading":"","plain_text":"        print &quot;Duo. Initialisé avec succès&quot;\n        retourne True","html":"<p>        print &quot;Duo. Initialisé avec succès&quot;\n        retourne True</p>"},{"id":"text-14","type":"text","heading":"","plain_text":"    def destroy (self, configurationAttributes):\n        print &quot;Duo. Destroy&quot;\n        print &quot;Duo. Détruit avec succès&quot;\n        retourne True","html":"<p>    def destroy (self, configurationAttributes):\n        print &quot;Duo. Destroy&quot;\n        print &quot;Duo. Détruit avec succès&quot;\n        retourne True</p>"},{"id":"text-15","type":"text","heading":"","plain_text":"    def getApiVersion (auto):\n        retour 1","html":"<p>    def getApiVersion (auto):\n        retour 1</p>"},{"id":"text-16","type":"text","heading":"","plain_text":"    def isValidAuthenticationMethod (self, usageType, configurationAttributes):\n        retourne True","html":"<p>    def isValidAuthenticationMethod (self, usageType, configurationAttributes):\n        retourne True</p>"},{"id":"text-17","type":"text","heading":"","plain_text":"    def getAlternativeAuthenticationMethod (self, usageType, configurationAttributes):\n        retourner Aucun","html":"<p>    def getAlternativeAuthenticationMethod (self, usageType, configurationAttributes):\n        retourner Aucun</p>"},{"id":"text-18","type":"text","heading":"","plain_text":"    def authenticate (self, configurationAttributes, requestParameters, step):\n        duo_host = configurationAttributes.get (&quot;duo_host&quot;). getValue2 ()","html":"<p>    def authenticate (self, configurationAttributes, requestParameters, step):\n        duo_host = configurationAttributes.get (&quot;duo_host&quot;). getValue2 ()</p>"},{"id":"text-19","type":"text","heading":"","plain_text":"        authenticationService = CdiUtil.bean (AuthenticationService)","html":"<p>        authenticationService = CdiUtil.bean (AuthenticationService)</p>"},{"id":"text-20","type":"text","heading":"","plain_text":"        identity = CdiUtil.bean (Identity)","html":"<p>        identity = CdiUtil.bean (Identity)</p>"},{"id":"text-21","type":"text","heading":"","plain_text":"        si (étape == 1):\n            print &quot;Duo. Authentifiez-vous pour l&#39;étape 1&quot;","html":"<p>        si (étape == 1):\n            print &quot;Duo. Authentifiez-vous pour l&#039;étape 1&quot;</p>"},{"id":"text-22","type":"text","heading":"","plain_text":"            credentials = identity.getCredentials ()\n            nom_utilisateur = credentials.getUsername ()\n            mot_de_passe_utilisateur = credentials.getPassword ()","html":"<p>            credentials = identity.getCredentials ()\n            nom_utilisateur = credentials.getUsername ()\n            mot_de_passe_utilisateur = credentials.getPassword ()</p>"},{"id":"text-23","type":"text","heading":"","plain_text":"            logs_in = Faux\n            if (StringHelper.isNotEmptyString (nom_utilisateur) et StringHelper.isNotEmptyString (mot_utilisateur_utilisateur)):\n                userService = CdiUtil.bean (UserService)\n                log_in = authenticationService.authenticate (nom d&#39;utilisateur, mot de passe utilisateur)","html":"<p>            logs_in = Faux\n            if (StringHelper.isNotEmptyString (nom_utilisateur) et StringHelper.isNotEmptyString (mot_utilisateur_utilisateur)):\n                userService = CdiUtil.bean (UserService)\n                log_in = authenticationService.authenticate (nom d&#039;utilisateur, mot de passe utilisateur)</p>"},{"id":"text-24","type":"text","heading":"","plain_text":"            si (non connecté):\n                retourne Faux","html":"<p>            si (non connecté):\n                retourne Faux</p>"},{"id":"text-25","type":"text","heading":"","plain_text":"            utilisateur = authenticationService.getAuthenticatedUser ()\n            si (self.use_duo_group):\n                print &quot;Duo. Authentifiez-vous à l&#39;étape 1. Vérification de l&#39;appartenance de l&#39;utilisateur au groupe Duo&quot;\n                is_member_duo_group = self.isUserMemberOfGroup (utilisateur, self.audit_attribute, self.duo_group)\n                if (is_member_duo_group):\n                    print &quot;Duo. Authentifiez-vous à l&#39;étape 1. Utilisateur &#39;&quot; + utilisateur.getUserId () + &quot;&#39; membre du groupe Duo&quot;\n                    duo_count_login_steps = 2\n                autre:\n                    self.processAuditGroup (utilisateur)\n                    duo_count_login_steps = 1","html":"<p>            utilisateur = authenticationService.getAuthenticatedUser ()\n            si (self.use_duo_group):\n                print &quot;Duo. Authentifiez-vous à l&#039;étape 1. Vérification de l&#039;appartenance de l&#039;utilisateur au groupe Duo&quot;\n                is_member_duo_group = self.isUserMemberOfGroup (utilisateur, self.audit_attribute, self.duo_group)\n                if (is_member_duo_group):\n                    print &quot;Duo. Authentifiez-vous à l&#039;étape 1. Utilisateur &#039;&quot; + utilisateur.getUserId () + &quot;&#039; membre du groupe Duo&quot;\n                    duo_count_login_steps = 2\n                autre:\n                    self.processAuditGroup (utilisateur)\n                    duo_count_login_steps = 1</p>"},{"id":"text-26","type":"text","heading":"","plain_text":"                identity.setWorkingParameter (&quot;duo_count_login_steps&quot;, duo_count_login_steps)","html":"<p>                identity.setWorkingParameter (&quot;duo_count_login_steps&quot;, duo_count_login_steps)</p>"},{"id":"text-27","type":"text","heading":"","plain_text":"            retourne True\n        elif (step == 2):\n            print &quot;Duo. Authentifiez-vous à l&#39;étape 2&quot;\n            utilisateur = authenticationService.getAuthenticatedUser ()\n            si utilisateur == Aucun:\n                print &quot;Duo. Authentifiez-vous à l&#39;étape 2. Echec de la détermination du nom d&#39;utilisateur&quot;\n                retourne Faux","html":"<p>            retourne True\n        elif (step == 2):\n            print &quot;Duo. Authentifiez-vous à l&#039;étape 2&quot;\n            utilisateur = authenticationService.getAuthenticatedUser ()\n            si utilisateur == Aucun:\n                print &quot;Duo. Authentifiez-vous à l&#039;étape 2. Echec de la détermination du nom d&#039;utilisateur&quot;\n                retourne Faux</p>"},{"id":"text-28","type":"text","heading":"","plain_text":"            nom_utilisateur = utilisateur.getUserId ()","html":"<p>            nom_utilisateur = utilisateur.getUserId ()</p>"},{"id":"text-29","type":"text","heading":"","plain_text":"            sig_response_array = requestParameters.get (&quot;sig_response&quot;)\n            si ArrayHelper.isEmpty (sig_response_array):\n                print &quot;Duo. Authentifiez-vous à l&#39;étape 2. sig_response est vide&quot;\n                retourne Faux","html":"<p>            sig_response_array = requestParameters.get (&quot;sig_response&quot;)\n            si ArrayHelper.isEmpty (sig_response_array):\n                print &quot;Duo. Authentifiez-vous à l&#039;étape 2. sig_response est vide&quot;\n                retourne Faux</p>"},{"id":"text-30","type":"text","heading":"","plain_text":"            duo_sig_response = sig_response_array[0]","html":"<p>            duo_sig_response = sig_response_array[0]</p>"},{"id":"text-31","type":"text","heading":"","plain_text":"print &quot;Duo. Authentifiez-vous à l&#39;étape 2. duo_sig_response:&quot; + duo_sig_response","html":"<p>print &quot;Duo. Authentifiez-vous à l&#039;étape 2. duo_sig_response:&quot; + duo_sig_response</p>"},{"id":"text-32","type":"text","heading":"","plain_text":"            nom_utilisateur_authentifié = duo_web.verify_response (self.ikey, self.skey, self.akey, duo_sig_response)","html":"<p>            nom_utilisateur_authentifié = duo_web.verify_response (self.ikey, self.skey, self.akey, duo_sig_response)</p>"},{"id":"text-33","type":"text","heading":"","plain_text":"            print &quot;Duo. Authentifiez-vous à l&#39;étape 2. nom d&#39;utilisateur authentifié:&quot; + nom d&#39;utilisateur authentifié + &quot;, nom d&#39;utilisateur attendu:&quot; + nom d&#39;utilisateur","html":"<p>            print &quot;Duo. Authentifiez-vous à l&#039;étape 2. nom d&#039;utilisateur authentifié:&quot; + nom d&#039;utilisateur authentifié + &quot;, nom d&#039;utilisateur attendu:&quot; + nom d&#039;utilisateur</p>"},{"id":"text-34","type":"text","heading":"","plain_text":"            if (non StringHelper.equals (nom d&#39;utilisateur, nom d&#39;utilisateur authentifié)):\n                retourne Faux","html":"<p>            if (non StringHelper.equals (nom d&#039;utilisateur, nom d&#039;utilisateur authentifié)):\n                retourne Faux</p>"},{"id":"text-35","type":"text","heading":"","plain_text":"            self.processAuditGroup (utilisateur)","html":"<p>            self.processAuditGroup (utilisateur)</p>"},{"id":"text-36","type":"text","heading":"","plain_text":"            retourne True\n        autre:\n            retourne Faux","html":"<p>            retourne True\n        autre:\n            retourne Faux</p>"},{"id":"text-37","type":"text","heading":"","plain_text":"    def prepareForStep (self, configurationAttributes, requestParameters, step):\n        identity = CdiUtil.bean (Identity)\n        authenticationService = CdiUtil.bean (AuthenticationService)","html":"<p>    def prepareForStep (self, configurationAttributes, requestParameters, step):\n        identity = CdiUtil.bean (Identity)\n        authenticationService = CdiUtil.bean (AuthenticationService)</p>"},{"id":"text-38","type":"text","heading":"","plain_text":"        duo_host = configurationAttributes.get (&quot;duo_host&quot;). getValue2 ()","html":"<p>        duo_host = configurationAttributes.get (&quot;duo_host&quot;). getValue2 ()</p>"},{"id":"text-39","type":"text","heading":"","plain_text":"        si (étape == 1):\n            print &quot;Duo. Préparez-vous pour l&#39;étape 1&quot;","html":"<p>        si (étape == 1):\n            print &quot;Duo. Préparez-vous pour l&#039;étape 1&quot;</p>"},{"id":"text-40","type":"text","heading":"","plain_text":"            retourne True\n        elif (step == 2):\n            print &quot;Duo. Préparez-vous pour l&#39;étape 2&quot;","html":"<p>            retourne True\n        elif (step == 2):\n            print &quot;Duo. Préparez-vous pour l&#039;étape 2&quot;</p>"},{"id":"text-41","type":"text","heading":"","plain_text":"            utilisateur = authenticationService.getAuthenticatedUser ()\n            si (utilisateur == aucun):\n                print &quot;Duo. Préparez-vous pour l&#39;étape 2. Echec de la détermination du nom d&#39;utilisateur&quot;\n                retourne Faux\n            nom_utilisateur = utilisateur.getUserId ()","html":"<p>            utilisateur = authenticationService.getAuthenticatedUser ()\n            si (utilisateur == aucun):\n                print &quot;Duo. Préparez-vous pour l&#039;étape 2. Echec de la détermination du nom d&#039;utilisateur&quot;\n                retourne Faux\n            nom_utilisateur = utilisateur.getUserId ()</p>"},{"id":"text-42","type":"text","heading":"","plain_text":"            duo_sig_request = duo_web.sign_request (self.ikey, self.skey, self.akey, nom d&#39;utilisateur)\n            print &quot;Duo. Préparez-vous pour l&#39;étape 2. duo_sig_request:&quot; + duo_sig_request\n            \n            identity.setWorkingParameter (&quot;duo_host&quot;, duo_host)\n            identity.setWorkingParameter (&quot;duo_sig_request&quot;, duo_sig_request)","html":"<p>            duo_sig_request = duo_web.sign_request (self.ikey, self.skey, self.akey, nom d&#039;utilisateur)\n            print &quot;Duo. Préparez-vous pour l&#039;étape 2. duo_sig_request:&quot; + duo_sig_request\n            \n            identity.setWorkingParameter (&quot;duo_host&quot;, duo_host)\n            identity.setWorkingParameter (&quot;duo_sig_request&quot;, duo_sig_request)</p>"},{"id":"text-43","type":"text","heading":"","plain_text":"            retourne True\n        autre:\n            retourne Faux","html":"<p>            retourne True\n        autre:\n            retourne Faux</p>"},{"id":"text-44","type":"text","heading":"","plain_text":"    def getExtraParametersForStep (self, configurationAttributes, step):\n        retourner Aucun","html":"<p>    def getExtraParametersForStep (self, configurationAttributes, step):\n        retourner Aucun</p>"},{"id":"text-45","type":"text","heading":"","plain_text":"    def getCountAuthenticationSteps (self, configurationAttributes):\n        identity = CdiUtil.bean (Identity)\n        if (identity.isSetWorkingParameter (&quot;duo_count_login_steps&quot;)):\n            return identity.getWorkingParameter (&quot;duo_count_login_steps&quot;)","html":"<p>    def getCountAuthenticationSteps (self, configurationAttributes):\n        identity = CdiUtil.bean (Identity)\n        if (identity.isSetWorkingParameter (&quot;duo_count_login_steps&quot;)):\n            return identity.getWorkingParameter (&quot;duo_count_login_steps&quot;)</p>"},{"id":"text-46","type":"text","heading":"","plain_text":"        retour 2","html":"<p>        retour 2</p>"},{"id":"text-47","type":"text","heading":"","plain_text":"    def getPageForStep (self, configurationAttributes, step):\n        si (étape == 2):\n            retourne &quot;/auth/duo/duologin.xhtml&quot;\n        revenir &quot;&quot;","html":"<p>    def getPageForStep (self, configurationAttributes, step):\n        si (étape == 2):\n            retourne &quot;/auth/duo/duologin.xhtml&quot;\n        revenir &quot;&quot;</p>"},{"id":"text-48","type":"text","heading":"","plain_text":"    def logout (self, configurationAttributes, requestParameters):\n        retourne True","html":"<p>    def logout (self, configurationAttributes, requestParameters):\n        retourne True</p>"},{"id":"text-49","type":"text","heading":"","plain_text":"    def isUserMemberOfGroup (self, utilisateur, attribut, groupe):\n        is_member = False\n        member_of_list = user.getAttributeValues ​​(attribut)\n        if (member_of_list! = None):\n            pour member_of dans member_of_list:\n                si StringHelper.equalsIgnoreCase (group, member_of) ou member_of.endswith (group):\n                    is_member = True\n                    Pause","html":"<p>    def isUserMemberOfGroup (self, utilisateur, attribut, groupe):\n        is_member = False\n        member_of_list = user.getAttributeValues ​​(attribut)\n        if (member_of_list! = None):\n            pour member_of dans member_of_list:\n                si StringHelper.equalsIgnoreCase (group, member_of) ou member_of.endswith (group):\n                    is_member = True\n                    Pause</p>"},{"id":"text-50","type":"text","heading":"","plain_text":"        retourne_membre","html":"<p>        retourne_membre</p>"},{"id":"text-51","type":"text","heading":"","plain_text":"    def processAuditGroup (self, user):\n        si (self.use_audit_group):\n            is_member = self.isUserMemberOfGroup (utilisateur, self.audit_attribute, self.audit_group)\n            if (is_member):\n                print &quot;Duo. Authentifiez-vous pour processAuditGroup. User &#39;&quot; + user.getUserId () + &quot;&#39; membre du groupe d&#39;audit&quot;\n                print &quot;Duo. Authentifiez-vous pour processAuditGroup. Envoi d&#39;un courrier électronique concernant l&#39;utilisateur &#39;&quot; + user.getUserId () + &quot;&#39; se connecter à&quot;, self.audit_email\n                \n                # Envoyer un e-mail à l&#39;administrateur\n                user_id = user.getUserId ()\n                mailService = CdiUtil.bean (MailService)\n                subject = &quot;Connexion de l&#39;utilisateur:&quot; + user_id\n                body = &quot;Connexion utilisateur:&quot; + user_id\n                mailService.sendMail (self.audit_email, sujet, corps)","html":"<p>    def processAuditGroup (self, user):\n        si (self.use_audit_group):\n            is_member = self.isUserMemberOfGroup (utilisateur, self.audit_attribute, self.audit_group)\n            if (is_member):\n                print &quot;Duo. Authentifiez-vous pour processAuditGroup. User &#039;&quot; + user.getUserId () + &quot;&#039; membre du groupe d&#039;audit&quot;\n                print &quot;Duo. Authentifiez-vous pour processAuditGroup. Envoi d&#039;un courrier électronique concernant l&#039;utilisateur &#039;&quot; + user.getUserId () + &quot;&#039; se connecter à&quot;, self.audit_email\n                \n                # Envoyer un e-mail à l&#039;administrateur\n                user_id = user.getUserId ()\n                mailService = CdiUtil.bean (MailService)\n                subject = &quot;Connexion de l&#039;utilisateur:&quot; + user_id\n                body = &quot;Connexion utilisateur:&quot; + user_id\n                mailService.sendMail (self.audit_email, sujet, corps)</p>"},{"id":"text-52","type":"text","heading":"","plain_text":"Click to rate this post!\n                                   \n                               [Total: 0  Average: 0]","html":"<p>Click to rate this post!\n                                   \n                               [Total: 0  Average: 0]</p>"}],"sections":[{"id":"text-1","heading":"Text","content":"# Vous trouverez ci-dessous un script d&#39;authentification utilisé par le serveur Gluu pour implémenter Duo Security pour une authentification à deux facteurs (2FA)."},{"id":"text-2","heading":"Text","content":"depuis org.xdi.service.cdi.util, importez CdiUtil\ndepuis org.xdi.oxauth.security import Identity\ndepuis org.xdi.model.custom.script.type.auth, importez PersonAuthenticationType\ndepuis org.xdi.oxauth.service import UserService, AuthenticationService\ndepuis org.xdi.service, importez MailService\ndepuis org.xdi.util, importez ArrayHelper\ndepuis org.xdi.util import StringHelper"},{"id":"text-3","heading":"Text","content":"import duo_web\nimporter json"},{"id":"text-4","heading":"Text","content":"classe PersonAuthentication (PersonAuthenticationType):\n    def __init __ (self, currentTimeMillis):\n        self.currentTimeMillis = currentTimeMillis"},{"id":"text-5","heading":"Text","content":"    def init (self, configurationAttributes):\n        print &quot;Duo. Initialization&quot;"},{"id":"text-6","heading":"Text","content":"        duo_creds_file = configurationAttributes.get (&quot;duo_creds_file&quot;). getValue2 ()\n        # Charger les informations d&#39;identification du fichier\n        f = open (duo_creds_file, &#39;r&#39;)\n        essayer:\n            creds = json.loads (f.read ())\n        sauf:\n            print &quot;Duo. Initialization. Impossible de charger les créations à partir du fichier:&quot;, duo_creds_file\n            retourne Faux\n        enfin:\n            f.close ()"},{"id":"text-7","heading":"Text","content":"        self.ikey = str (creds[\"ikey\"])\n        self.skey = str (creds[\"skey\"])\n        self.akey = str (creds[\"akey\"])"},{"id":"text-8","heading":"Text","content":"        self.use_duo_group = False\n        if (configurationAttributes.containsKey (&quot;groupe_duo&quot;)):\n            self.duo_group = configurationAttributes.get (&quot;duo_group&quot;). getValue2 ()\n            self.use_duo_group = True\n            print &quot;Duo. Initialization. Utiliser Duo uniquement si l&#39;utilisateur appartient au groupe:&quot;, self.duo_group"},{"id":"text-9","heading":"Text","content":"        self.use_audit_group = False\n        if (configurationAttributes.containsKey (&quot;groupe_audits&quot;)):\n            self.audit_group = configurationAttributes.get (&quot;audit_group&quot;). getValue2 ()"},{"id":"text-10","heading":"Text","content":"            if (pas configurationAttributes.containsKey (&quot;audit_group_email&quot;)):\n                print &quot;Duo. Initialization. La propriété audit_group_email n&#39;est pas spécifiée&quot;\n                retourne Faux"},{"id":"text-11","heading":"Text","content":"            self.audit_email = configurationAttributes.get (&quot;audit_group_email&quot;). getValue2 ()\n            self.use_audit_group = True"},{"id":"text-12","heading":"Text","content":"            print &quot;Duo. Initialization. Utilisation de audito group:&quot;, self.audit_group\n            \n        if (self.use_duo_group ou self.use_audit_group):\n            if (pas configurationAttributes.containsKey (&quot;audit_attribute&quot;)):\n                print &quot;Duo. Initialization. La propriété audit_attribute n&#39;est pas spécifiée&quot;\n                retourne Faux\n            autre:\n                self.audit_attribute = configurationAttributes.get (&quot;audit_attribute&quot;). getValue2 ()"},{"id":"text-13","heading":"Text","content":"        print &quot;Duo. Initialisé avec succès&quot;\n        retourne True"},{"id":"text-14","heading":"Text","content":"    def destroy (self, configurationAttributes):\n        print &quot;Duo. Destroy&quot;\n        print &quot;Duo. Détruit avec succès&quot;\n        retourne True"},{"id":"text-15","heading":"Text","content":"    def getApiVersion (auto):\n        retour 1"},{"id":"text-16","heading":"Text","content":"    def isValidAuthenticationMethod (self, usageType, configurationAttributes):\n        retourne True"},{"id":"text-17","heading":"Text","content":"    def getAlternativeAuthenticationMethod (self, usageType, configurationAttributes):\n        retourner Aucun"},{"id":"text-18","heading":"Text","content":"    def authenticate (self, configurationAttributes, requestParameters, step):\n        duo_host = configurationAttributes.get (&quot;duo_host&quot;). getValue2 ()"},{"id":"text-19","heading":"Text","content":"        authenticationService = CdiUtil.bean (AuthenticationService)"},{"id":"text-20","heading":"Text","content":"        identity = CdiUtil.bean (Identity)"},{"id":"text-21","heading":"Text","content":"        si (étape == 1):\n            print &quot;Duo. Authentifiez-vous pour l&#39;étape 1&quot;"},{"id":"text-22","heading":"Text","content":"            credentials = identity.getCredentials ()\n            nom_utilisateur = credentials.getUsername ()\n            mot_de_passe_utilisateur = credentials.getPassword ()"},{"id":"text-23","heading":"Text","content":"            logs_in = Faux\n            if (StringHelper.isNotEmptyString (nom_utilisateur) et StringHelper.isNotEmptyString (mot_utilisateur_utilisateur)):\n                userService = CdiUtil.bean (UserService)\n                log_in = authenticationService.authenticate (nom d&#39;utilisateur, mot de passe utilisateur)"},{"id":"text-24","heading":"Text","content":"            si (non connecté):\n                retourne Faux"},{"id":"text-25","heading":"Text","content":"            utilisateur = authenticationService.getAuthenticatedUser ()\n            si (self.use_duo_group):\n                print &quot;Duo. Authentifiez-vous à l&#39;étape 1. Vérification de l&#39;appartenance de l&#39;utilisateur au groupe Duo&quot;\n                is_member_duo_group = self.isUserMemberOfGroup (utilisateur, self.audit_attribute, self.duo_group)\n                if (is_member_duo_group):\n                    print &quot;Duo. Authentifiez-vous à l&#39;étape 1. Utilisateur &#39;&quot; + utilisateur.getUserId () + &quot;&#39; membre du groupe Duo&quot;\n                    duo_count_login_steps = 2\n                autre:\n                    self.processAuditGroup (utilisateur)\n                    duo_count_login_steps = 1"},{"id":"text-26","heading":"Text","content":"                identity.setWorkingParameter (&quot;duo_count_login_steps&quot;, duo_count_login_steps)"},{"id":"text-27","heading":"Text","content":"            retourne True\n        elif (step == 2):\n            print &quot;Duo. Authentifiez-vous à l&#39;étape 2&quot;\n            utilisateur = authenticationService.getAuthenticatedUser ()\n            si utilisateur == Aucun:\n                print &quot;Duo. Authentifiez-vous à l&#39;étape 2. Echec de la détermination du nom d&#39;utilisateur&quot;\n                retourne Faux"},{"id":"text-28","heading":"Text","content":"            nom_utilisateur = utilisateur.getUserId ()"},{"id":"text-29","heading":"Text","content":"            sig_response_array = requestParameters.get (&quot;sig_response&quot;)\n            si ArrayHelper.isEmpty (sig_response_array):\n                print &quot;Duo. Authentifiez-vous à l&#39;étape 2. sig_response est vide&quot;\n                retourne Faux"},{"id":"text-30","heading":"Text","content":"            duo_sig_response = sig_response_array[0]"},{"id":"text-31","heading":"Text","content":"print &quot;Duo. Authentifiez-vous à l&#39;étape 2. duo_sig_response:&quot; + duo_sig_response"},{"id":"text-32","heading":"Text","content":"            nom_utilisateur_authentifié = duo_web.verify_response (self.ikey, self.skey, self.akey, duo_sig_response)"},{"id":"text-33","heading":"Text","content":"            print &quot;Duo. Authentifiez-vous à l&#39;étape 2. nom d&#39;utilisateur authentifié:&quot; + nom d&#39;utilisateur authentifié + &quot;, nom d&#39;utilisateur attendu:&quot; + nom d&#39;utilisateur"},{"id":"text-34","heading":"Text","content":"            if (non StringHelper.equals (nom d&#39;utilisateur, nom d&#39;utilisateur authentifié)):\n                retourne Faux"},{"id":"text-35","heading":"Text","content":"            self.processAuditGroup (utilisateur)"},{"id":"text-36","heading":"Text","content":"            retourne True\n        autre:\n            retourne Faux"},{"id":"text-37","heading":"Text","content":"    def prepareForStep (self, configurationAttributes, requestParameters, step):\n        identity = CdiUtil.bean (Identity)\n        authenticationService = CdiUtil.bean (AuthenticationService)"},{"id":"text-38","heading":"Text","content":"        duo_host = configurationAttributes.get (&quot;duo_host&quot;). getValue2 ()"},{"id":"text-39","heading":"Text","content":"        si (étape == 1):\n            print &quot;Duo. Préparez-vous pour l&#39;étape 1&quot;"},{"id":"text-40","heading":"Text","content":"            retourne True\n        elif (step == 2):\n            print &quot;Duo. Préparez-vous pour l&#39;étape 2&quot;"},{"id":"text-41","heading":"Text","content":"            utilisateur = authenticationService.getAuthenticatedUser ()\n            si (utilisateur == aucun):\n                print &quot;Duo. Préparez-vous pour l&#39;étape 2. Echec de la détermination du nom d&#39;utilisateur&quot;\n                retourne Faux\n            nom_utilisateur = utilisateur.getUserId ()"},{"id":"text-42","heading":"Text","content":"            duo_sig_request = duo_web.sign_request (self.ikey, self.skey, self.akey, nom d&#39;utilisateur)\n            print &quot;Duo. Préparez-vous pour l&#39;étape 2. duo_sig_request:&quot; + duo_sig_request\n            \n            identity.setWorkingParameter (&quot;duo_host&quot;, duo_host)\n            identity.setWorkingParameter (&quot;duo_sig_request&quot;, duo_sig_request)"},{"id":"text-43","heading":"Text","content":"            retourne True\n        autre:\n            retourne Faux"},{"id":"text-44","heading":"Text","content":"    def getExtraParametersForStep (self, configurationAttributes, step):\n        retourner Aucun"},{"id":"text-45","heading":"Text","content":"    def getCountAuthenticationSteps (self, configurationAttributes):\n        identity = CdiUtil.bean (Identity)\n        if (identity.isSetWorkingParameter (&quot;duo_count_login_steps&quot;)):\n            return identity.getWorkingParameter (&quot;duo_count_login_steps&quot;)"},{"id":"text-46","heading":"Text","content":"        retour 2"},{"id":"text-47","heading":"Text","content":"    def getPageForStep (self, configurationAttributes, step):\n        si (étape == 2):\n            retourne &quot;/auth/duo/duologin.xhtml&quot;\n        revenir &quot;&quot;"},{"id":"text-48","heading":"Text","content":"    def logout (self, configurationAttributes, requestParameters):\n        retourne True"},{"id":"text-49","heading":"Text","content":"    def isUserMemberOfGroup (self, utilisateur, attribut, groupe):\n        is_member = False\n        member_of_list = user.getAttributeValues ​​(attribut)\n        if (member_of_list! = None):\n            pour member_of dans member_of_list:\n                si StringHelper.equalsIgnoreCase (group, member_of) ou member_of.endswith (group):\n                    is_member = True\n                    Pause"},{"id":"text-50","heading":"Text","content":"        retourne_membre"},{"id":"text-51","heading":"Text","content":"    def processAuditGroup (self, user):\n        si (self.use_audit_group):\n            is_member = self.isUserMemberOfGroup (utilisateur, self.audit_attribute, self.audit_group)\n            if (is_member):\n                print &quot;Duo. Authentifiez-vous pour processAuditGroup. User &#39;&quot; + user.getUserId () + &quot;&#39; membre du groupe d&#39;audit&quot;\n                print &quot;Duo. Authentifiez-vous pour processAuditGroup. Envoi d&#39;un courrier électronique concernant l&#39;utilisateur &#39;&quot; + user.getUserId () + &quot;&#39; se connecter à&quot;, self.audit_email\n                \n                # Envoyer un e-mail à l&#39;administrateur\n                user_id = user.getUserId ()\n                mailService = CdiUtil.bean (MailService)\n                subject = &quot;Connexion de l&#39;utilisateur:&quot; + user_id\n                body = &quot;Connexion utilisateur:&quot; + user_id\n                mailService.sendMail (self.audit_email, sujet, corps)"},{"id":"text-52","heading":"Text","content":"Click to rate this post!\n                                   \n                               [Total: 0  Average: 0]"}],"media":{"primary_image":""},"relations":[{"rel":"canonical","href":"https://tutos-gameserver.fr/2019/05/04/gluu-bien-choisir-son-serveur-d-impression/"},{"rel":"alternate","href":"https://tutos-gameserver.fr/2019/05/04/gluu-bien-choisir-son-serveur-d-impression/llm","type":"text/html"},{"rel":"alternate","href":"https://tutos-gameserver.fr/2019/05/04/gluu-bien-choisir-son-serveur-d-impression/llm.json","type":"application/json"},{"rel":"llm-manifest","href":"https://tutos-gameserver.fr/llm-endpoints-manifest.json","type":"application/json"}],"http_headers":{"X-LLM-Friendly":"1","X-LLM-Schema":"1.1.0","Content-Security-Policy":"default-src 'none'; img-src * data:; style-src 'unsafe-inline'"},"license":"CC BY-ND 4.0","attribution_required":true,"allow_cors":false}