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
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2024 the original author or authors.
* Copyright 2019-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down 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() {
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