Vaadin 23 重新部署后无法完全重新加载应用程序

2024-05-13

现在,我正在准备 Vaadin 23.2.5 应用程序进行生产,并且经常在重新部署应用程序后无法完全重新加载自身,并在顶部挂有蓝色的进度条。

我可能看到的唯一问题是浏览器控制台中的以下 JS 问题:

FireFox

Chrome

另外,根据我之前关于此主题的问题 - 我从应用程序中完全删除了网格组件,但正如您所看到的 - 问题仍然存在。如何解决这个问题?

UPDATED

我的配置:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfiguration extends VaadinWebSecurityConfigurerAdapter {

    private final ClientRegistrationRepository clientRegistrationRepository;
    private final GrantedAuthoritiesMapper authoritiesMapper;
    private final ProfileService profileService;

    SecurityConfiguration(ClientRegistrationRepository clientRegistrationRepository,
                          GrantedAuthoritiesMapper authoritiesMapper, ProfileService profileService) {
        this.clientRegistrationRepository = clientRegistrationRepository;
        this.authoritiesMapper = authoritiesMapper;
        this.profileService = profileService;
        SecurityContextHolder.setStrategyName(VaadinAwareSecurityContextHolderStrategy.class.getName());
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);
        http
                // Enable OAuth2 login
                .oauth2Login(oauth2Login ->
                        oauth2Login
                                .clientRegistrationRepository(clientRegistrationRepository)
                                .userInfoEndpoint(userInfoEndpoint ->
                                        userInfoEndpoint
                                                // Use a custom authorities mapper to get the roles from the identity provider into the Authentication token
                                                .userAuthoritiesMapper(authoritiesMapper)
                                )
                                // Use a Vaadin aware authentication success handler
                                .successHandler(new KeycloakVaadinAuthenticationSuccessHandler(profileService))
                )
                // Configure logout
                .logout(logout ->
                        logout
                                // Enable OIDC logout (requires that we use the 'openid' scope when authenticating)
                                .logoutSuccessHandler(logoutSuccessHandler())
                                // When CSRF is enabled, the logout URL normally requires a POST request with the CSRF
                                // token attached. This makes it difficult to perform a logout from within a Vaadin
                                // application (since Vaadin uses its own CSRF tokens). By changing the logout endpoint
                                // to accept GET requests, we can redirect to the logout URL from within Vaadin.
                                .logoutRequestMatcher(new AntPathRequestMatcher("/logout", "GET"))
                );
    }

    @Bean
    @Primary
    public SpringViewAccessChecker springViewAccessChecker(AccessAnnotationChecker accessAnnotationChecker) {
        return new KeycloakSpringViewAccessChecker(accessAnnotationChecker, "/oauth2/authorization/keycloak");
    }

    private OidcClientInitiatedLogoutSuccessHandler logoutSuccessHandler() {
        var logoutSuccessHandler = new OidcClientInitiatedLogoutSuccessHandler(clientRegistrationRepository);
        logoutSuccessHandler.setPostLogoutRedirectUri("{baseUrl}");
        return logoutSuccessHandler;
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        super.configure(web);
        // Don't apply security rules on our static pages
        web.ignoring().antMatchers("/session-expired", "/images/*");
    }

    @Bean
    public PolicyFactory htmlSanitizer() {
        // This is the policy we will be using to sanitize HTML input
        return Sanitizers.FORMATTING.and(Sanitizers.BLOCKS).and(Sanitizers.STYLES).and(Sanitizers.LINKS);
    }

}


@Component
class VaadinSessionConfiguration implements VaadinServiceInitListener, SystemMessagesProvider, SessionDestroyListener {

    private final String relativeSessionExpiredUrl;

    VaadinSessionConfiguration(ServerProperties serverProperties) {
        relativeSessionExpiredUrl = UriComponentsBuilder.fromPath(serverProperties.getServlet().getContextPath()).path("logout").build().toUriString();
    }

    @Override
    public SystemMessages getSystemMessages(SystemMessagesInfo systemMessagesInfo) {
        var messages = new CustomizedSystemMessages();
        // Redirect to a specific screen when the session expires. In this particular case we don't want to logout
        // just yet. If you would like the user to be completely logged out when the session expires, this URL
        // should the logout URL.
        messages.setSessionExpiredURL(relativeSessionExpiredUrl);
        return messages;
    }

    @Override
    public void sessionDestroy(SessionDestroyEvent event) {
        // We also want to destroy the underlying HTTP session since it is the one that contains the authentication
        // token.
        try {
            event.getSession().getSession().invalidate();
        } catch (Exception ignore) {
            // Session was probably already invalidated.
        }
    }

    @Override
    public void serviceInit(ServiceInitEvent event) {
        event.getSource().setSystemMessagesProvider(this);
        event.getSource().addSessionDestroyListener(this);
    }

}

public final class VaadinAwareSecurityContextHolderStrategy implements SecurityContextHolderStrategy {

    private final ThreadLocal<SecurityContext> contextHolder = new ThreadLocal<>();

    @Override
    public void clearContext() {
        contextHolder.remove();
    }

    @Override
    @NonNull
    public SecurityContext getContext() {
        var context = contextHolder.get();
        if (context == null) {
            context = getFromVaadinSession().orElseGet(() -> {
                var newCtx = createEmptyContext();
                // This copies the behaviour of ThreadLocalSecurityContextHolder.
                contextHolder.set(newCtx);
                return newCtx;
            });
        }
        return context;
    }

    @NonNull
    private Optional<SecurityContext> getFromVaadinSession() {
        // Don't store this security context in the ThreadLocal as that may lead to the context leaking
        // into other sessions as threads may be reused.
        var session = VaadinSession.getCurrent();
        if (session == null) {
            return Optional.empty();
        }
        var securityContext = session.getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
        if (securityContext instanceof SecurityContext) {
            return Optional.of((SecurityContext) securityContext);
        } else {
            return Optional.empty();
        }
    }

    @Override
    public void setContext(@NonNull SecurityContext securityContext) {
        contextHolder.set(requireNonNull(securityContext));
    }

    @Override
    @NonNull
    public SecurityContext createEmptyContext() {
        return new SecurityContextImpl();
    }
}

更新1


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Vaadin 23 重新部署后无法完全重新加载应用程序 的相关文章

随机推荐

  • WebView 与 Chrome 自定义选项卡

    我正在构建一个应用程序 在详细活动中我必须显示一个网页 我本来打算使用 WebView 但后来我看到了 Chrome Custom Tab 你们认为最好实施什么 为什么 如果您只想显示某个页面 那么我建议您使用 chrome 自定义选项卡
  • git在Windows和Linux之间切换后强制刷新索引

    我有一个Windows和Linux共享的磁盘分区 格式 NTFS 它包含一个 git 存储库 约 6 7 GB 如果我只使用Windows or 只使用Linux操作 git 存储库一切正常 但是每次切换系统的时候git status命令将
  • laravel 5:找不到类“输入”

    In my routes php我有的文件 Route get function return view login Route get index function return view index Route get register
  • 尝试拍摄 https://github.com/appsthatmatter/GraphView 的图表快照时出现 IllegalStateException

    我正在尝试拍摄 GraphView 的快照 但它给出了错误 GraphView 必须在硬件加速模式下使用 我正在使用以下代码来拍摄快照 Bitmap bitmap Bitmap createBitmap view getWidth view
  • Android 无法查找支持版本 27.0.0 的窗口

    更新后supportVersion to 27 0 0仅在 Android 5 0 2 上 应用程序会因以下堆栈跟踪而崩溃 W WindowManager Failed looking up window java lang Illegal
  • 如何从android中的webview获取选定的文本?

    我需要从网络视图中获取选定的文本 为此 我这样说 webView loadUrl javascript Android getHtml window getSelection toString 在我的触摸事件中 触摸事件效果很好 Andro
  • 如何使用scrapy抓取xml url

    你好 我正在使用 scrapy 来抓取 xml url 假设下面是我的 Spider py 代码 class TestSpider BaseSpider name test allowed domains www example com s
  • Iexpress 用于大文件(损坏的 Cabinet 文件)

    我希望结合许多安装程序并使用 Iexpress 制作一个 exe 安装程序的总大小为 750MB 我尝试使用 Iexpress 合并并生成 但创建的 exe 文件大小只有 80MB 当我双击并尝试运行该 exe 时 它 指出其内阁文件已损坏
  • 从when语句内的函数返回

    我想做的就是使用 when 语句返回一个值 我想要以下功能 if x return y 我正在尝试使用 when x y 但是when语句并没有以退出函数并返回y的方式进行计算 它只是愉快地继续下一行 有没有办法做到这一点而不需要制作一个看
  • 如何在运行“go test”时排除或跳过特定目录[重复]

    这个问题在这里已经有答案了 go test go list grep v vendor coverprofile testCoverage txt 我正在使用上述命令来测试文件 但有 1 个名为 Store 的文件夹我想从测试中排除 怎样才
  • 传单圆圈绘制/编辑问题

    我第一次制作传单 并面临绘制圆圈和编辑 更改圆圈位置 的问题 我面临的问题是 编辑 移动 圆从一个位置到另一位置会改变其半径 Note 请尝试在给定的小提琴中在地图顶部创建圆圈 然后通过单击编辑按钮将其移动到底部 如果我在地图的顶部创建圆圈
  • 如何在 JavaScript 中检查未定义的变量

    我想检查变量是否已定义 例如 以下内容会引发未定义的错误 alert x 我怎样才能捕获这个错误 在 JavaScript 中 null是一个对象 不存在的事物还有另一种价值 undefined DOM 返回null对于几乎所有无法在文档中
  • 如何收集 Sphinx 中的所有外部链接?

    我必须在手册中放入一些外部链接 并且希望在 部分甚至整本书的末尾 不重要 列出所有链接 而无需手动重复它们 我怎样才能做到这一点 这是带有参考书目的文档的摘录 呈现的版本是here http packages python org pyte
  • 在嵌入式 Jetty 上使用 DefaultServlet 提供静态 html 文件

    我正在开发一个需要独立的项目 因此我决定将 Jetty 嵌入到我的应用程序中 我将提供静态 HTML 页面 一些 JSP 页面 并且还将使用一些自定义 servlet 我找到了一个完美的示例 说明如何设置嵌入式 Jetty 来完成所有这一切
  • 通过 clang++ 的 -finstrument-functions 进行 C++ 函数检测:如何忽略内部 std 库调用?

    假设我有一个类似的函数 template
  • 捕获动态表中 HTML 元素的值

    我有从数据库生成的以下动态表
  • iPhone表情插入MySQL却变成空值

    我们正在开发一个 iPhone 应用程序 它将表情符号从 iPhone 发送到服务器端 PHP 并插入到 MySQL 表中 我正在做服务器端的工作 但是insert语句执行成功后 插入的值变成空了 我可以正确插入字段 varchar 的是文
  • GOPATH值设置

    我用go1 3 1 windows amd64 msi安装go 安装后GOROOT是默认设置 我发现 D Programs Go bin 在 PATH 中 然后我创建一个 GOPATH 环境变量 使用 go get 命令时 出现错误 软件包
  • Twython - 如何使用媒体 url 更新状态

    在我的应用程序中 我允许用户在 Twitter 上发帖 现在我想让他们通过媒体更新他们的状态 In twython py我看到一个方法update status with media从文件系统读取图像并上传到 Twitter 我的图像不在文
  • Vaadin 23 重新部署后无法完全重新加载应用程序

    现在 我正在准备 Vaadin 23 2 5 应用程序进行生产 并且经常在重新部署应用程序后无法完全重新加载自身 并在顶部挂有蓝色的进度条 我可能看到的唯一问题是浏览器控制台中的以下 JS 问题 FireFox Chrome 另外 根据我之