#!/bin/bash echo "=============================================================================" echo "🔧 RÉPARATION DES MOTS DE PASSE UTILISATEURS UNIONFLOW" echo "=============================================================================" echo "" # Obtenir le token admin echo "[INFO] Obtention du token d'administration..." token_response=$(curl -s -X POST \ "http://192.168.1.145:8180/realms/master/protocol/openid-connect/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "username=admin&password=admin&grant_type=password&client_id=admin-cli") if echo "$token_response" | grep -q "access_token"; then token=$(echo "$token_response" | grep -o '"access_token":"[^"]*' | cut -d'"' -f4) echo "[SUCCESS] Token obtenu" else echo "[ERROR] Impossible d'obtenir le token" exit 1 fi echo "" echo "RĂ©paration des mots de passe..." echo "" # Fonction pour obtenir l'ID utilisateur get_user_id() { local username="$1" local response=$(curl -s -X GET \ "http://192.168.1.145:8180/admin/realms/unionflow/users?username=${username}" \ -H "Authorization: Bearer ${token}") echo "$response" | grep -o '"id":"[^"]*' | head -1 | cut -d'"' -f4 } # Fonction pour rĂ©initialiser le mot de passe reset_password() { local username="$1" local password="$2" echo -n "RĂ©paration mot de passe pour $username... " # Obtenir l'ID utilisateur user_id=$(get_user_id "$username") if [ -z "$user_id" ]; then echo "✗ Utilisateur non trouvĂ©" return 1 fi # RĂ©initialiser le mot de passe local response=$(curl -s -w "%{http_code}" -X PUT \ "http://192.168.1.145:8180/admin/realms/unionflow/users/${user_id}/reset-password" \ -H "Authorization: Bearer ${token}" \ -H "Content-Type: application/json" \ -d "{\"type\":\"password\",\"value\":\"${password}\",\"temporary\":false}") local http_code="${response: -3}" if [ "$http_code" = "204" ]; then echo "✓ SUCCÈS" return 0 else echo "✗ ÉCHEC (code: $http_code)" return 1 fi } # RĂ©initialiser les mots de passe pour tous les utilisateurs declare -A users=( ["marie.active"]="Marie123!" ["superadmin"]="SuperAdmin123!" ["jean.simple"]="Jean123!" ["tech.lead"]="TechLead123!" ["rh.manager"]="RhManager123!" ["admin.org"]="AdminOrg123!" ["tresorier"]="Tresorier123!" ["visiteur"]="Visiteur123!" ) success_count=0 total_count=${#users[@]} for username in "${!users[@]}"; do password="${users[$username]}" if reset_password "$username" "$password"; then ((success_count++)) fi done echo "" echo "=============================================================================" echo "📊 RÉSULTATS RÉPARATION" echo "=============================================================================" echo "" echo "✅ Mots de passe rĂ©parĂ©s : $success_count/$total_count" echo "" if [ $success_count -gt 0 ]; then echo "đŸ§Ș Test d'authentification avec marie.active..." auth_response=$(curl -s -X POST \ "http://192.168.1.145:8180/realms/unionflow/protocol/openid-connect/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "username=marie.active&password=Marie123!&grant_type=password&client_id=unionflow-mobile") if echo "$auth_response" | grep -q "access_token"; then echo "✓ Test authentification rĂ©ussi !" echo "" echo "🎉 RÉPARATION TERMINÉE AVEC SUCCÈS !" echo "" echo "🚀 COMPTES PRÊTS POUR L'APPLICATION MOBILE :" echo " ‱ marie.active / Marie123! (MEMBRE_ACTIF)" echo " ‱ superadmin / SuperAdmin123! (SUPER_ADMINISTRATEUR)" echo " ‱ jean.simple / Jean123! (MEMBRE_SIMPLE)" echo " ‱ tech.lead / TechLead123! (RESPONSABLE_TECHNIQUE)" echo " ‱ rh.manager / RhManager123! (RESPONSABLE_MEMBRES)" echo "" else echo "✗ Test authentification Ă©chouĂ©" echo "RĂ©ponse: ${auth_response:0:100}..." fi else echo "❌ Aucun mot de passe n'a pu ĂȘtre rĂ©parĂ©" fi echo "" echo "=============================================================================" echo "✅ RÉPARATION TERMINÉE" echo "============================================================================="