Benefits of adding CAs
What is CAs is not much said, in short is a single sign-on system, a landing, the entire network has access to the system.
One landing, multiple systems interoperability
CAs are generally placed in the intranet, and the CAs verification must require users to take VPN access and improve security.
CAs can be combined with domain control and so on, the password is timed expired;
Basic Certification Unified Go CAS control, minus open account and other trouble;
How Django uses CAS validation
The good thing about Django is that there's a lot of support, and there's already a great God-related app on the web, just download and install it.
All we have to do is download and unzip the copy, and then we can run it in a slightly configurable way.
As for the installation is also very simple, direct decompression after the Python setup.py install can be.
Official Links:
Django-cas
Django-cas How to configure
Configuration method
As for the configuration, the familiar Django students also understand that Django is installed by the app to partition, the scalability is very strong.
Django-cas is also an app, so we configure it according to the app's configuration method.
* Add CAS configuration in middleware_classes:
' Django_cas.middleware.CASMiddleware '
in Authentication_backends To add the configuration of CAs:
' django_cas.backends.CASBackend '
Note that there are no authenticationmiddleware configuration items in django1.6, which need to be manually added,
and add the row configuration:
' django.contrib.auth.backends.ModelBackend ',
* Configure Cas_server_url: This address is the address of the CAS authentication server and must be configured
The full configuration is as follows
Installed_apps = (
' django.contrib.admin ',
' Django.contrib.auth ', '
django.contrib.contenttypes ',
' django.contrib.sessions ',
' django.contrib.messages ', '
django.contrib.staticfiles ',
)
middleware_classes = (
' django.contrib.sessions.middleware.SessionMiddleware ',
' Django.middleware.common.CommonMiddleware ',
' django.middleware.csrf.CsrfViewMiddleware ',
' Django.contrib.auth.middleware.AuthenticationMiddleware ',
' Django.contrib.messages.middleware.MessageMiddleware ',
' Django.middleware.clickjacking.XFrameOptionsMiddleware ',
' django_cas.middleware.CASMiddleware ',
' Django.middleware.doc.XViewMiddleware ',
)
authentication_backends = (
' Django.contrib.auth.backends.ModelBackend ',
' django_cas.backends.CASBackend ',
)
Cas_server_url = ' Http://cas.oxxs.letv.cn:6789/cas/login '
Instance
settings.py configuration file
As configured on
Views file
# Create your views here.
From django.http import HttpResponse
def login (Request):
if request.user.is_authenticated ():
return HttpResponse (' Login in Port 9000 ')
else: return
httpresponse (' not login at Port 9000 ')
Nothing to say, just simple to detect whether the user logged in, and then print the line string.
URL file
From Django.conf.urls import patterns, include, URLs from
django.contrib import admin from
Report_system Import v Iews
admin.autodiscover ()
urlpatterns = Patterns (',
# Examples:
# URL (r ' ^$ ', ' Report_ System.views.home ', name= ' home '),
# URL (r ' ^blog/', include (' Blog.urls '),
url (r ' ^$ ', Views.login)
, URL (r ' ^login/$ ', ' Django_cas.views.login '),
url (r ' ^logout/$ ', ' django_cas.views.logout '),
url (r ' ^admin /', include (Admin.site.urls),
)
There is nothing more, a look at all understand.
Test
Let's go down and see:
Can see obviously after accessing our server, since not logged in, so then 302 jump to
The CAS server verifies.
This figure is immediately following the previous figure, after the CAS server checksum, if the checksum passes, then jump to our
Server address, this seems to be the default jump back/, and we in/corresponding views inside the printed two lines
Character and see that the login is actually printed, then our landing is successful!
Cancellation and so on other also types, no longer say more.
Summarize
Django_cas in general, it is very convenient, can very quickly help me access the CAS authentication system, but
The current configuration seems to be a bit problematic, log off again after landing is unable to jump back to our server address,
Instead, it jumps back to the address of CAs. Need to continue to verify Kazakhstan.