Python django integrated cas verification system, pythondjango

Source: Internet
Author: User

Python django integrated cas verification system, pythondjango

Benefits of adding cas

Cas is nothing to say. In short, it is a single point of login system. All systems with permissions on the entire network can access one site.

One login, multiple systems interconnected
Cas are generally placed on the Intranet, and users must be requested to access the site through vpn to improve security;
Cas can be used with domain control systems to regularly expire passwords;
The cas control is adopted for basic authentication, and Account Activation and other troubles are eliminated;
How does django use cas for verification?

The benefit of django is that it supports many packages. There are already related apps on the Internet, which can be downloaded and installed directly.

All we need to do is download, decompress, and copy the file. We can run it with a slight configuration.

The installation is also very simple. You can decompress python setup. py install directly.

Official link:

Django-cas

How to configure django-cas

Configuration method

As for the configuration, those familiar with django also understand that django is divided by installing apps and has high scalability.

Django-cas is also an app, so we can configure it according to the app configuration method.

* Add the CAS configuration to MIDDLEWARE_CLASSES: 'django _ cas. middleware. CASMiddleware * Add the CAS configuration in AUTHENTICATION_BACKENDS: 'django _ cas. backends. casbackend' note that in django1.6, the configuration item of AuthenticationMiddleware is not found by default. You need to manually add the configuration item and add the row: 'django. contrib. auth. backends. modelBackend ', * configure CAS_SERVER_URL: This address is the address of the cas verification server, which must be configured

 
The complete 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

Configuration above

Views File

# Create your views here.from django.http import HttpResponse def login(request):  if request.user.is_authenticated():    return HttpResponse('login in at port 9000')  else:    return HttpResponse('not login at port 9000')

Nothing can be said, but it simply checks whether the user logs in and then prints a line string.

Urls File

from django.conf.urls import patterns, include, urlfrom django.contrib import adminfrom report_system import views 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 to understand.

Test

Let's log in and see:

It can be seen that, after accessing our server, the system jumps to 302 due to not logging in.
Cas server for verification.

This figure is followed by the previous figure. After cas server verification, if the verification is passed, the jump will jump to our
Server address. It seems that the default jump is back to/, and we printed two lines in/'s views.
It indicates that login is successfully logged on!

Other types such as logout are also supported.

Summary

Django_cas is very convenient in general. It can help me access the cas verification system very quickly,

The current configuration still seems to be a problem. After logging out again, you cannot jump back to our server address,

Instead, the cas address is redirected back. Verification is pending.


Python django Publishing System

URL: www.djangoproject.com/

Python django url Problems

You are not familiar with regular expressions. The second sentence is written like this. As long as the URL has a form such as update/id1, it will be sent to views. update, so the third sentence is useless. The correct method should be to add ^ after R', like this
(R' ^ update /(? P <id> \ d +)/$ ', 'Views. Update') matches only the URL starting with update. This is the basic rule for regular expressions.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.