KeyCloak 服务器响应 IllegalArgumentException:An cookie 值或属性中存在无效的控制字符

KeyCloak server responds with IllegalArgumentException:An invalid control character was present in the cookie value or attribute

我正在尝试使用 KeyCloak 集成部署和测试简单的 Spring 启动应用程序。我正在学习这个官方教程:https://blog.keycloak.org/2017/05/easily-secure-your-spring-boot.html。但是我在浏览器中收到错误 "This page isn’t working"(未显示 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.access0(Servlet
 InitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler.call(ServletInit
 ialHandler.java:138)
    at io.undertow.servlet.handlers.ServletInitialHandler.call(ServletInit
 ialHandler.java:135)
    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction.cal
 l(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet.core.ContextClassLoaderSetupAction.call(Context
 ClassLoaderSetupAction.java:43)
    at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAct
 ion.lambda$create[=13=](SecurityContextThreadSetupAction.java:105)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi

ce$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java : 1508) 在 org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi

ce$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java: 1508) 在 org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi

ce$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java: 1508) 在 org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi

ce$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java: 1508) 在 io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(硒 rvletInitialHandler.java:272) 在 io.undertow.servlet.handlers.ServletInitialHandler.access$000(Servlet InitialHandler.java:81) 在 io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(Se rvletInitialHandler.java:104) 在 io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)

    at io.undertow.server.HttpServerExchange.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 会起作用,但无论如何在我部署我的应用程序并单击 'My products' 后我再次遇到相同的异常...

有什么猜测吗?

哈哈!解决方案是愚蠢的...我的 PC 名称...我的 PC 的名称是 Talgat-ПК。 П 和 К 是俄语字母...在我将其重命名为 Talgat-PC 后一切开始正常工作。

日期地区时间设置可以wrong.You可以设置“-Duser.language=en -Duser.country=US”到系统变量