Skip to content

Add option to disable anonymous authentication in RSocketSecurity #17159

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
* @author Manuel Tejeda
* @author Ebert Toribio
* @author Ngoc Nhan
* @author Andrey Litvitski
* @since 5.2
*/
public class RSocketSecurity {
Expand All @@ -119,6 +120,8 @@ public class RSocketSecurity {

private SimpleAuthenticationSpec simpleAuthSpec;

private boolean disableAnonymous;

private JwtSpec jwtSpec;

private AuthorizePayloadsSpec authorizePayload;
Expand Down Expand Up @@ -179,6 +182,15 @@ public RSocketSecurity basicAuthentication(Customizer<BasicAuthenticationSpec> b
return this;
}

/**
* Disables anonymous authentication.
* @return the builder for additional customizations
*/
public RSocketSecurity disableAnonymous() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree that this is a straightforward way to expose the feature, I see some additional benefit in exposing it in a way that's similar to HttpSecurity and ServerHttpSecurity. Are you able to add this feature in the following way instead?

Copy link
Contributor Author

@therepanic therepanic Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that would indeed be better. I think we should add a class similar to RSocketSecurity.BasicAuthenticationSpec, but without fields, and the build() method will execute the logic of the current anonymous() method. And I think we can remove it as unnecessary.

this.disableAnonymous = true;
return this;
}

public RSocketSecurity jwt(Customizer<JwtSpec> jwt) {
if (this.jwtSpec == null) {
this.jwtSpec = new JwtSpec();
Expand Down Expand Up @@ -214,7 +226,9 @@ private List<PayloadInterceptor> payloadInterceptors() {
if (this.jwtSpec != null) {
result.addAll(this.jwtSpec.build());
}
result.add(anonymous());
if (!this.disableAnonymous) {
result.add(anonymous());
}
if (this.authorizePayload != null) {
result.add(this.authorizePayload.build());
}
Expand Down