209 lines
8.2 KiB
Python
209 lines
8.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test du mapping du rôle SUPER_ADMINISTRATEUR
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
import base64
|
|
|
|
def test_superadmin_role():
|
|
base_url = "http://localhost:8180"
|
|
|
|
print("🧪 Test du rôle SUPER_ADMINISTRATEUR")
|
|
print("=" * 60)
|
|
print()
|
|
|
|
# Test avec superadmin@unionflow.com
|
|
email_username = "superadmin@unionflow.com"
|
|
password = "SuperAdmin123!"
|
|
|
|
print(f"🔐 Authentification de {email_username}")
|
|
|
|
data = {
|
|
"username": email_username,
|
|
"password": password,
|
|
"grant_type": "password",
|
|
"client_id": "unionflow-mobile"
|
|
}
|
|
|
|
try:
|
|
response = requests.post(
|
|
f"{base_url}/realms/unionflow/protocol/openid-connect/token",
|
|
data=data,
|
|
headers={"Content-Type": "application/x-www-form-urlencoded"}
|
|
)
|
|
|
|
print(f"📊 Status: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
token_data = response.json()
|
|
if "access_token" in token_data:
|
|
print("✅ AUTHENTIFICATION RÉUSSIE !")
|
|
|
|
# Décoder le token pour voir les rôles
|
|
access_token = token_data['access_token']
|
|
|
|
# Décoder le payload du JWT
|
|
token_parts = access_token.split('.')
|
|
if len(token_parts) >= 2:
|
|
# Ajouter du padding si nécessaire
|
|
payload = token_parts[1]
|
|
payload += '=' * (4 - len(payload) % 4)
|
|
decoded = base64.b64decode(payload)
|
|
token_info = json.loads(decoded)
|
|
|
|
print()
|
|
print("🎫 INFORMATIONS DU TOKEN :")
|
|
print(f" 👤 Utilisateur: {token_info.get('preferred_username', 'N/A')}")
|
|
print(f" 📧 Email: {token_info.get('email', 'N/A')}")
|
|
print(f" 👨💼 Nom: {token_info.get('name', 'N/A')}")
|
|
|
|
# Extraire les rôles
|
|
roles = []
|
|
if 'realm_access' in token_info and 'roles' in token_info['realm_access']:
|
|
all_roles = token_info['realm_access']['roles']
|
|
# Filtrer les rôles système
|
|
roles = [r for r in all_roles if not r.startswith('default-') and r not in ['offline_access', 'uma_authorization']]
|
|
|
|
print()
|
|
print("🎭 RÔLES KEYCLOAK EXTRAITS :")
|
|
for role in roles:
|
|
if role == 'SUPER_ADMINISTRATEUR':
|
|
print(f" ✅ {role} (SUPER ADMIN - ACCÈS COMPLET)")
|
|
else:
|
|
print(f" ✓ {role}")
|
|
|
|
print()
|
|
print("🎯 MAPPING VERS L'APPLICATION MOBILE :")
|
|
|
|
if 'SUPER_ADMINISTRATEUR' in roles:
|
|
print(" ✅ Rôle mappé: UserRole.superAdmin")
|
|
print(" ✅ Dashboard: SuperAdminDashboard")
|
|
print(" ✅ Navigation: Command Center")
|
|
print(" ✅ Permissions: ACCÈS COMPLET SYSTÈME")
|
|
print()
|
|
print("🚀 FONCTIONNALITÉS DISPONIBLES :")
|
|
print(" • Vue globale multi-organisations")
|
|
print(" • Métriques système en temps réel")
|
|
print(" • Outils d'administration avancés")
|
|
print(" • Monitoring et analytics")
|
|
print(" • Gestion des utilisateurs globale")
|
|
print(" • Configuration système")
|
|
print(" • Sécurité et audit")
|
|
print(" • Sauvegarde et maintenance")
|
|
print()
|
|
print("📱 ONGLETS DU DASHBOARD :")
|
|
print(" 1. Vue Globale - Métriques système")
|
|
print(" 2. Organisations - Gestion multi-org")
|
|
print(" 3. Système - Monitoring technique")
|
|
print(" 4. Analytics - Rapports avancés")
|
|
|
|
return True
|
|
else:
|
|
print(" ❌ Rôle SUPER_ADMINISTRATEUR non trouvé")
|
|
print(" ⚠️ L'utilisateur sera mappé comme visiteur")
|
|
return False
|
|
|
|
else:
|
|
print("❌ Token manquant dans la réponse")
|
|
else:
|
|
print("❌ Authentification échouée")
|
|
print(f"Response: {response.text}")
|
|
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Erreur: {e}")
|
|
return False
|
|
|
|
def test_all_roles():
|
|
"""Teste tous les comptes avec leurs rôles"""
|
|
base_url = "http://localhost:8180"
|
|
|
|
print()
|
|
print("=" * 60)
|
|
print("🧪 TEST DE TOUS LES RÔLES UNIONFLOW")
|
|
print("=" * 60)
|
|
print()
|
|
|
|
users = [
|
|
("superadmin@unionflow.com", "SuperAdmin123!", "SUPER_ADMINISTRATEUR"),
|
|
("marie.active@unionflow.com", "Marie123!", "MEMBRE_ACTIF"),
|
|
("jean.simple@unionflow.com", "Jean123!", "MEMBRE_SIMPLE"),
|
|
("tech.lead@unionflow.com", "TechLead123!", "RESPONSABLE_TECHNIQUE"),
|
|
("rh.manager@unionflow.com", "RhManager123!", "RESPONSABLE_MEMBRES"),
|
|
]
|
|
|
|
for email, password, expected_role in users:
|
|
print(f"🔐 Test de {email} (attendu: {expected_role})")
|
|
|
|
data = {
|
|
"username": email,
|
|
"password": password,
|
|
"grant_type": "password",
|
|
"client_id": "unionflow-mobile"
|
|
}
|
|
|
|
try:
|
|
response = requests.post(
|
|
f"{base_url}/realms/unionflow/protocol/openid-connect/token",
|
|
data=data,
|
|
headers={"Content-Type": "application/x-www-form-urlencoded"}
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
token_data = response.json()
|
|
access_token = token_data['access_token']
|
|
|
|
# Décoder le token
|
|
token_parts = access_token.split('.')
|
|
payload = token_parts[1]
|
|
payload += '=' * (4 - len(payload) % 4)
|
|
decoded = base64.b64decode(payload)
|
|
token_info = json.loads(decoded)
|
|
|
|
# Extraire les rôles
|
|
roles = []
|
|
if 'realm_access' in token_info and 'roles' in token_info['realm_access']:
|
|
all_roles = token_info['realm_access']['roles']
|
|
roles = [r for r in all_roles if not r.startswith('default-') and r not in ['offline_access', 'uma_authorization']]
|
|
|
|
if expected_role in roles:
|
|
print(f" ✅ Rôle {expected_role} trouvé")
|
|
else:
|
|
print(f" ❌ Rôle {expected_role} manquant. Rôles trouvés: {roles}")
|
|
|
|
else:
|
|
print(f" ❌ Authentification échouée: {response.status_code}")
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Erreur: {e}")
|
|
|
|
print()
|
|
|
|
if __name__ == "__main__":
|
|
success = test_superadmin_role()
|
|
|
|
if success:
|
|
print()
|
|
print("=" * 60)
|
|
print("🎉 SUPER ADMINISTRATEUR CONFIGURÉ AVEC SUCCÈS !")
|
|
print("=" * 60)
|
|
print()
|
|
print("📱 VOTRE APPLICATION MOBILE AFFICHERA :")
|
|
print(" • Dashboard Super Admin complet")
|
|
print(" • Navigation Command Center")
|
|
print(" • Toutes les fonctionnalités administratives")
|
|
print()
|
|
print("🚀 Testez maintenant sur votre Samsung avec :")
|
|
print(" Username: superadmin@unionflow.com")
|
|
print(" Password: SuperAdmin123!")
|
|
else:
|
|
print()
|
|
print("⚠️ Problème de configuration détecté")
|
|
print("Vérifiez que le rôle SUPER_ADMINISTRATEUR est bien assigné")
|
|
|
|
# Test de tous les rôles
|
|
test_all_roles()
|