Skip to content

Commit 19015a1

Browse files
therepanicjzheaux
authored andcommitted
Add Disabling Anonymous Authentication in RSocketSecurity
Closes gh-17132 Signed-off-by: Andrey Litvitski <[email protected]>
1 parent ca557a9 commit 19015a1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

config/src/main/java/org/springframework/security/config/annotation/rsocket/RSocketSecurity.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
* @author Manuel Tejeda
110110
* @author Ebert Toribio
111111
* @author Ngoc Nhan
112+
* @author Andrey Litvitski
112113
* @since 5.2
113114
*/
114115
public class RSocketSecurity {
@@ -119,6 +120,8 @@ public class RSocketSecurity {
119120

120121
private SimpleAuthenticationSpec simpleAuthSpec;
121122

123+
private boolean disableAnonymous;
124+
122125
private JwtSpec jwtSpec;
123126

124127
private AuthorizePayloadsSpec authorizePayload;
@@ -179,6 +182,15 @@ public RSocketSecurity basicAuthentication(Customizer<BasicAuthenticationSpec> b
179182
return this;
180183
}
181184

185+
/**
186+
* Disables anonymous authentication.
187+
* @return the builder for additional customizations
188+
*/
189+
public RSocketSecurity disableAnonymous() {
190+
this.disableAnonymous = true;
191+
return this;
192+
}
193+
182194
public RSocketSecurity jwt(Customizer<JwtSpec> jwt) {
183195
if (this.jwtSpec == null) {
184196
this.jwtSpec = new JwtSpec();
@@ -214,7 +226,9 @@ private List<PayloadInterceptor> payloadInterceptors() {
214226
if (this.jwtSpec != null) {
215227
result.addAll(this.jwtSpec.build());
216228
}
217-
result.add(anonymous());
229+
if (!this.disableAnonymous) {
230+
result.add(anonymous());
231+
}
218232
if (this.authorizePayload != null) {
219233
result.add(this.authorizePayload.build());
220234
}

0 commit comments

Comments
 (0)