SpringBoot - 解析HTTP请求标头时出错(Oauth2 https端点)

问题描述 投票:2回答:3

当我尝试从spring启动应用程序访问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:null org.apache.tomcat.util.net.NioEndpoint $ NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1250)at org.apache.tomcat.util.net.NioEndpoint $ NioSocketWrapper.read(NioEndpoint.java) :org.apache.coyote.http11,http:1190)org.apache。 Http11Processor.service(Http11Processor.java:687)org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)atg.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:790)org.apache .tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1459)atg.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)位于org.apache.tomcat.util.thre的java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624) ads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)at 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>
spring spring-boot spring-security spring-security-oauth2
3个回答
0
投票

我刚刚找到了解决方案,问题在于localhost的自签名证书。一旦在JDK的信任库中导入这些,一切都应该正常工作。


0
投票

谢谢@bavlin

要在本地工作Oauth2端点,您需要在本地JRE信任库中安装证书

使用以下命令在本地信任库中添加:(在命令提示符下)

•keytool -keystore cacerts -import -trustcacerts -file“cert的文件路径”

•使其在邮递员中工作 - 在Chrome浏览器中,将localhost证书安装到“受信任的根证书颁发机构”


0
投票

这不是错误,它是一个调试消息。

我也打了这个,我相信正确的答案在这里:

如果日志级别不是DEBUG,则EOF会被静默吞噬。不幸的是,消息上写着“意外的EOF”,因为在这种情况下这是正常的。

我在tomcat nabble site找到了

这里的调试信息:

   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

并且导致它的EOFException被添加到这个Tomcat修复:Non-blocking should throw an EOFException on EOF as well

我在这个spring-cloud github discussion的另一个关于这个“问题”的讨论中找到了

我认为这是完全正常的,因为这个OEFException是我们的同事根据apache/tomcat@91b7859添加的。当对非ssl连接器进行ssl连接时,INFO级别上的日志记录错误有点激进。

© www.soinside.com 2019 - 2024. All rights reserved.