This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
cn:ccr:aai:howto:wordpress._configurare_l_accesso_saml_2.0_con_onelogin_saml_sso [2021/02/17 11:36] becchett@infn.it |
cn:ccr:aai:howto:wordpress._configurare_l_accesso_saml_2.0_con_onelogin_saml_sso [2021/02/17 19:35] (current) becchett@infn.it |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | |||
+ | |||
+ | ===== Wordpress. Configurare SAML 2.0 con plugin Onelogin SAML SSO ===== | ||
+ | |||
+ | In questa guida viene descritto come agganciare l' | ||
+ | |||
+ | Programmi utilizzati per realizzare questa guida: | ||
+ | |||
+ | * Sistema operativo: CentOS 7.8.2003 | ||
+ | * httpd 2.4.6-93 | ||
+ | * PHP 7.4.11 | ||
+ | * MariaDB 5.5.68 | ||
+ | * Wordpress 5.6.1 | ||
+ | * Onelogin SAML SSO 3.3.1 | ||
+ | |||
+ | Componenti aggiuntivi per PHP: | ||
+ | |||
+ | * php-gd | ||
+ | * php-mcrypt | ||
+ | * php-mbstring | ||
+ | * php-curl | ||
+ | * php-xml | ||
+ | * php-pear | ||
+ | * php-bcmath php-json | ||
+ | |||
+ | **Prerequisiti**. Installare e configurare Wordpress con https attivo. | ||
+ | |||
+ | **Facoltativo**. Attivare un tema figlio seguendo questa guida: [[https:// | ||
+ | |||
+ | **Fase 1.** Scaricare il certificato dell’ IDP. | ||
+ | |||
+ | versione di test: | ||
+ | < | ||
+ | |||
+ | versione di produzione: | ||
+ | < | ||
+ | |||
+ | generare il certificato e la chiave private da usare per questo SP: | ||
+ | < | ||
+ | |||
+ | ** Fase 2.** | ||
+ | |||
+ | Utilizzando la dashborad di Wordpress installare e attivare il plugin **<< | ||
+ | |||
+ | Nelle impostazioni selezionare **<< | ||
+ | |||
+ | * //Enable **YES**// | ||
+ | |||
+ | * Parametri per IDP di test: | ||
+ | * //IdP Entity Id //: https:// | ||
+ | * //Single Sign On Service Url// : https:// | ||
+ | * //Single Log Out Service Url// : https:// | ||
+ | |||
+ | * Parametri per IDP di Produzione: | ||
+ | * //IdP Entity Id // : https:// | ||
+ | * //Single Sign On Service Url // : https:// | ||
+ | * //Single Log Out Service Url // : https:// | ||
+ | |||
+ | * //X509 Certificate: | ||
+ | * //Create user if not exists: //**YES** | ||
+ | * //Update user data: **YES**// | ||
+ | * //Force Saml Login: **NO**// | ||
+ | * //Single Log Out: **NO**// | ||
+ | * //Keep Local Login: **YES**// | ||
+ | * // | ||
+ | * //Match Wordpress account by: **username**// | ||
+ | * //Trigger wp_login hook: **YES**// | ||
+ | * //Multi Role Support: **YES**// | ||
+ | |||
+ | * //Attribute Mapping:// | ||
+ | * //Username : **uid**// | ||
+ | * //E-mail: **mail**// | ||
+ | * //First Name: **givenName**// | ||
+ | * //Last Name: **sn**// | ||
+ | * //Nickname: **givenName**// | ||
+ | * //Role: **eduPersonEntitlement**// | ||
+ | * //Remember Me: **yes**// | ||
+ | |||
+ | * //Role Mappging:// | ||
+ | * // | ||
+ | * //Editor: **editor**// | ||
+ | * //Author: **author**// | ||
+ | * // | ||
+ | * // | ||
+ | |||
+ | * //Multiple role values in one saml attribute value: **yes**// | ||
+ | * //Regular expression for multiple role values:** / | ||
+ | |||
+ | Sostituire **SEDE** con la sigla della sezione o del laboratorio | ||
+ | |||
+ | * //Role precedence:// | ||
+ | * // | ||
+ | * //Editor: **2**// | ||
+ | * //Author: **3**// | ||
+ | * // | ||
+ | * // | ||
+ | |||
+ | * //Customize Actions And Links:// | ||
+ | * //Prevent use of normal: **no**// | ||
+ | * //Prevent reset password: **yes**// | ||
+ | * //Prevent change password: **yes**// | ||
+ | * //Prevent change mail: **yes**// | ||
+ | * //Stay in WordPress after SLO: **No**// | ||
+ | * //User Registration:// | ||
+ | * //Lost Password:// [[https:// | ||
+ | * //SAML Link Message: **INFN-AAI LOGIN**// | ||
+ | |||
+ | * //Advanced Settings:// | ||
+ | * //Debug Mode: **NO**// | ||
+ | * //Strict Mode: **YES**// | ||
+ | * //Service Provider Entity Id: **NOME_HOST.SEDE.infn.it**// | ||
+ | * //Lowercase URL encoding?: **NO**// | ||
+ | * //Encrypt nameID: **NO**// | ||
+ | * //Sign AuthnRequest: | ||
+ | * //Sign LogoutRequest: | ||
+ | * //Sign LogoutResponse: | ||
+ | * //Reject Unsigned Messages: **YES**// | ||
+ | * //Reject Unsigned Assertions: **YES**// | ||
+ | * //Reject Unencrypted Assertions: **YES**// | ||
+ | * //Retrieve Parameters From Server: **YES**// | ||
+ | |||
+ | * // | ||
+ | * //Service Provider X.509 Certificate: | ||
+ | * // Service Provider Private Key: **“copiare il contenuto del file / | ||
+ | * //Signature Algorithm: **SHA256**// | ||
+ | * //Digest Algorithm: **SHA256**// | ||
+ | |||
+ | Salvare le modifiche e generare i metadati **<< | ||
+ | |||
+ | Salvare i metadati e modificare il campo validUntil=" | ||
+ | |||
+ | **Fase 3.** Inviare i metadati tramite il modulo web [[https:// | ||
+ | * Service_Description: | ||
+ | * selezionare: | ||
+ | * selezionare: | ||
+ | * EduPersonEntitlement filter regex: **/ | ||
+ | |||
+ | assegnare un nome a **NOME_HOST** e sostituire a **SEDE** la sigla della sezione o del laboratorio. | ||
+ | |||
+ | copiare i metadati in **<< | ||
+ | |||
+ | Rimuovere la chiave privata ed i certificati: | ||
+ | < | ||
+ | |||
+ | Dopo aver ricevuto la mail di conferma da aai-support@infn.it, | ||
+ | |||
+ | **Fase 4.**Ruoli e autorizzazione. Per consentire a Wordpress di associare un ruolo ad un utente occorre creare con Godiva la seguente struttura: // | ||
+ | |||
+ | Accedere a Godiva e selezionare //**Domini -> Gestione Domini.**// | ||
+ | |||
+ | Selezionare //**Gruppi -> INFN -> Sede**// | ||
+ | |||
+ | Aggiungere il nodo **wp**, specificando: | ||
+ | * nome dominio: **wp** | ||
+ | * entry ldap: **wp** | ||
+ | * descrizione: | ||
+ | |||
+ | All’ interno di questo nodo creare un ulteriore nodo per ogni ruolo di Wordpress: | ||
+ | * **admin** | ||
+ | * **author** | ||
+ | * **editor** | ||
+ | * **contrib** | ||
+ | * **subscr** | ||
+ | |||
+ | **Entry Ldap** deve avere lo stesso nome del nodo, mentre il valore da assegnare a **Codice** e’ **ENTITLEMENTS**. | ||
+ | |||
+ | Dopo aver creato tutti i nodi si possono aggiungere gli utenti. Di seguito un esempio relativo al ruolo di editor: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | **Fase 5.** Per completare la fase di autorizzazione e consentire l' | ||
+ | elettronica. Se è gia stato attivato un tema figlio, scelta consigliata, | ||
+ | altrimenti si deve editare il file**// / | ||
+ | |||
+ | Di seguito un esempio con le istruzioni PHP ad aggiungere: | ||
+ | |||
+ | < | ||
+ | /** | ||
+ | * Funzione per autorizzazione login tramite controllo sul campo mail | ||
+ | */ | ||
+ | function wp_user_mail_check($user_login, | ||
+ | $infndomain=" | ||
+ | $mail=" | ||
+ | $username=" | ||
+ | | ||
+ | // inserire nell’array $localusers tutti gli utenti non presenti in AAI ma già definiti nel db locale di WP. | ||
+ | // Esempio: | ||
+ | $localusers[]=" | ||
+ | $localusers[]=" | ||
+ | $localuser_wp=" | ||
+ | |||
+ | // controllo se l' | ||
+ | foreach ( $localusers as $localuser ) { | ||
+ | if ( " | ||
+ | $localuser_wp = " | ||
+ | } | ||
+ | } | ||
+ | // controllo mail per autorizzazione | ||
+ | if ( $localuser_wp == " | ||
+ | get_header(); | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "</ | ||
+ | get_sidebar(); | ||
+ | get_footer(); | ||
+ | exit; | ||
+ | } | ||
+ | } | ||
+ | add_action( ' | ||
+ | </ | ||
+ | |||
+ | **Fase 6.** Personalizzazione della schermata di login di Wordpress. | ||
+ | |||
+ | Creare la directory **images** nel tema attivo, per esempio in **/ | ||
+ | |||
+ | Nel file **functions.php** aggiungere le seguenti linee: | ||
+ | |||
+ | < | ||
+ | # Logo INFN-AAI nella pagina di login | ||
+ | function my_login_logo() { ?> | ||
+ | <style type=" | ||
+ | #login h1 a, .login h1 a { | ||
+ | background-image: | ||
+ | height: | ||
+ | width: | ||
+ | background-size: | ||
+ | background-repeat: | ||
+ | padding-bottom: | ||
+ | } | ||
+ | </ | ||
+ | <?php } | ||
+ | add_action( ' | ||
+ | function my_login_logo_url() { | ||
+ | $url=home_url()."/ | ||
+ | return $url; | ||
+ | } | ||
+ | add_filter( ' | ||
+ | |||
+ | function my_login_logo_url_title() { | ||
+ | return 'INFN AAI'; | ||
+ | } | ||
+ | add_filter( ' | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | **Fase 7.** Accesso al sistema. | ||
+ | |||
+ | Quando saranno inseriti i metadati nell’IDP si potrà effettuare il login **https:// | ||
+ | |||
+ | **Link utili:** | ||
+ | |||
+ | //Onelogin SAML SSO, codice sorgente:// [[https:// | ||
+ | |||
+ | //Onelogin SAML SSO, home page plugin:// [[https:// | ||
+ | |||
+ | //Wordpress Login:// [[https:// | ||
+ | |||
+ | //Wordpress tema figlio:// [[https:// | ||
+ | |||
+ | //Godiva:// [[https:// | ||
+ | |||
+ | //Gestione delle autorizzazioni in godiva:// [[https:// | ||
+ | |||
+ | |||
+ | --- // | ||
+ | |||