Files
hzdyjs/test/系统权限诊断.py
T
2025-07-16 18:11:31 +08:00

174 lines
5.2 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
系统权限诊断脚本
检查登录权限配置问题
"""
import requests
import json
from datetime import datetime
# 配置
BASE_URL = "http://localhost:8080"
ACTUATOR_URL = f"{BASE_URL}/actuator"
HEALTH_URL = f"{BASE_URL}/actuator/health"
LOGIN_URL = f"{BASE_URL}/auth/login"
def test_actuator_health():
"""测试健康检查端点"""
print("🔍 测试系统健康状态...")
try:
response = requests.get(HEALTH_URL, timeout=5)
print(f"健康检查响应状态: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"健康检查结果: {json.dumps(result, indent=2, ensure_ascii=False)}")
return True
else:
print(f"健康检查失败: {response.text}")
return False
except Exception as e:
print(f"❌ 健康检查异常: {e}")
return False
def test_actuator_endpoints():
"""测试Actuator端点"""
print("🔍 测试Actuator端点...")
try:
response = requests.get(ACTUATOR_URL, timeout=5)
print(f"Actuator响应状态: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"可用端点: {json.dumps(result, indent=2, ensure_ascii=False)}")
return True
else:
print(f"Actuator访问失败: {response.text}")
return False
except Exception as e:
print(f"❌ Actuator访问异常: {e}")
return False
def test_different_login_methods():
"""测试不同的登录方式"""
print("🔍 测试不同的登录方式...")
# 方式1:标准登录
print("\n--- 方式1:标准登录 ---")
login_data_1 = {
"clientId": "e5cd7e4891bf95d1d19206ce24a7b32e",
"username": "admin",
"password": "admin123",
"grant_type": "password",
"tenantId": "000000"
}
try:
response = requests.post(LOGIN_URL, json=login_data_1, timeout=10)
print(f"响应状态: {response.status_code}")
print(f"响应内容: {json.dumps(response.json(), indent=2, ensure_ascii=False)}")
except Exception as e:
print(f"❌ 登录异常: {e}")
# 方式2:尝试不同的clientId
print("\n--- 方式2:尝试其他clientId ---")
login_data_2 = {
"clientId": "default",
"username": "admin",
"password": "admin123",
"grant_type": "password",
"tenantId": "000000"
}
try:
response = requests.post(LOGIN_URL, json=login_data_2, timeout=10)
print(f"响应状态: {response.status_code}")
print(f"响应内容: {json.dumps(response.json(), indent=2, ensure_ascii=False)}")
except Exception as e:
print(f"❌ 登录异常: {e}")
# 方式3:尝试表单提交
print("\n--- 方式3:表单提交 ---")
form_data = {
"clientId": "e5cd7e4891bf95d1d19206ce24a7b32e",
"username": "admin",
"password": "admin123",
"grant_type": "password",
"tenantId": "000000"
}
try:
response = requests.post(LOGIN_URL, data=form_data, timeout=10)
print(f"响应状态: {response.status_code}")
print(f"响应内容: {json.dumps(response.json(), indent=2, ensure_ascii=False)}")
except Exception as e:
print(f"❌ 登录异常: {e}")
def test_system_info():
"""测试系统信息端点"""
print("🔍 测试系统信息...")
endpoints = [
"/actuator/info",
"/actuator/env",
"/actuator/configprops",
"/system/info",
"/auth/info"
]
for endpoint in endpoints:
try:
url = f"{BASE_URL}{endpoint}"
response = requests.get(url, timeout=5)
print(f"\n{endpoint}: {response.status_code}")
if response.status_code == 200:
try:
result = response.json()
print(f" 内容: {json.dumps(result, indent=2, ensure_ascii=False)[:500]}...")
except:
print(f" 内容: {response.text[:200]}...")
else:
print(f" 错误: {response.text[:200]}")
except Exception as e:
print(f" 异常: {e}")
def main():
"""主函数"""
print("="*80)
print("🔍 系统权限诊断")
print("="*80)
print(f"⏰ 诊断时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print()
# 1. 测试健康检查
test_actuator_health()
print()
# 2. 测试Actuator端点
test_actuator_endpoints()
print()
# 3. 测试不同登录方式
test_different_login_methods()
print()
# 4. 测试系统信息
test_system_info()
print()
print("="*80)
print("📋 诊断建议:")
print("1. 如果返回403错误,可能是:")
print(" - 数据库连接问题")
print(" - 用户权限配置问题")
print(" - 客户端配置问题")
print(" - 租户配置问题")
print("2. 检查后端日志文件获取更多信息")
print("3. 确认数据库中的用户和权限配置")
print("="*80)
if __name__ == "__main__":
main()