日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

cas .net 重定向循环_接口测试平台接入企业cas(一)

發布時間:2025/3/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 cas .net 重定向循环_接口测试平台接入企业cas(一) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

cas系統簡介

提供運營系統的 SSO 和 access control功能。類似百度的UC。

CAS 是 Yale 大學發起的一個開源項目,旨在為 Web 應用系統提供一種可靠的單點登錄方法,CAS 在 2004 年 12 月正式成為 JA-SIG 的一個項目。官方網站:https://www.apereo.org/

CAS 具有以下特點:

  • 開源的企業級單點登錄解決方案。

  • CAS Server 為需要獨立部署的 Web 應用。

  • CAS Client 支持非常多的客戶端(這里指單點登錄系統中的各個 Web 應用),包括 Java, .Net, PHP, Perl, Apache, uPortal, Ruby 等。

從結構上看,CAS 包含兩個部分:CAS Server 和 CAS Client。

  • CAS Server 需要獨立部署,主要負責對用戶的認證工作;

  • CAS Client 負責處理對客戶端受保護資源的訪問請求,需要登錄時,重定向到 CAS Server。

Python接入cas示例

一、soc環境

python3.6.9 + django 2.1.7 + django-cas-ng 3.6.0

二、cas服務端

cas 3.5.2 (yale大學開源)

三、配置流程

3.1、settings.py 配置

3.1.1、 配置INSTALLED_APPS:添加django_cas_ng到INSTALLED_APPS

INSTALLED_APPS?=?[ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_cas_ng']

3.1.2、配置MIDDLEWARE:添加django_cas_ng.middleware.CASMiddleware到MIDDLEWARE:

MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', '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_ng.middleware.CASMiddleware']

3.1.3、配置AUTHENTICATION_BACKENDS:添加django_cas_ng.backends.CASBackend到AUTHENTICATION_BACKENDS:

AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', 'django_cas_ng.backends.CASBackend',)

3.1.4、配置CAS服務器URL和CAS協議版本:(咱們的cas是3.5.2 cas_version 需要填寫對應的2;當前最新版的版本是3;版本號不能填錯,否則無法認證通過)

CAS_SERVER_URL = 'https://test-cas.xxx.com/cas/'

CAS_VERSION = '2'

CAS_REDIRECT_URL = "/server/api/portmonitor/gpb/" #認證通過后跳轉到的目錄

以上是settings.py中的配置

#####################################################################

下面是代碼中的配置

3.1.5、配置 ?mysite/urls.py:

from django.contrib import adminfrom django.urls import pathimport django_cas_ng.viewsfrom . import viewsurlpatterns = [ path('', views.index, name='index'), path('admin/', admin.site.urls), path('accounts/login', django_cas_ng.views.LoginView.as_view(), name='cas_ng_login'), path('accounts/logout', django_cas_ng.views.LogoutView.as_view(), name='cas_ng_logout'),]

3.1.6、mysite / views.py

創建一個名為的新文件mysite/views.py并實現index方法。

演示視圖將使用檢查用戶身份驗證request.user.is_authenticated。如果通過身份驗證,它將從以下位置獲取登錄的用戶名 ? request.user.username

from django.httpimport HttpResponsedef index(request): if request.user.is_authenticated: ##使用request對象可以做權限控制 return HttpResponse('<p>Welcome to <a href="https://djangocas.dev">django-cas-nga>.p><p>You logged in as <strong>%sstrong>.p><p><a href="/accounts/logout">Logouta> p>' % request.user) else: return HttpResponse('<p>Welcome to <a href="https://djangocas.dev">django-cas-nga>.p><p><a href="/accounts/login">Login<

四、生成數據庫

只需要直接執行 migrate 就可以了,我默認用的sqlite3數據庫

$ python manage.py migrateOperations to perform: Apply all migrations: admin, auth, contenttypes, django_cas_ng, sessionsRunning migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying admin.0003_logentry_add_action_flag_choices... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying auth.0009_alter_user_last_name_max_length... OK Applying auth.0010_alter_group_name_max_length... OK Applying auth.0011_update_proxy_permissions... OK Applying django_cas_ng.0001_initial... OK Applying sessions.0001_initial... OK

可以登陸數據庫檢查新生成的表:一共新增6張表

sqlite3 db.sqlite3root@xxx:/apps/soc_test# sqlite3 db.sqlite3SQLite version 3.22.0 2018-01-22 18:45:57Enter ".help" for usage hints.sqlite> .tablesauth_group django_admin_log auth_group_permissions django_cas_ng_proxygrantingticketauth_permission django_cas_ng_sessionticket auth_user django_content_type auth_user_groups django_migrations auth_user_user_permissions django_session

五、運行項目測試

$ python manage.py runserver 0.0.0.0:80Performing system checks.........Django version 2.1.7, using settings 'mysite.settings'Starting development server at http://ip:80/Quit the server with CONTROL-C.

總結

以上是生活随笔為你收集整理的cas .net 重定向循环_接口测试平台接入企业cas(一)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。