如何在 Spring Security 中动态切换应用程序上下文? [英] How to dynamically switch application context in Spring Security?

查看:76
本文介绍了如何在 Spring Security 中动态切换应用程序上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 Web 应用程序中使用 Spring 安全性,我正在使用 Javaconfig.最近,我们还在应用程序中添加了 Spring SAML 身份验证,并最终在一些障碍后使其工作.在 WebApplicationInitializeronStartUp() 中,我正在根据一些前置条件加载 SpringSecurity 配置或 SpringSaml 配置.

I am using Spring security in my web application and I am using Javaconfig for it. Recently we have also added Spring SAML authentication in the application and finally got it working after some hurdles. Inside the WebApplicationInitializer's onStartUp() I am loading SpringSecurity configuration or SpringSaml configuration based on some pre condition.

现在我怎样才能动态地做到这一点?实际上,我将介绍一个按钮,一旦管理员单击此按钮,管理员将注销所有用户并重新加载上下文.此时,如果系统在一段时间内无法访问并重新初始化应用程序上下文(这实际上是我的目标),那还可以吗?

Now how can I do this dynamically ? Actually I will introduce a button and once admin clicks on this button admin and all users will be logged out and context should be reloaded. At this point of time its ok if system is inaccessible for sometime and it re initializes application context (which is actually my goal) ?

换句话说,我如何调用 WebApplicationInitializeronStartUp() 方法?

In other words how can I call the onStartUp() method of WebApplicationInitializer ?

推荐答案

您使用 Spring Environment Profiles 来控制加载哪个安全配置.

You use Spring Environment Profiles to control which security configuration is loaded.

要切换配置文件,请更新列出活动配置文件的配置文件,然后重新加载应用.

To switch profile, you then update the configuration file listing the active profiles, and reload the app.

参见 Spring Boot 参考指南 -25. 个人资料.

这篇关于如何在 Spring Security 中动态切换应用程序上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆