我正在尝试使用KeyCloak集成部署和测试简单的Spring Boot应用程序。我正在关注这个官方教程:https://blog.keycloak.org/2017/05/easily-secure-your-spring-boot.html。但是我在浏览器中收到错误“此页面无效”(KeyCloak登录页面未显示),KeyCloak抛出此异常:
IllegalArgumentException: An invalid control character was present in the
cookie value or attribute
这是我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.13.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<keycloak.version>3.3.0.Final</keycloak.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.bom</groupId>
<artifactId>keycloak-adapter-bom</artifactId>
<version>${keycloak.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
这是例外日志:
09:55:18,976 ERROR [io.undertow.request] (default task-7) UT005071: Undertow
req
uest failed HttpServerExchange{ GET /auth/ request {Accept=
[text/html,applicatio
n/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8], Accept-
Langu
age=[en-US,en;q=0.9,ru-RU;q=0.8,ru;q=0.7], Cache-Control=[max-age=0],
Accept-Enc
oding=[gzip, deflate, br], User-Agent=[Mozilla/5.0 (Windows NT 6.1; Win64;
x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36],
Conn
ection=[keep-alive], Cookie=[OAuth_Token_Request_State=2132636f-ed6a-44e2-
915b-9
cefed4dc446; JSESSIONID=D0DA2ADDBE8F62E55C9F65EB71BE85A0], Referer=
[http://local
host:8080/], Upgrade-Insecure-Requests=[1], Host=[localhost:8080]} response
{Cac
he-Control=[no-cache, must-revalidate, no-transform, no-store], X-Powered-
By=[Un
dertow/1], Server=[WildFly/11], X-XSS-Protection=[1; mode=block], X-Frame-
Option s=[SAMEORIGIN], Content-Security-Policy=[frame-src 'self'; frame
ancestors
'self
'; object-src 'none';], Date=[Wed, 23 May 2018 03:55:18 GMT], Connection=
[keep-a
live], X-Robots-Tag=[none], X-Content-Type-Options=[nosniff], Content-Type=
[text
/html;charset=utf-8], Content-Length=[2740]}}:
java.lang.IllegalArgumentExceptio
n: UT000173: An invalid control character [1087] was present in the cookie
value
or attribute
at io.undertow.util.LegacyCookieSupport.isHttpSeparator(LegacyCookieSupp
ort.java:142)
at io.undertow.util.LegacyCookieSupport.isHttpToken(LegacyCookieSupport.
java:163)
at io.undertow.util.LegacyCookieSupport.adjustedCookieVersion(LegacyCook
ieSupport.java:248)
at io.undertow.server.Connectors.getCookieString(Connectors.java:154)
at io.undertow.server.Connectors.flattenCookies(Connectors.java:99)
at io.undertow.server.protocol.http.HttpResponseConduit.processWrite(Htt
pResponseConduit.java:161)
at io.undertow.server.protocol.http.HttpResponseConduit.write(HttpRespon
seConduit.java:596)
at io.undertow.conduits.AbstractFixedLengthStreamSinkConduit.write(Abstr
actFixedLengthStreamSinkConduit.java:106)
at org.xnio.conduits.Conduits.writeFinalBasic(Conduits.java:132)
at io.undertow.conduits.AbstractFixedLengthStreamSinkConduit.writeFinal(
AbstractFixedLengthStreamSinkConduit.java:175)
at org.xnio.conduits.ConduitStreamSinkChannel.writeFinal(ConduitStreamSi
nkChannel.java:104)
at io.undertow.channels.DetachableStreamSinkChannel.writeFinal(Detachabl
eStreamSinkChannel.java:195)
at io.undertow.server.HttpServerExchange$WriteDispatchChannel.writeFinal
(HttpServerExchange.java:2042)
at io.undertow.servlet.spec.ServletOutputStreamImpl.writeBufferBlocking(
ServletOutputStreamImpl.java:568)
at io.undertow.servlet.spec.ServletOutputStreamImpl.close(ServletOutputS
treamImpl.java:603)
at io.undertow.servlet.spec.HttpServletResponseImpl.closeStreamAndWriter
(HttpServletResponseImpl.java:479)
at io.undertow.servlet.spec.HttpServletResponseImpl.responseDone(HttpSer
vletResponseImpl.java:568)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest
(ServletInitialHandler.java:339)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(Servlet
InitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInit
ialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInit
ialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.cal
l(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(Context
ClassLoaderSetupAction.java:43)
at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAct
ion.lambda$create$0(SecurityContextThreadSetupAction.java:105)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi
CE $ $ UndertowThreadSetupAction.lambda创建$ 0(UndertowDeploymentInfoService.java : 1508) 在org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi
CE $ $ UndertowThreadSetupAction.lambda创建$ 0(UndertowDeploymentInfoService.java: 1508) 在org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi
CE $ $ UndertowThreadSetupAction.lambda创建$ 0(UndertowDeploymentInfoService.java: 1508) 在org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi
CE $ $ UndertowThreadSetupAction.lambda创建$ 0(UndertowDeploymentInfoService.java: 1508) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(Se rvletInitialHandler.java:272) at io.undertow.servlet.handlers.ServletInitialHandler.access $ 000(Servlet InitialHandler.java:81) at io.undertow.servlet.handlers.ServletInitialHandler $ 1.handleRequest(Se rvletInitialHandler.java:104) 在io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:8
12)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:624)
at java.lang.Thread.run(Thread.java:748)
如果我清除浏览数据keycloak将工作,但无论如何我部署我的应用程序后点击“我的产品”我再次得到相同的例外...
任何猜测?
答案 0 :(得分:1)
LOL!解决方案很愚蠢...我的电脑名称......我的电脑名称是Talgat-ПК。 П和К是俄文字母......在我将其重命名为Talgat-PC之后,一切都开始正常工作。
答案 1 :(得分:0)
日期区域时间设置可能有误,系统变量可以设置“-Duser.language=en -Duser.country=US”