简体   繁体   中英

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. 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) ?

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

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.

See Spring Boot Reference Guide - 25. Profiles .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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