and using an integrated keycloak sprinboot client records (a)

A, SSO

SSO, Chinese name "Single Sign On", English name is SingleSignOn. Understand, probably the unified portal login, unified user management and authentication, shared authentication services mean. Baidu Encyclopedia criteria explained as follows:

Single sign-on (SingleSignOn, SSO), it is a one-time identification of the logged in user. When the user authentication server to log on again later, you can get access to single sign-on system in other federal systems and applications software.
While this implementation does not require administrator user's login status or other information to make changes, which means that multiple applications, users with a single login to access all mutual trust applications. This approach reduces the time consumed by the login produced auxiliary user management, is currently more popular.

Focus on single sign-on is a very versatile with a demand, so there is a lot of open source solutions correspond, to contact individuals currently there are two, one is the CAS, is a keycloak, keycloak this is a learning .

Two, keycloak foundation for an integrated reference documentation:

keycloak official document personally I think it is to force a lot of things do not need extra to go elsewhere in search data, so the foundation for an integrated basic direct reference to the official website of the document on the line, the following is a personal process using springboot integrated in the main reference of the official website of the document:
HTTPS : //www.keycloak.org/docs/latest/getting_started/index.html
https://www.keycloak.org/docs/latest/securing_apps/index.html#_spring_boot_adapter

As the description on the official website of integration steps is very detailed, so it seems there is no basic steps necessary to copy again.
From the big step is, basically two steps:
step is to download, configure and start keycloak server, and then refer to the upper link in the document various configurations on the service side UI interface;
another step in that client integration keycloak.

The difference is that the official entry guide in only the most simple examples, so some of the details still have many problems. The following is a preliminary question recorded in the integration process:

Third, the problem record

1, the difference between springboot1.5 integration and integration keycloak 2.0 client

Due to the current limitations of the project, or based version springboot, so I just started also using this version of springboot 1.5, and then refer to the official documentation integrated client, mainly the introduction of the following two maven configuration:
<pre>
<dependency >
<the groupId> org.keycloak </ the groupId>
<the artifactId> keycloak-Spring-Boot-Starter </ the artifactId>
</ dependency>
<the dependencyManagement>
<Dependencies>
<dependency>
<the groupId> org.keycloak.bom </ the groupId>
<the artifactId> keycloak-Adapter-BOM </ the artifactId>
<Version> 6.0.1 </ Version>
<type> POM </ type>
<scope> Import </ scope>
</ dependency>
</ Dependencies>
</ the dependencyManagement>

but integration has been started after the error:

java.lang.NoClassDefFoundError: org/springframework/boot/web/server/WebServerFactoryCustomizer
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_201]
	at java.lang.Class.privateGetDeclaredMethods(Unknown Source) ~[na:1.8.0_201]
	at java.lang.Class.getDeclaredMethods(Unknown Source) ~[na:1.8.0_201]

After a lot of information to find reasons not find, ask a colleague stepped before the next pit, I know that this is version, and then try again springboot version 2.0 instead, really started successfully, and normal use.
But other projects are 1.5 springboot, is unlikely to suddenly upgrade, so in fact springboot version 1.5 still need the job and finally found a 1.5 version springboot integrated properly configured, eliminating the need dependencyManagement top configuration, then keycloak- spring-boot-starter-dependent configuration to below:

<dependency>
	  <groupId>org.keycloak</groupId>
          <artifactId>keycloak-legacy-spring-boot-starter</artifactId>
          <version>6.0.1</version>
</dependency>

2, H2 database server configuration issues instead of mysql

How to keycloak comes with an embedded database H2 to switch to another database, the document's official website also has some instructions, it can be considered in more detail, but some details still cause a variety of problems. We are basically project currently use mysql, so here you want to change, then naturally changed mysql to test the integration process discovered there are two problems:

2.1, jar version of the problem

Official website did not say what version of the database to be, saying only that the package need to drive, so I started a project directly in the 5.1.46 version of mysql to take over with the result the server would not start.
Later, after a variety of search data, the server mysql driven into mysql-connector-java-8.0.11.jar, and after repeated tests proved really this version can, but 5.1.46 will not do.

2.2, database connectivity problems will bring the url serverTimeZone

Whether it is the official website or most of the information online, it does not seem to mention serverTimeZone the url parameter when mysql connection problems, but found that without this parameter start the server will throw an exception when actually used as follows:
java.lang.RuntimeException: WFLYCTL0195: Interrupted awaiting transaction commit or rollback
Thus, the actual mysql url should be connected in the following manner:
JDBC: mysql: // localhost:? 3306 / keycloak to false useSSL = GMT = & serverTimezone% = UTF-2B8 & characterEncoding. 8

3, on public and confidential customer problems end configuration

When keycloak service end ui interface to create and configure a client, there are three types available, namely public, confidential and bearer-only, public is net example official, and many other network information tutorial type, bearer-only have a certain limit, so basically being tried public and confidential types.
It should be noted that the use of public type, springboot client configuration must be below this configuration:

keycloak.public-client=true

The use of confidential type, you need to remove this configuration, otherwise an exception will be 403.

Published 272 original articles · won praise 371 · Views 1.26 million +

Guess you like

Origin blog.csdn.net/tuzongxun/article/details/96979245