开发者

Django integration with Acegi

I have existing Java application that is using Acegi for authentication/authorization. Our new web interface would be preferably written in Django. I would like Django to maintain users - registration etc. Django would either share or update Acegi authentication data so the older application still works and users don't have to use two sets开发者_高级运维 of credentials (maybe even share authentication cookie). I was wondering if someone was already dealing with similar issue and if yes which approach was chosen.

Thanks


Just remember whatever you do with Django, it is still Python, therefore just because Django doesn't have it/doesn't do it that way, doesn't mean you can't. Also, from another point of view, there is nothing stopping you using bits of the Django framework from outside the traditional Django application.

I don't particularly like the admin interface to Django although I do use Form and ModelForm a lot outside of it. I actually implemented my own authentication system - all you need are functions that let you log in/out etc and an interface to that data. It (users/groups etc) doesn't have to be represented as a Django model although that's what I did for ease. There is nothing stopping you hooking in another ORM or writing your own for acegi. Alternatively, if writing your own layer is simple enough, do that.

I'd recommend hooking into the context processors for Django and the Django middleware and library-ising your work simply because it'll make re-use a breeze and it will act in a similar manner to the existing authentication framework. Here's an example context processor I use to allow me to write {{ username }} in my template without having to get it out of every request object in every view method:

def Authentication(request):
    if AuthenticationCheck(sess=request.session, timeofaction=datetime.datetime.now(), ipaddress=request.META['REMOTE_ADDR']) == True:
        return dict(username=request.session["username"])
    else:
        return dict(username='')

Also, Django Middleware Documentation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜