首页 > 解决方案 > 春季启动的Vaadin登录问题

问题描述

我对 Vaadin (v. 14.6.1) 和 Spring boot (v. 2.4.5) 有一个奇怪的问题。我已按照https://vaadin.com/learn/tutorials/securing-your-app-with-spring-security/setting-up-spring-security中的说明来实现登录视图和安全设置。

当我加载应用程序并转到 localhost/8080 登录时,我输入了正确的凭据,但登录失败并显示消息

WARN 8184 --- [io-8080-exec-10] cvfscUidlRequestHandler:从 0:0:0:0:0:0:0:1 收到的安全密钥无效

当我尝试使用相同的凭据再次登录时,登录成功。如果我注销并尝试再次登录,它工作正常。

我可以通过重新启动服务器并尝试再次登录来重现此问题。我在开发模式和生产模式下测试了这个问题,并得到了相同的行为。

标签: spring-bootvaadinvaadin14

解决方案


我发现您的代码有两个问题:

  1. 安全实用程序

ServletHelper课程已被弃用,我认为这会导致问题。我将其替换为HandlerHelper

public class SecurityUtils {

    /**
     * Tests if the request is an internal framework request. The test consists of
     * checking if the request parameter is present and if its value is consistent
     * with any of the request types know.
     *
     * @param request
     *            {@link HttpServletRequest}
     * @return true if is an internal framework request. False otherwise.
     */
    static boolean isFrameworkInternalRequest(HttpServletRequest request) {
        final String parameterValue = request.getParameter(ApplicationConstants.REQUEST_TYPE_PARAMETER);
        return parameterValue != null && Stream.of(HandlerHelper.RequestType.values())
                .anyMatch(r -> r.getIdentifier().equals(parameterValue));
    }
  1. 缺少 Vaadin 插件(如果您使用 Maven 运行它,则必须运行准备前端)

pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-maven-plugin</artifactId>
            <version>${vaadin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-frontend</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

推荐阅读