当我尝试从Spring Boot应用程序访问OAuth HTTPS端点时,出现以下错误,但是HTTP端点工作得很好
错误:
2018-07-24 10:25:06.292 [DEBUG] [8464] [https-jsse-nio-8084-exec-8] o.apache.coyote.http11.Http11Processor:解析HTTP请求标头
java.io.EOFException:在org.apache.tomcat.util.net.NioEndpoint $ NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1250)为null 在 org.apache.tomcat.util.net.NioEndpoint $ NioSocketWrapper.read(NioEndpoint.java:1190) 在 org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:717) 在 org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:366) 在 org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687) 在 org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 在 org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:790) 在 org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1459) 在 org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 在 java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624) 在 org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(Thread.java:748)
端点
https://localhost:8084/my-auth/oauth/authorize
https://localhost:8084/my-auth/oauth/token
用于ssl的应用程序YML配置:
port: 8084
non-http-port: 8083
context-path: /my-auth
ssl:
key-alias: <my cert alais>
key-password: <my pasword>
key-store: <my jks path>
key-store-type: JKS
enabled: true
安全性Java配置
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern(contextPath+"/api/v1/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(redirectConnector());
return tomcat;
}
private Connector redirectConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(unSecuredPort);
connector.setSecure(false);
connector.setRedirectPort(securedPort);
return connector;
}
POM文件
<?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">
<parent>
<artifactId>my-app-name</artifactId>
<groupId>my.group.id</groupId>
<version>my-version</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>my-app-name</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.0.15.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
答案 0 :(得分:0)
我刚刚找到了一个解决方案,问题出在本地主机的自签名证书上。一旦将这些导入到您的JDK信任库中,一切就可以正常工作。
答案 1 :(得分:0)
感谢@bavlin
要在本地工作Oauth2端点,您必须在本地JRE信任库中安装证书
使用以下命令将其添加到本地信任存储中:(在命令提示符下)
•keytool-密钥库cacerts-导入-trustcacerts-文件“证书的文件路径”
•要使其在邮递员中工作-在chrome浏览器中,将localhost cert安装到“受信任的根证书颁发机构”
答案 2 :(得分:0)
这不是错误,而是调试消息。
我也击中了这个,我相信正确的答案在这里:
我在tomcat nabble site 上找到的如果日志级别不是DEBUG,则EOF将被默默地吞下。不幸的是,该消息显示“意外的EOF”,因为在这种情况下,这是正常现象。
此处的调试消息:
catch (IOException e) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("http11processor.header.parse"), e);
}
setErrorState(ErrorState.CLOSE_CONNECTION_NOW, e);
break;
}
在Http11Processor from Tomcat 8.5
中为此Tomcat修复程序添加了导致该错误的EOFException:Non-blocking should throw an EOFException on EOF as well
我在spring-cloud github discussion 的另一个关于“问题”的讨论中找到了
我认为这是完全正常的,因为我们的同事根据apache/tomcat@91b7859添加了此
OEFException
。当将SSL连接到非SSL连接器时,在INFO级别上记录错误有点激进。