I have basic authentication enabled in my system and now I am trying to integrate the SAML auth using Spring-security-SAML. I have created a method that returns the RelyingPartRegistrationRepository
bean. In a condition While the user-configured values are not sufficient to Create the RelyingPartRegistration
, I would have to either create a RelyingPartRegistrationRepository with Empty array which is not possible because there are checks to be not empty. another option is to return null from the Bean method. which is also a failure case because context initialization will fail in that case. All I want is to either not initialize this bean or at least not prevent context initialization. So that I can at least switch back to Basic Authentication.
Asked
Active
Viewed 388 times
0

kushal agrawal
- 167
- 2
- 5
1 Answers
0
You can use @ConditionalOn...
to selectively enable/disable particular beans, based on things like properties
class MyConfiguration {
@Bean
@ConditionalOnProperty(name = "saml-enabled", havingValue = "true")
public RelyingPartRegistrationRepository() { ... }
}
See this article on Baeldung, and another article which covers a few other conditionals which may be useful, and of course the official documentation.

ptomli
- 11,730
- 4
- 40
- 68