Skip to content

Commit 290508a

Browse files
committed
Make anonymousAuthentication enabled by default
Signed-off-by: Andrey Litvitski <andrey1010102008@gmail.com>
1 parent 7414684 commit 290508a

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

config/src/integration-test/java/org/springframework/security/config/annotation/rsocket/AnonymousAuthenticationITests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsocket) {
121121
ReactiveAuthorizationManager<PayloadExchangeAuthorizationContext> anonymous = (authentication,
122122
exchange) -> authentication.map(trustResolver::isAnonymous).map(AuthorizationDecision::new);
123123
rsocket.authorizePayload((authorize) -> authorize.anyExchange().access(anonymous));
124+
rsocket.anonymousAuthentication((anonymousAuthentication) -> anonymousAuthentication.disable());
124125
return rsocket.build();
125126
}
126127

config/src/integration-test/java/org/springframework/security/config/annotation/rsocket/RSocketMessageHandlerITests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsocket) {
268268
.route("secure.*").authenticated()
269269
.anyExchange().permitAll()
270270
)
271-
.basicAuthentication(Customizer.withDefaults())
272-
.anonymousAuthentication(Customizer.withDefaults());
271+
.basicAuthentication(Customizer.withDefaults());
273272
// @formatter:on
274273
return rsocket.build();
275274
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public class RSocketSecurity {
120120

121121
private SimpleAuthenticationSpec simpleAuthSpec;
122122

123-
private AnonymousAuthenticationSpec anonymousAuthSpec;
123+
private AnonymousAuthenticationSpec anonymousAuthSpec = new AnonymousAuthenticationSpec(this);
124124

125125
private JwtSpec jwtSpec;
126126

@@ -174,7 +174,7 @@ public RSocketSecurity simpleAuthentication(Customizer<SimpleAuthenticationSpec>
174174
*/
175175
public RSocketSecurity anonymousAuthentication(Customizer<AnonymousAuthenticationSpec> anonymous) {
176176
if (this.anonymousAuthSpec == null) {
177-
this.anonymousAuthSpec = new AnonymousAuthenticationSpec();
177+
this.anonymousAuthSpec = new AnonymousAuthenticationSpec(this);
178178
}
179179
anonymous.customize(this.anonymousAuthSpec);
180180
return this;
@@ -297,7 +297,10 @@ protected AuthenticationPayloadInterceptor build() {
297297

298298
public final class AnonymousAuthenticationSpec {
299299

300-
private AnonymousAuthenticationSpec() {
300+
private RSocketSecurity parent;
301+
302+
private AnonymousAuthenticationSpec(RSocketSecurity parent) {
303+
this.parent = parent;
301304
}
302305

303306
protected AnonymousPayloadInterceptor build() {
@@ -306,6 +309,10 @@ protected AnonymousPayloadInterceptor build() {
306309
return result;
307310
}
308311

312+
public void disable() {
313+
this.parent.anonymousAuthSpec = null;
314+
}
315+
309316
}
310317

311318
public final class BasicAuthenticationSpec {

0 commit comments

Comments
 (0)