2017-11-14 10 views
0

LDAP3 인증을위한 플라스크 청사진을 작성하려고합니다. 나는 표준 플라스크 응용 프로그램과 같은 코드를 사용하는 경우, 예상대로 모든 것이, 바인드는 성공적으로 작동하고 사용자 인증도 성공 :Flask LDAP3 Auth 청사진이 초기화되지 않은 ASN.1 값과 함께 실패합니다.

DEBUG:root:Validating LDAPLoginForm against LDAP 
DEBUG:flask_ldap3_login:Opening connection with bind user '[email protected]' 
DEBUG:flask_ldap3_login:Successfully bound to LDAP as '[email protected]' for search_bind method 
DEBUG:flask_ldap3_login:Performing an LDAP Search using filter '(&(objectclass=person)(sAMAccountName=YYYY))', base 'ou=Users,ou=XXXX,dc=XXXX,dc=COM', and scope 'SUBTREE' 
DEBUG:flask_ldap3_login:Opening connection with bind user 'CN=YYYY,OU=Admin Users,OU=Users,OU=XXXX,DC=XXXX,DC=COM' 
DEBUG:flask_ldap3_login:Directly binding a connection to a server with user:'CN=YYYY,OU=Admin Users,OU=Users,OU=XXXX,DC=XXXX,DC=COM' 
DEBUG:flask_ldap3_login:Authentication was successful for user 'YYYY' 

하지만 최대한 빨리 청사진으로 바꿀 같이

DEBUG:root:Validating LDAPLoginForm against LDAP 
DEBUG:flask_ldap3_login:Opening connection with bind user '[email protected]' 
DEBUG:flask_ldap3_login:Destroying connection at <0x7f181f9ee2b0> 
ERROR:flask_ldap3_login:Uninitialized ASN.1 value ("__len__" attribute looked up) 

:

from flask import Flask 

app = Flask(__name__) 
app.config.from_object('config') 

from app.ldauth.views import auth_blueprint 
app.register_blueprint(auth_blueprint) 

그리고 응용 프로그램/ldauth/views.py을 다음과 같이

초기화 평이다 617,451,515,

from flask import Flask, Blueprint, url_for 
from flask_ldap3_login import LDAP3LoginManager 
from flask_login import LoginManager, login_user, UserMixin, current_user 
from flask import render_template_string, render_template, redirect 
from flask_ldap3_login.forms import LDAPLoginForm 
from app import app 

auth_blueprint = Blueprint('ldauth',__name__,template_folder='templates') 

login_manager = LoginManager(app)    # Setup a Flask-Login Manager 
ldap_manager = LDAP3LoginManager(app)   # Setup a LDAP3 Login Manager. 
login_manager.login_view = "auth.login" 
users = {} 

class User(UserMixin): 
    def __init__(self, dn, username, data): 
     self.dn = dn 
     self.username = username 
     self.data = data 

    def __repr__(self): 
     return self.dn 

    def get_id(self): 
     return self.dn 

@login_manager.user_loader 
def load_user(id): 
    if id in users: 
     return users[id] 
    return None 


@ldap_manager.save_user 
def save_user(dn, username, data, memberships): 
    user = User(dn, username, data) 
    users[dn] = user 
    return user 

@auth_blueprint.route('/login', methods=['GET', 'POST']) 
def login(): 
    template = """ 
    {{ get_flashed_messages() }} 
    {{ form.errors }} 
    <form method="POST"> 
     <label>Username{{ form.username() }}</label> 
     <label>Password{{ form.password() }}</label> 
     {{ form.submit() }} 
     {{ form.hidden_tag() }} 
    </form> 
    """ 

    # Instantiate a LDAPLoginForm which has a validator to check if the user 
    # exists in LDAP. 

    form = LDAPLoginForm() 

    if form.validate_on_submit(): 
     # Successfully logged in, We can now access the saved user object 
     # via form.user. 
     login_user(form.user) # Tell flask-login to log them in. 

     # TODO: Validate next to ensure it is safe! 
     return redirect(next) # Send them home 

    return render_template_string(template,form=form) 

핍 동결 :

Babel==2.5.1 
blinker==1.4 
click==6.7 
Flask==0.12.2 
Flask-BabelEx==0.9.3 
flask-ldap3-login==0.9.13 
Flask-Login==0.4.0 
Flask-Mail==0.9.1 
Flask-Principal==0.4.0 
Flask-Security==3.0.0 
Flask-SQLAlchemy==2.3.2 
Flask-WTF==0.14.2 
itsdangerous==0.24 
Jinja2==2.10 
ldap3==2.3 
MarkupSafe==1.0 
passlib==1.7.1 
pkg-resources==0.0.0 
pyasn1==0.3.7 
pyasn1-modules==0.1.5 
python3-ldap==0.9.8.4 
pytz==2017.3 
speaklater==1.3 
SQLAlchemy==1.1.15 
Werkzeug==0.12.2 
WTForms==2.1 

내가 분명히 여기에 어떤 아이디어가 뭔가를 누락?

답변

0

이것이 virtualenv의 문제였습니다. 오늘 아침에 새로운 virtualenv를 만들었고 코드를이 코드로 옮겼습니다. 예상대로 작동합니다.