I heard that wechat search “Java fish” will change strong oh!
This article is posted on Github and Gitee, and contains my entire Java series of articles for study and interview purposes
(1) Overview
Recently, I suddenly had an idea to build some wheels. I usually write code business, so I want to write something else. Thus came the building wheels series. Login authentication should be the first feature every programmer writes, at least for me, so my first Wheel-building project was going to write login authentication, but it was a distributed unified authentication project instead. The desired effect is that access projects can be quickly accessed through simple configuration, and no longer worry about login authentication.
Github address: github.com/OliverLiy/f…
Gitee address: gitee.com/lyucoding/f…
Maven: search for FAST-SSO directly in the warehouse
(2) Demonstration effect
If you access the application of fast-SSO, run localhost:8999/index. If you do not log in to the application, the login page of the unified authentication service is automatically displayed
Enter the username and password and click Sign in to automatically jump back to localhost:8999/index
Open localhost:9000/index in the same browser, do not need to log in directly to the system:
(3) How to access
The project consists of fast-SSO-server and fast-sso-client. The fast-Sso-server is a unified authentication service center, and the fast-Sso-client is used for system access. Because the current official version, so the use of source code compilation. Download the source code first: github.com/OliverLiy/f…
Configure a unified authentication center
1. Create an SSO user information table in the database
CREATE DATABASE sso_user;
USE sso_user;
SET NAMES utf8mb4;
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`userId` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'user Id'.`username` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'Username'.`password` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'password',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
Copy the code
2. In the fast-sso-server configuration, change sso.server.path to the SSO application path
sso.server.path=http://localhost:8777
Copy the code
3. Modify the redis address and connection information
redis.host = 10.10.128.226
redis.port = 6379
# Maximum free number
redis.maxidle = 10
# Maximum number of connections
redis.maxtotal = 30
# if redis has no password set, leave it blank
redis.password =
Copy the code
4. Modify the mysql connection information
spring.datasource.url=JDBC: mysql: / / 10.10.128.226:3306 / sso_user? serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
Copy the code
Configure each application for access
1. Introduce dependencies. The latest value is 0.0.2
<dependency>
<artifactId>fast-sso-client</artifactId>
<groupId>io.github.oliverliy</groupId>
<version>{latest}</version>
</dependency>
Copy the code
2. Configure sso and Redis addresses
sso.server.path = http://localhost:8777
redis.host = 10.10.128.226
redis.port = 6379
redis.maxidle = 10
redis.maxtotal = 30
redis.password =
# Add the following address will not be unified authentication
exclude.url=/css/**,/actuator/**
Copy the code
3. Configure an interceptor
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Autowired
UserInterceptor userInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(userInterceptor)
.addPathPatterns("/ * *");
}
@Bean
public UserInterceptor userInterceptor(a){
return newUserInterceptor(); }}Copy the code
Available interfaces currently provided
To obtain the current login user information:
Sso – / getUserInfo server address
Log out:
Sso server address/logout
(4) How to use
If the local run, directly run fast-sso-server can be, if the server, you can run the project into jar package. Note that the current implementation is based on cookies, so the unified authentication authority and the project need to be under the same domain name.
After the fast-SSO-server is started, you can run your own access projects.
(5) How to expand
5.1 What Do I Do if I Want to Add User Information?
The current user table has no other field information. To add more user information, create a user details table and associate it with the ID in the user table. Mybatis SQL do join table operation can be.
5.2 What Do I Do if I Want to Break Unified Domain Access Authentication?
Token mechanism will be introduced later, independent of cookie.
5.3 What should I do if I have other problems?
You can do it directly on Github or Gitee, or you can contact me.