1
1
/*
2
- * Copyright 2019-2024 the original author or authors.
2
+ * Copyright 2019-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
109
109
* @author Manuel Tejeda
110
110
* @author Ebert Toribio
111
111
* @author Ngoc Nhan
112
+ * @author Andrey Litvitski
112
113
* @since 5.2
113
114
*/
114
115
public class RSocketSecurity {
@@ -119,6 +120,8 @@ public class RSocketSecurity {
119
120
120
121
private SimpleAuthenticationSpec simpleAuthSpec ;
121
122
123
+ private boolean disableAnonymous ;
124
+
122
125
private JwtSpec jwtSpec ;
123
126
124
127
private AuthorizePayloadsSpec authorizePayload ;
@@ -179,6 +182,15 @@ public RSocketSecurity basicAuthentication(Customizer<BasicAuthenticationSpec> b
179
182
return this ;
180
183
}
181
184
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
+
182
194
public RSocketSecurity jwt (Customizer <JwtSpec > jwt ) {
183
195
if (this .jwtSpec == null ) {
184
196
this .jwtSpec = new JwtSpec ();
@@ -214,7 +226,9 @@ private List<PayloadInterceptor> payloadInterceptors() {
214
226
if (this .jwtSpec != null ) {
215
227
result .addAll (this .jwtSpec .build ());
216
228
}
217
- result .add (anonymous ());
229
+ if (!this .disableAnonymous ) {
230
+ result .add (anonymous ());
231
+ }
218
232
if (this .authorizePayload != null ) {
219
233
result .add (this .authorizePayload .build ());
220
234
}
0 commit comments