正在显示
10 个修改的文件
包含
74 行增加
和
30 行删除
... | ... | @@ -2,18 +2,25 @@ from functools import wraps |
2 | 2 | from authlib.integrations.flask_oauth2 import current_token |
3 | 3 | from flask import abort |
4 | 4 | from app.modules.auth.oauth2 import require_oauth |
5 | +from flask import request | |
5 | 6 | |
6 | 7 | # 认证装饰器 |
7 | 8 | |
9 | + | |
8 | 10 | class auth_decorator(object): |
9 | - def __init__(self, action='', permission=''): | |
11 | + def __init__(self, action='', permission='', scope='profile'): | |
10 | 12 | self.permission = permission |
11 | 13 | self.action = action |
14 | + self.scope = scope | |
12 | 15 | |
13 | 16 | def __call__(self, func): |
17 | + | |
14 | 18 | @wraps(func) |
15 | - @require_oauth("profile") | |
16 | 19 | def wrapped_function(*args, **kwargs): |
20 | + token = request.headers.get('Authorization') | |
21 | + if not token: | |
22 | + abort(401) | |
23 | + validate_token() | |
17 | 24 | if current_token and current_token.user and current_token.user.role: |
18 | 25 | print(func.__name__) |
19 | 26 | if self.permission and len(self.permission) > 0: |
... | ... | @@ -28,6 +35,10 @@ class auth_decorator(object): |
28 | 35 | # 无permission,不校验 |
29 | 36 | return func(*args, **kwargs) |
30 | 37 | else: |
31 | - pass # 无token,401 | |
38 | + abort(401) # 无token,401 | |
39 | + | |
40 | + @require_oauth(self.scope) | |
41 | + def validate_token(): | |
42 | + pass | |
32 | 43 | |
33 | 44 | return wrapped_function | ... | ... |
app/decorators/token_decorator.py
0 → 100644
1 | +from functools import wraps | |
2 | +from authlib.integrations.flask_oauth2 import current_token | |
3 | +from flask import abort | |
4 | +from app.modules.auth.oauth2 import require_oauth | |
5 | +from flask import request | |
6 | + | |
7 | +# 认证装饰器 | |
8 | + | |
9 | + | |
10 | +class token_decorator(object): | |
11 | + def __init__(self, scope='profile'): | |
12 | + self.scope = scope | |
13 | + | |
14 | + def __call__(self, func): | |
15 | + @wraps(func) | |
16 | + def wrapped_function(*args, **kwargs): | |
17 | + token = request.headers.get('Authorization') | |
18 | + if token: | |
19 | + validate_token() | |
20 | + if current_token and current_token.user: | |
21 | + return func(*args, **kwargs) | |
22 | + else: | |
23 | + abort(403) | |
24 | + | |
25 | + else: | |
26 | + abort(401) # 无token,401 | |
27 | + | |
28 | + @require_oauth(self.scope) | |
29 | + def validate_token(): | |
30 | + pass | |
31 | + | |
32 | + return wrapped_function | ... | ... |
... | ... | @@ -6,12 +6,13 @@ from app.util import BlueprintApi |
6 | 6 | from flask import Blueprint, render_template, redirect, request, session, jsonify |
7 | 7 | from sqlalchemy import and_ |
8 | 8 | from .models import * |
9 | -from .oauth2 import authorization, require_oauth, generate_user_info | |
9 | +from .oauth2 import authorization, generate_user_info | |
10 | 10 | from authlib.oauth2 import OAuth2Error |
11 | 11 | from authlib.integrations.flask_oauth2 import current_token |
12 | 12 | from . import user_create, client_create, client_query, user_query, user_update, user_delete |
13 | 13 | import configure |
14 | 14 | from app.decorators.auth_decorator import auth_decorator |
15 | +from app.decorators.token_decorator import token_decorator | |
15 | 16 | |
16 | 17 | |
17 | 18 | def current_user(): |
... | ... | @@ -81,7 +82,7 @@ class DataManager(BlueprintApi): |
81 | 82 | |
82 | 83 | @staticmethod |
83 | 84 | @bp.route("/userinfo") |
84 | - @require_oauth("profile") | |
85 | + @token_decorator("profile") | |
85 | 86 | def api_me(): |
86 | 87 | try: |
87 | 88 | return jsonify(generate_user_info(current_token.user, current_token.scope)) | ... | ... |
... | ... | @@ -11,7 +11,7 @@ from . import task_detail |
11 | 11 | from . import task_delete |
12 | 12 | from . import task_count |
13 | 13 | from . import task_kill |
14 | -from app.modules.auth.oauth2 import require_oauth | |
14 | +from app.decorators.token_decorator import token_decorator | |
15 | 15 | |
16 | 16 | |
17 | 17 | class DataManager(BlueprintApi): |
... | ... | @@ -39,7 +39,7 @@ class DataManager(BlueprintApi): |
39 | 39 | @staticmethod |
40 | 40 | @bp.route('/Delete', methods=['POST']) |
41 | 41 | @swag_from(task_delete.Api.api_doc) |
42 | - @require_oauth("profile") | |
42 | + @token_decorator("profile") | |
43 | 43 | def task_delete(): |
44 | 44 | """ |
45 | 45 | 删除任务 |
... | ... | @@ -49,7 +49,7 @@ class DataManager(BlueprintApi): |
49 | 49 | @staticmethod |
50 | 50 | @bp.route('/Kill', methods=['POST']) |
51 | 51 | @swag_from(task_kill.Api.api_doc) |
52 | - @require_oauth("profile") | |
52 | + @token_decorator("profile") | |
53 | 53 | def task_kill(): |
54 | 54 | """ |
55 | 55 | Kill任务 | ... | ... |
... | ... | @@ -16,7 +16,7 @@ from . import service_info |
16 | 16 | from . import service_edit |
17 | 17 | import os |
18 | 18 | from flask import send_from_directory |
19 | -from app.modules.auth.oauth2 import require_oauth | |
19 | +from app.decorators.token_decorator import token_decorator | |
20 | 20 | |
21 | 21 | |
22 | 22 | class DataManager(BlueprintApi): |
... | ... | @@ -28,7 +28,7 @@ class DataManager(BlueprintApi): |
28 | 28 | @staticmethod |
29 | 29 | @bp.route('/Register', methods=['POST']) |
30 | 30 | @swag_from(service_register.Api.api_doc) |
31 | - @require_oauth("profile") | |
31 | + @token_decorator("profile") | |
32 | 32 | def api_service_register(): |
33 | 33 | """ |
34 | 34 | 服务注册 |
... | ... | @@ -47,7 +47,7 @@ class DataManager(BlueprintApi): |
47 | 47 | @staticmethod |
48 | 48 | @bp.route('/State', methods=['POST']) |
49 | 49 | @swag_from(service_state.Api.api_doc) |
50 | - @require_oauth("profile") | |
50 | + @token_decorator("profile") | |
51 | 51 | def api_service_state(): |
52 | 52 | """ |
53 | 53 | 修改服务状态 |
... | ... | @@ -85,7 +85,7 @@ class DataManager(BlueprintApi): |
85 | 85 | @staticmethod |
86 | 86 | @bp.route('/Edit', methods=['POST']) |
87 | 87 | @swag_from(service_edit.Api.api_doc) |
88 | - @require_oauth("profile") | |
88 | + @token_decorator("profile") | |
89 | 89 | def api_service_edit(): |
90 | 90 | """ |
91 | 91 | 服务Edit |
... | ... | @@ -97,7 +97,7 @@ class DataManager(BlueprintApi): |
97 | 97 | @staticmethod |
98 | 98 | @bp.route('/Delete', methods=['POST']) |
99 | 99 | @swag_from(service_delete.Api.api_doc) |
100 | - @require_oauth("profile") | |
100 | + @token_decorator("profile") | |
101 | 101 | def api_service_delete(): |
102 | 102 | """ |
103 | 103 | 服务删除 | ... | ... |
... | ... | @@ -7,7 +7,7 @@ from flasgger import swag_from |
7 | 7 | from flask import Blueprint |
8 | 8 | from app.util import BlueprintApi |
9 | 9 | from . import image_service_delete,image_service_register,image_service_edit,image_build_pyramid |
10 | -from app.modules.auth.oauth2 import require_oauth | |
10 | +from app.decorators.token_decorator import token_decorator | |
11 | 11 | |
12 | 12 | class DataManager(BlueprintApi): |
13 | 13 | |
... | ... | @@ -18,7 +18,7 @@ class DataManager(BlueprintApi): |
18 | 18 | @staticmethod |
19 | 19 | @bp.route('/BuildPyramid', methods=['POST']) |
20 | 20 | @swag_from(image_build_pyramid.Api.api_doc) |
21 | - @require_oauth("profile") | |
21 | + @token_decorator("profile") | |
22 | 22 | def api_image_build_pyramid(): |
23 | 23 | """ |
24 | 24 | 创建影像金字塔 |
... | ... | @@ -28,7 +28,7 @@ class DataManager(BlueprintApi): |
28 | 28 | @staticmethod |
29 | 29 | @bp.route('/Register', methods=['POST']) |
30 | 30 | @swag_from(image_service_register.Api.api_doc) |
31 | - @require_oauth("profile") | |
31 | + @token_decorator("profile") | |
32 | 32 | def api_image_service_register(): |
33 | 33 | """ |
34 | 34 | 注册ImageService |
... | ... | @@ -38,7 +38,7 @@ class DataManager(BlueprintApi): |
38 | 38 | @staticmethod |
39 | 39 | @bp.route('/Edit', methods=['POST']) |
40 | 40 | @swag_from(image_service_edit.Api.api_doc) |
41 | - @require_oauth("profile") | |
41 | + @token_decorator("profile") | |
42 | 42 | def api_image_service_edit(): |
43 | 43 | """ |
44 | 44 | 修改ImageService |
... | ... | @@ -48,7 +48,7 @@ class DataManager(BlueprintApi): |
48 | 48 | @staticmethod |
49 | 49 | @bp.route('/Delete', methods=['POST']) |
50 | 50 | @swag_from(image_service_delete.Api.api_doc) |
51 | - @require_oauth("profile") | |
51 | + @token_decorator("profile") | |
52 | 52 | def api_image_service_delete(): |
53 | 53 | """ |
54 | 54 | ImageService Delete | ... | ... |
... | ... | @@ -7,7 +7,7 @@ from flasgger import swag_from |
7 | 7 | from flask import Blueprint |
8 | 8 | from app.util import BlueprintApi |
9 | 9 | from . import map_service_register, map_service_edit |
10 | -from app.modules.auth.oauth2 import require_oauth | |
10 | +from app.decorators.token_decorator import token_decorator | |
11 | 11 | |
12 | 12 | |
13 | 13 | class DataManager(BlueprintApi): |
... | ... | @@ -19,7 +19,7 @@ class DataManager(BlueprintApi): |
19 | 19 | @staticmethod |
20 | 20 | @bp.route('/Register', methods=['POST']) |
21 | 21 | @swag_from(map_service_register.Api.api_doc) |
22 | - @require_oauth("profile") | |
22 | + @token_decorator("profile") | |
23 | 23 | def api_wms_register(): |
24 | 24 | """ |
25 | 25 | 注册MapService |
... | ... | @@ -29,7 +29,7 @@ class DataManager(BlueprintApi): |
29 | 29 | @staticmethod |
30 | 30 | @bp.route('/Edit', methods=['POST']) |
31 | 31 | @swag_from(map_service_edit.Api.api_doc) |
32 | - @require_oauth("profile") | |
32 | + @token_decorator("profile") | |
33 | 33 | def api_wms_edit(): |
34 | 34 | """ |
35 | 35 | 修改MapService | ... | ... |
... | ... | @@ -14,7 +14,7 @@ from . import scheme_edit |
14 | 14 | from . import scheme_list |
15 | 15 | from . import scheme_resolve |
16 | 16 | from . import scheme_info |
17 | -from app.modules.auth.oauth2 import require_oauth | |
17 | +from app.decorators.token_decorator import token_decorator | |
18 | 18 | |
19 | 19 | |
20 | 20 | class SchemeManager(BlueprintApi): |
... | ... | @@ -25,7 +25,7 @@ class SchemeManager(BlueprintApi): |
25 | 25 | @staticmethod |
26 | 26 | @bp.route('/Create', methods=['POST']) |
27 | 27 | @swag_from(scheme_create.Api.api_doc) |
28 | - @require_oauth("profile") | |
28 | + @token_decorator("profile") | |
29 | 29 | def api_scheme_create(): |
30 | 30 | """ |
31 | 31 | 创建切片方案 |
... | ... | @@ -36,7 +36,7 @@ class SchemeManager(BlueprintApi): |
36 | 36 | @staticmethod |
37 | 37 | @bp.route('/Delete', methods=['POST']) |
38 | 38 | @swag_from(scheme_delete.Api.api_doc) |
39 | - @require_oauth("profile") | |
39 | + @token_decorator("profile") | |
40 | 40 | def api_scheme_delete(): |
41 | 41 | """ |
42 | 42 | 删除切片方案 |
... | ... | @@ -46,7 +46,7 @@ class SchemeManager(BlueprintApi): |
46 | 46 | @staticmethod |
47 | 47 | @bp.route('/Edit', methods=['POST']) |
48 | 48 | @swag_from(scheme_edit.Api.api_doc) |
49 | - @require_oauth("profile") | |
49 | + @token_decorator("profile") | |
50 | 50 | def api_scheme_edit(): |
51 | 51 | """ |
52 | 52 | 修改切片方案 | ... | ... |
... | ... | @@ -8,7 +8,7 @@ from flasgger import swag_from |
8 | 8 | from flask import Blueprint |
9 | 9 | from app.util import BlueprintApi |
10 | 10 | from . import upload_oview,tile_service_register,tile_service_edit,tile_service_reload |
11 | -from app.modules.auth.oauth2 import require_oauth | |
11 | +from app.decorators.token_decorator import token_decorator | |
12 | 12 | |
13 | 13 | |
14 | 14 | class DataManager(BlueprintApi): |
... | ... | @@ -30,7 +30,7 @@ class DataManager(BlueprintApi): |
30 | 30 | @staticmethod |
31 | 31 | @bp.route('/Register', methods=['POST']) |
32 | 32 | @swag_from(tile_service_register.Api.api_doc) |
33 | - @require_oauth("profile") | |
33 | + @token_decorator("profile") | |
34 | 34 | def api_wmts_register(): |
35 | 35 | """ |
36 | 36 | 注册TileService |
... | ... | @@ -40,7 +40,7 @@ class DataManager(BlueprintApi): |
40 | 40 | @staticmethod |
41 | 41 | @bp.route('/Edit', methods=['POST']) |
42 | 42 | @swag_from(tile_service_edit.Api.api_doc) |
43 | - @require_oauth("profile") | |
43 | + @token_decorator("profile") | |
44 | 44 | def api_wmts_edit(): |
45 | 45 | """ |
46 | 46 | 修改TileService | ... | ... |
... | ... | @@ -4,8 +4,8 @@ import logging |
4 | 4 | deploy_ip_host = "172.26.40.105:8840" |
5 | 5 | # 系统数据库 |
6 | 6 | |
7 | -SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.100:5432/dmap_manager_test" | |
8 | -# SQLALCHEMY_DATABASE_URI = "postgresql://postgres:postgres@localhost:5433/dmap_dms_test" | |
7 | +# SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.100:5432/dmap_manager_test" | |
8 | +SQLALCHEMY_DATABASE_URI = "postgresql://postgres:postgres@localhost:5433/dmap_dms_test" | |
9 | 9 | |
10 | 10 | # 指定精华表所在位置(必须为空间库),设置为None则存放在各自的实体库中 |
11 | 11 | #VACUATE_DB_URI = None | ... | ... |
请
注册
或
登录
后发表评论