Skip to content

Commit 2feef7a

Browse files
therepanicjzheaux
authored andcommitted
add option to disable anonymous authentication in RSocketSecurity (spring-projects#17132)
Signed-off-by: Andrey Litvitski <[email protected]>
1 parent d9c894f commit 2feef7a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 the original author or authors.
2+
* Copyright 2019-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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)