博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
单点登录-系统搭建
阅读量:4483 次
发布时间:2019-06-08

本文共 27114 字,大约阅读时间需要 90 分钟。

  之前说了单点登录系统的原理,这篇就来点硬货,说下单点登录的一个系统是如何搭建的。

 架构分析

    表现层:提供手机客户端,或其他系统的调用

      表现层的存在意义就是,提供给所有非本系统的其他系统进行登录。具体实现的思路就是,编写一个登录的接口(本系统使用RESTful风格的),让需要该服务的其他系统通过接口提交数据,并获得相应的返回。

    服务层:系统内部的调用

      这个比较简单了,内部的所有登录,查询的操作都是通过服务层去实现的。

    我们本次的搭建使用maven实现的,如果使用其他技术,请自行从网上查找其他资料

    服务层

    首先是我们的服务层,我们的服务层中总共只有三个子项目:分别是聚合工程的父工程(taotao-sso)还有就是两个子工程,负责提供接口和依赖的接口工程(taotao-sso-interface)和负责真正的业务处理的业务处理工程(taotao-sso-service)。跟其他聚合工程的的服务层相比,它的里面是没有实体层(pojo)和持久层(mapper)的。因为项目中一般所有的数据库表都是有一个专门的团队去维护的(数据库开发工程师),目的是保证数据的安全性、读取速度等。所以对应的实体层(pojo)和持久层(mapper)的编写一般也都是由他们来进行完成的。

    而我们的单点登录系统肯定是要使用实体和持久层的,这个时候,我们需要依赖后台的pojo和mapper就可以了。

     表现层

    表现层主要提供接口给别的系统用,就是一个普通的表现层web工程。

 搭建

  搭建taotao-sso

   创建工程

    创建聚合工程父工程

    

    

    

    创建聚合工程子工程-interface

    

    

    

    创建聚合工程子工程-service

     

    

 

   加入依赖(就是pom.xml文件中的代码)

    这里依赖的那个parent的包下的xml文件也一并提供下,建工程的过程就不写了,参见taotao-sso

    
1 
2
4.0.0
3
com.taotao
4
taotao-parent
5
0.0.1-SNAPSHOT
6
pom
7 8
9
10
4.12
11
4.1.3.RELEASE
12
3.2.7
13
1.2.2
14
1.2.15
15
5.1.32
16
1.6.4
17
2.4.2
18
1.0.9
19
0.8.0.RELEASE
20
1.2
21
2.5
22
2.0
23
2.5
24
3.3.2
25
1.3.2
26
3.3
27
3.7.5
28
2.3.4
29
0.9.1
30
1.3.1
31
1.9
32
2.7.2
33
4.10.3
34
2.5.3
35
3.4.7
36
0.1
37
5.12.0
38
2.3.23
39
2.2.2
40
41 42
43
44
45
junit
46
junit
47
${junit.version}
48
test
49
50 51
52
53
org.springframework
54
spring-webmvc
55
${spring.version}
56
57
58
org.springframework
59
spring-jdbc
60
${spring.version}
61
62
63
org.springframework
64
spring-aspects
65
${spring.version}
66
67
68
org.springframework
69
spring-context-support
70
${spring.version}
71
72 73
74
75
org.mybatis
76
mybatis
77
${mybatis.version}
78
79
80
org.mybatis
81
mybatis-spring
82
${mybatis.spring.version}
83
84 85
86
87
com.github.abel533
88
mapper
89
${mapper.version}
90
91 92
93
94
com.github.pagehelper
95
pagehelper
96
${pagehelper.version}
97
98
99
com.github.jsqlparser
100
jsqlparser
101
${jsqlparser.version}
102
103 104
105
106
mysql
107
mysql-connector-java
108
${mysql.version}
109
110 111
112
113
org.slf4j
114
slf4j-log4j12
115
${slf4j.version}
116
117 118
119
120
com.fasterxml.jackson.core
121
jackson-databind
122
${jackson.version}
123
124 125
126
127
com.jolbox
128
bonecp-spring
129
${jolbox.version}
130
131 132
133
134
jstl
135
jstl
136
${jstl.version}
137
138
139
javax.servlet
140
servlet-api
141
${servlet-api.version}
142
provided
143
144
145
javax.servlet
146
jsp-api
147
${jsp-api.version}
148
provided
149
150 151
152
153
joda-time
154
joda-time
155
${joda-time.version}
156
157 158
159
160
org.apache.commons
161
commons-lang3
162
${commons-lang3.version}
163
164
165
org.apache.commons
166
commons-io
167
${commons-io.version}
168
169 170
171
172
commons-fileupload
173
commons-fileupload
174
${commons-fileupload.version}
175
176 177
178
179
com.alibaba
180
dubbo
181
${dubbo.version}
182
183
184
org.springframework
185
spring
186
187
188
org.jboss.netty
189
netty
190
191
192
193
194
org.apache.zookeeper
195
zookeeper
196
${zookeeper.version}
197
198
199
com.github.sgroschupf
200
zkclient
201
${zkclient.version}
202
203 204
205
206
commons-codec
207
commons-codec
208
${commons-codec.version}
209
210 211
212
213
org.quartz-scheduler
214
quartz
215
2.2.1
216
217 218
219
220
org.apache.activemq
221
activemq-all
222
${activemq.version}
223
224
225
org.springframework
226
spring-jms
227
${spring.version}
228
229 230
231
232
org.freemarker
233
freemarker
234
${freemarker.version}
235
236 237
238
239
redis.clients
240
jedis
241
${jedis.version}
242
243 244
245
246
org.apache.solr
247
solr-solrj
248
${solrj.version}
249
250 251
252 253
254
${project.artifactId}
255
256
257
258
org.apache.maven.plugins
259
maven-resources-plugin
260
2.7
261
262
UTF-8
263
264
265
266
267
org.apache.maven.plugins
268
maven-compiler-plugin
269
3.2
270
271
1.7272
1.7
273
UTF-8
274
275
276
277
278
279
280
281
org.apache.tomcat.maven
282
tomcat7-maven-plugin
283
2.2
284
285
286
287
288
289
290
src/main/java
291
292
**/*.properties
293
**/*.xml
294
295
false
296
297
298
299
src/main/resources
300
301
**/*.properties
302
**/*.xml
303
304
false
305
306
307
308
View Code

    taotao-sso

    
1 
3
4.0.0
4
5
com.taotao
6
taotao-parent
7
0.0.1-SNAPSHOT
8
9
com.taotao
10
taotao-sso
11
0.0.1-SNAPSHOT
12
pom
13
14
taotao-sso-interface
15
taotao-sso-service
16
17 18
19
20
21
22
org.apache.tomcat.maven
23
tomcat7-maven-plugin
24
25
8082
26
/
27
28
29
30
31
View Code

    taotao-sso-interface

    
1 
3
4.0.0
4
5
com.taotao
6
taotao-sso
7
0.0.1-SNAPSHOT
8
9
taotao-sso-interface
10
1.0.0-SNAPSHOT
11 12
13
14
15
com.taotao
16
taotao-manager-pojo
17
1.0.0-SNAPSHOT
18
19
20
View Code

    taotao-sso-service

    
1 
3
4.0.0
4
5
com.taotao
6
taotao-sso
7
0.0.1-SNAPSHOT
8
9
taotao-sso-service
10
1.0.0-SNAPSHOT
11
war
12 13
14
15
16
com.taotao
17
taotao-manager-mapper
18
1.0.0-SNAPSHOT
19
20 21
22
23
com.taotao
24
taotao-sso-interface
25
1.0.0-SNAPSHOT
26
27
28
View Code

   加入配置文件

    在taotao-service工程中,创建如图示目录和文件:

    

    其中的各个文件的配置:

    SqlMapConfig.xml

    
1 
2 5
6 7
8
9 10
11
12
13
14
15
16 17
18 19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 38 39 40
41 42 43
View Code

    jdbc.properties

    
1 jdbc.driver=com.mysql.jdbc.Driver2 jdbc.url=jdbc:mysql://localhost:3306/数据库名3 jdbc.username=root4 jdbc.password=root
View Code

    jedis.properties

    
1 #这里引用的是我的个人配置,各位读者请根据自己的配置自行修改自己的#reidis 的参数。默认使用的是单机版的,如果有想测试redis集群版的,可 2 #以通过我的博客查看如何配置。并在application.jedis 中进行修改 3 #配置redis单机版的参数 4 jedis.host=192.168.37.161 5 jedis.port=6379 6  7 #配置redis集群版的参数 8 cluster.host1=192.168.37.161 9 cluster.port1=700110 11 cluster.host2=192.168.37.16112 cluster.port2=700213 14 cluster.host3=192.168.37.16115 cluster.port3=700316 17 cluster.host4=192.168.37.16118 cluster.port4=700419 20 cluster.host5=192.168.37.16121 cluster.port5=700522 23 cluster.host6=192.168.37.16124 cluster.port6=7006
View Code

    web.xml

    
1 
2
6
taotao-sso
7 8
9
index.jsp
10
11 12
13
14
contextConfigLocation
15
classpath:spring/applicationContext*.xml
16
17 18
19
20
org.springframework.web.context.ContextLoaderListener
21
22 23
View Code

    applicationContext-dao.xml

    
1 
2
9 10
11
12 13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 34
35
36
37
38
39
40
41 42
43
44
45
46
47
View Code

    applicationContext-jedis.xml

    
1 
8 9
10
11
12
13
14 15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 48
49
50 51
52
53
View Code

    对了,还需要引入之前的redis中写的工具类的包。其实大家可以试着自己写一下,很简单的不过我还是提供下代码:建立的包结构如下:  

    

    JedisClusterUtiles.java

    
1 package com.taotao.manager.redis.impl; 2  3 import org.springframework.beans.factory.annotation.Autowired; 4  5 import com.taotao.manager.redis.RedisUtils; 6  7 import redis.clients.jedis.JedisCluster; 8  9 /**10  * 集群版redis11  * @author Administrator12  *13  */14 public class RedisCluster implements RedisUtils {15 16     @Autowired17     private JedisCluster jedisCluster;18 19     @Override20     public void set(String key, String value) {21         this.jedisCluster.set(key, value);22     }23 24     @Override25     public String get(String key) {26         String result = this.jedisCluster.get(key);27         return result;28     }29 30     @Override31     public void del(String key) {32         this.jedisCluster.del(key);33     }34 35     @Override36     public void expire(String key, Integer seconds) {37         this.jedisCluster.expire(key, seconds);38     }39 40     @Override41     public void set(String key, String value, Integer seconds) {42         this.jedisCluster.set(key, value);43         this.jedisCluster.expire(key, seconds);44     }45 46     @Override47     public Long incr(String key) {48         Long count = this.jedisCluster.incr(key);49         return count;50     }51 }
View Code

    JedisPoolUtils.java

    
1 package com.taotao.manager.redis.impl; 2  3 import org.springframework.beans.factory.annotation.Autowired; 4  5 import com.taotao.manager.redis.RedisUtils; 6  7 import redis.clients.jedis.Jedis; 8 import redis.clients.jedis.JedisPool; 9 10 /**11  * 单机版redis实现12  * @author Administrator13  *14  */15 public class RedisPool implements RedisUtils {16 17     @Autowired18     private JedisPool jedisPool;19 20     @Override21     public void set(String key, String value) {22         Jedis jedis = this.jedisPool.getResource();23 24         jedis.set(key, value);25         jedis.close();26     }27 28     @Override29     public String get(String key) {30         Jedis jedis = this.jedisPool.getResource();31 32         String result = jedis.get(key);33         jedis.close();34 35         return result;36     }37 38     @Override39     public void del(String key) {40         Jedis jedis = this.jedisPool.getResource();41 42         jedis.del(key);43         jedis.close();44 45     }46 47     @Override48     public void expire(String key, Integer seconds) {49         Jedis jedis = this.jedisPool.getResource();50 51         jedis.expire(key, seconds);52         jedis.close();53 54     }55 56     @Override57     public void set(String key, String value, Integer seconds) {58         Jedis jedis = this.jedisPool.getResource();59 60         jedis.set(key, value);61         jedis.expire(key, seconds);62         jedis.close();63 64     }65 66     @Override67     public Long incr(String key) {68         Jedis jedis = this.jedisPool.getResource();69 70         Long count = jedis.incr(key);71         jedis.close();72 73         return count;74     }75 }
View Code

    RedisUtils.java

    
1 package com.taotao.manager.redis; 2 public interface RedisUtils{ 3     /** 4      * 保存 5      *  6      * @param key 7      * @param value 8      */ 9     public void set(String key, String value);10 11     /**12      * 根据key查询13      * 14      * @param key15      * @return16      */17     public String get(String key);18 19     /**20      * 删除21      * 22      * @param key23      */24     public void del(String key);25 26     /**27      * 根据key设置生存时间28      * 29      * @param key30      * @param seconds31      */32     public void expire(String key, Integer seconds);33 34     /**35      * 保存并设置生存时间36      * 37      * @param key38      * @param value39      * @param seconds40      */41     public void set(String key, String value, Integer seconds);42 43     /**44      * value加一45      * 46      * @param key47      * @return48      */49     public Long incr(String key);50 51 }
View Code

    applicationContext-serivce.xml

    
1 
2
10 11
12
13 14
15
16 17
18
19
20
21 22
23
24 25
26
27
28 29
View Code

    applicationContext-trans.xml

    
1 
9 10
11
13
14
15 16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 33
34
37
38
39
40
41
View Code

  搭建taotao-sso-web

   创建工程

    

    

    

 

   加入依赖

    pom.xml

    
1 
3
4.0.0
4
5
com.taotao
6
taotao-parent
7
0.0.1-SNAPSHOT
8
9
com.taotao
10
taotao-sso-web
11
1.0.0-SNAPSHOT
12
war
13 14
15
16
17
com.taotao
18
taotao-sso-interface
19
1.0.0-SNAPSHOT
20
21
22 23
24
25
26
27
org.apache.tomcat.maven
28
tomcat7-maven-plugin
29
30
8085
31
/
32
33
34
35
36
View Code

   加入配置文件

    web.xml

    
1 
2
6
taotao-sso-web
7 8
9
index.html
10
11 12
13
14
encoding
15
org.springframework.web.filter.CharacterEncodingFilter
16
17
encoding
18
UTF-8
19
20
21
22
encoding
23
/*
24
25 26
27
28
taotao-sso-web
29
org.springframework.web.servlet.DispatcherServlet
30
31
32
contextConfigLocation
33
classpath:spring/springmvc.xml
34
35
1
36
37 38
39
40
taotao-sso-web
41
42
/
43
44 45
View Code

  springmvc.xml

    
1 
2
10 11
12
13 14
15
16 17
18
19 20
21
22 23
24
25
26 27
28
29
30 31
View Code

 

  

转载于:https://www.cnblogs.com/liyasong/p/sso_dj.html

你可能感兴趣的文章
unmount
查看>>
数据库连接池
查看>>
windwos iis 7.5 使用html 报405错误
查看>>
范围(地址转换)
查看>>
Unity3D游戏,TCP,WEBCOSKT,HTTP通信架构 weaving-socket
查看>>
【小程序入门集锦】19,微信小程序个人帐号申请
查看>>
php写一个简单的计算器
查看>>
【JAVA零基础入门系列】Day3 Java基本数据类型
查看>>
两个整数,求他们的最小公倍数和最大公约数
查看>>
Mongo索引
查看>>
php 实现设计模式之 建造者模式
查看>>
An Easy C Program Problem
查看>>
Replace Nested Conditional with Guard Clauses(用卫语句代替嵌套循环)
查看>>
jsp中${}是EL表达式的常规表示方式
查看>>
GoldenGate常见问题及处理
查看>>
Android JNI学习(五)——Demo演示
查看>>
SSRS 呈现Barcode Free
查看>>
java快速排序引起的StackOverflowError异常
查看>>
泛函编程(35)-泛函Stream IO:IO处理过程-IO Process
查看>>
-XX:-PrintClassHistogram 按下Ctrl+Break后,打印类的信息
查看>>