-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add with() method to apply Custom DSLs returning the builder #13204
Comments
Thanks for reaching out, @bwgjoseph, I think you make a good point that |
Hi @bwgjoseph, thank you so much for the report. After talking to @jzheaux, we decided that we want to add a new public <C extends SecurityConfigurerAdapter<O, B>> B with(C configurer) throws Exception {
configurer.addObjectPostProcessor(this.objectPostProcessor);
configurer.setBuilder((B) this);
add(configurer);
return (B) this;
} Then you can do: http
.with(new CustomDsl().myMethod())
.formLogin(Customizer.withDefaults())
.httpBasic(Customizer.withDefaults()); I already prioritized this for 6.2. I'll update the issue's title to align better with the problem if you are okay with it. As of now, you can create a new method inside your custom DSL that returns the builder: static class CustomDsl extends AbstractHttpConfigurer<CustomDsl, HttpSecurity> {
// ...
public HttpSecurity build() {
return getBuilder();
}
}
// then
http
.apply(new CustomDsl()
.myMethod()
.myOtherMethod()
.build())
.formLogin(...)
// ... |
Thank you, this new way looks good. I just tried what you suggested but encounter some error.
public class DummyDsl extends AbstractHttpConfigurer<DummyDsl, HttpSecurity> {
@Override
public void init(HttpSecurity http) throws Exception {
http.formLogin(AbstractHttpConfigurer::disable);
}
public static DummyDsl dummyDsl() {
return new DummyDsl();
}
public HttpSecurity build() {
return getBuilder();
}
} |
What I meant is to replace http.apply(new DummyDsl()).build()
.formLogin(...)
.build(); I realize that the name of the method might be somewhat confusing. You might call it different than |
Great, I think it works now. Thanks for the great work 👏 |
This method is intended to replace .apply() because it will not be possible to chain configurations when .and() gets removed Closes spring-projectsgh-13204
This method is intended to replace .apply() because it will not be possible to chain configurations when .and() gets removed Closes gh-13204
Given that
and()
is stated for removal, does it mean that in the future, I cannot chain theHttpSecurity
?The text was updated successfully, but these errors were encountered: