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