当前位置:网站首页>Teach you how to use code to realize SSO single sign on
Teach you how to use code to realize SSO single sign on
2022-07-26 05:04:00 【Xi. Technical chopping】
1. summary
1.1. What is? SSO?
Single sign on ( Single Sign-On , abbreviation SSO ) It is one of the most popular solutions for enterprise business integration , SSO In many application systems , Users only need Log in once You can access all the trusted applications .
1.2. What is? CAS?
With SSO The popularity of technology , There are many related products , among CAS It's a solution ,CAS(Central Authentication Service) Unified identity authentication service or central identity service , It consists of server and client , Realization SSO, And it is easy to integrate enterprise applications .
CAS yes Yale university ( Yale ) An open source project launched , For the purpose of web The application system provides a reliable single sign on method ,CAS stay 2004 year 12 The month officially became JA-SIG A project for .
Official website :https://www.apereo.org/projects/cas

CAS It has the following characteristics :
Open source enterprise single sign on solution
CAS Server For those that need to be deployed independently web application
CAS Client Support a lot of clients ( This refers to the single sign on system web application ), Include Java、.Net 、ISAPI、Php、Perl、uPortal、Acegi、Ruby、VBScript Such as the client
With CAS, Our system architecture evolved into the following :

It can be seen from the architecture that ,CAS There are two parts :CAS Server and CAS Client.
CAS Server Independent deployment required , Mainly responsible for user authentication ,CAS Client Responsible for handling
Access requests to client protected resources , Need to log in , Redirect to CAS Server.
below , We build... Step by step CAS Realization SSO.
1.3. Development environment requirements
Jdk1.8+ maven3.6 idea tomcat9.0+ windows10
2. CAS Server Server side
2.1. CAS Server side software package download
The download version is 5.3
Download the server's overlay Address : https://github.com/apereo/cas-overlay-template/tree/5.3
Compressed package :cas-overlay-template-5.3.zip
After decompression, use the command :build.cmd package
Then use the compiled directory to view war package :

2.2. Basic deployment and testing on the server side
take war Put the bag in tomcat Of webapp in , Then start tomcat
Access address :http://localhost:8080/cas perhaps http://localhost:8080/cas/login

The default user name and password are \webapps\cas\WEB-INF\classes\application.properties Inside user name :casuser password :Mellon

CAS Server started successfully
2.3. CAS Server Server configuration
2.3.1 Remove https authentication
CAS The default is HTTPS agreement , If you use HTTPS Agreement needs to be SSL A security certificate ( You need to apply and purchase from a specific organization ). If the security requirements are not high or in the development and testing stage , You can use HTTP agreement . Here we explain how to modify the configuration , Give Way CAS Use HTTP agreement .
WeChat search official account :Java Back end programming , reply :java Collect information .
modify CAS Server profile :
\cas\WEB-INF\classes\application.properties Add the following to it :
cas.tgc.secure=false
cas.serviceRegistry.initFromJson=true
\cas\WEB-INF\classes\services In the catalog HTTPSandIMAPS-10000001.json The modification is as follows :
"serviceId" : "^(https|http|imaps)://.*"
3. CAS Client Client configuration ( Own project )
Pom File dependency, i.e pom.xml
<dependency>
<groupId>net.unicon.cas</groupId>
<artifactId>cas-client-autoconfig-support</artifactId>
<version>2.1.0-GA</version>
</dependency>
application.yml The configuration file
WeChat search official account : Architect's Guide , reply : Architects Collect information .
client 1
server:
port: 9010
cas:
server-url-prefix: http://localhost:8080/cas
server-login-url: http://localhost:8080/cas/login
client-host-url: http://localhost:9010
validation-type: cas3
notes : The startup class appends the startup class CAS Annotations @EnableCasClient
Create a new test class in the project
iimport io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Api(description = "SSO-CAS Test of ")
public class TestController {
@GetMapping("/test1")
public String test1(){
return "test1....";
}
}
client 2
server:
port: 9011
cas:
server-url-prefix: http://localhost:8080/cas
server-login-url: http://localhost:8080/cas/login
client-host-url: http://localhost:9011
validation-type: cas3
notes : The startup class appends the startup class CAS Annotations @EnableCasClient
Create a new test class in the project
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Api(description = "SSO-CAS Test of ")
public class TestController {
@GetMapping("/test2")
public String test1(){
return "test2....";
}
}
client 1, client 2 and cas After the server is set up , So let's test that out :
1. First start tomcat In the server CAS Server.
2. Start the client respectively 1 And the client 2, Then enter the client... In the browser address bar 1 The address of http://localhost:9010/test1

Not logged in , Continue to enter the client in the address bar of the browser 2 The address of :http://localhost:9011/test2

When we log in to one of the login interfaces ( Suppose you log in to the client 2) Will jump to the login interface , Here's the picture :

We re-enter the client in the browser window again 1,http://localhost:9010/test1, Or refresh the client page just entered , You can enter the page without logging in , Here's the picture :

The above is the single sign on test .
If this article helps you , Don't forget to give me a 3 even , give the thumbs-up , forward , Comment on ,
Learn more JAVA Knowledge and skills , Pay attention to Blogger learning JAVA Courseware , Source code , Installation package , There are also the latest interview materials of big factories, etc
I'll see you next time .
Collection It's like whoring for nothing , Praise is the truth .

边栏推荐
- [weekly translation go] how to write your first program with go
- The pit of history can only be filled up as far as possible
- 【ACWing】1268. 简单题
- MySQL八股知识点:从入门到删库
- JVM第六讲:线上环境 FGC 频繁,如何解决?
- webassembly 01基本资料
- 一次线上事故,我顿悟了异步的精髓
- columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by mysql8.0解决办法
- [Luogu] p3919 [template] persistent segment tree 1 (persistent array)
- How to reproduce the official course of yolov5 gracefully (II) -- Mark and train your own data set
猜你喜欢

Distance between bus stops: simple simulation problem

The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly 100 times the improvement of analysis performance

Excel VBA:实现自动下拉填充公式至最后一行

Please elaborate on the implementation principle of synchronized and related locks

Icml2022 | imitation learning by evaluating the professional knowledge of the presenter

Good at C (summer vacation daily question 6)

Mysql主从同步及主从同步延迟解决方案

擅长C(暑假每日一题 6)

Sliding window -- leetcode solution

STM32开发 | AD7606并行多路采集数据
随机推荐
一次线上事故,我顿悟了异步的精髓
JVM Lecture 5: how to deal with peak push of vertical and horizontal data
To study the trend of open source and gain insight into the future of the industry, stonedb community and the China Academy of communications and communications released the Research Report on the dev
Niuke-top101-bm32
汉字风格迁移篇---通过生成对抗网络学习一对多程式化汉字的转换和生成
Nacos 介绍和部署
9 best project set management tools
The landing of tdengine in the GPS and AIS scheduling of Zhongtian steel
“双碳”目标下资源环境中的可计算一般均衡(CGE)模型实践技术
C language -- string function, memory function collection and Simulation Implementation
C language - pointer one touch ※
Google Emoji guessing game helps parents guide their children to surf the Internet safely
Ansible tutorial
【ACWing】2983. 玩具
Principle of image nonlocal mean filtering
Why is the value represented by a negative number greater than an integer by 1?
Excel VBA:将多个工作表保存为新文件
Building blocks for domestic databases, stonedb integrated real-time HTAP database is officially open source!
webassembly 01基本资料
[cloud native | 17] four network modes of container