简体   繁体   English

如何在Spring Security中动态切换应用程序上下文?

[英]How to dynamically switch application context in Spring Security?

I am using Spring security in my web application and I am using Javaconfig for it. 我在我的Web应用程序中使用Spring安全性,我正在使用Javaconfig。 Recently we have also added Spring SAML authentication in the application and finally got it working after some hurdles. 最近我们还在应用程序中添加了Spring SAML身份验证,并在遇到一些障碍后终于开始工作。 Inside the WebApplicationInitializer 's onStartUp () I am loading SpringSecurity configuration or SpringSaml configuration based on some pre condition. WebApplicationInitializeronStartUp ()内部,我根据一些前提条件加载SpringSecurity配置或SpringSaml配置。

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) ? 在这个时间点,如果系统有时无法访问并且它重新初始化应用程序上下文(这实际上是我的目标),那么它是否正常?

In other words how can I call the onStartUp() method of WebApplicationInitializer ? 换句话说,如何调用WebApplicationInitializeronStartUp()方法?

You use Spring Environment Profiles to control which security configuration is loaded. 您可以使用Spring Environment Profiles来控制加载的安全配置。

To switch profile, you then update the configuration file listing the active profiles, and reload the app. 要切换配置文件,请更新列出活动配置文件的配置文件,然后重新加载应用程序。

See Spring Boot Reference Guide - 25. Profiles . 请参见Spring Boot参考指南 - 25.配置文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM