我已经成功制作了一个Flask-Login应用程序,可以使用LDAP记录人员 . 也就是说,我可以使用登录过程和@login_required装饰器来区分两种类型的用户:
-
未经身份验证(用户名/密码在LDAP中未被识别为有效的组合)
-
已验证(用户可以使用给定的用户名/密码登录LDAP)
我现在想要的是:
-
未经身份验证(用户名/密码在LDAP中未被识别为有效的组合)
-
未经授权(用户名/密码是有效的LDAP组合,但用户不是正确的LDAP组的成员)
-
已授权(用户的凭据位于LDAP中,用户是相应LDAP组的成员)
在伪代码中,我喜欢这样:
@app.route("/")
def index():
return render_template("index.html")
# This is for any authenticated user
@app.route('/allmembers')
@login_required
def allmembers():
return render_template("allmembers.html")
# This is for only certain LDAP group members
@app.route('/secret')
@authorization_required(allowed_groups=["secret", "top-secret"]) # does this exist?
@login_required
def secret():
return render_template("secret.html")
我已经看过Flask-Login“User”类的“is_authenticated”方法,但这似乎只能让我看到#1 . 是否有Flask类型的方法从认证状态进入授权状态?
或者Flask-Login的有用性在认证之后结束,我需要弄清楚如何滚动我自己的 @authorization_required
装饰器?
1 回答
flask-login docs明确说它不"Handle permissions beyond 'logged in or not.'"
所以,是的,你将不得不推出自己的
@authorization_required
装饰 .