Skip to content

Commit af83859

Browse files
committed
fix: simplify DefaultRestAuthenticatorEventPublisher construction
Parent `DefaultAuthenticationEventPublisher` creates its own no-op publisher when constructed without arguments.
1 parent 0c2e328 commit af83859

2 files changed

Lines changed: 2 additions & 20 deletions

File tree

plugin-rest/spring-security-rest/src/main/groovy/grails/plugin/springsecurity/rest/authentication/DefaultRestAuthenticationEventPublisher.groovy

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,14 @@ import org.springframework.security.authentication.DefaultAuthenticationEventPub
3030
@CompileStatic
3131
class DefaultRestAuthenticationEventPublisher extends DefaultAuthenticationEventPublisher implements RestAuthenticationEventPublisher {
3232

33-
// Spring Security 7 no longer accepts a null ApplicationEventPublisher in the
34-
// DefaultAuthenticationEventPublisher constructor, so use a no-op fallback until
35-
// Spring injects the real publisher through the setter.
36-
private static final ApplicationEventPublisher NO_OP_APPLICATION_EVENT_PUBLISHER = new ApplicationEventPublisher() {
37-
@Override
38-
void publishEvent(Object event) {
39-
}
40-
}
41-
4233
private ApplicationEventPublisher applicationEventPublisher
4334

4435
DefaultRestAuthenticationEventPublisher() {
45-
this(null)
36+
super()
4637
}
4738

4839
DefaultRestAuthenticationEventPublisher(ApplicationEventPublisher publisher) {
49-
super(publisher ?: NO_OP_APPLICATION_EVENT_PUBLISHER)
40+
super(publisher)
5041
this.applicationEventPublisher = publisher
5142
}
5243

plugin-rest/spring-security-rest/src/test/groovy/grails/plugin/springsecurity/rest/authentication/DefaultRestAuthenticationEventPublisherSpec.groovy

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,6 @@ class DefaultRestAuthenticationEventPublisherSpec extends Specification {
8383
0 * eventPublisher.publishEvent(_)
8484
}
8585

86-
void "should allow null publisher in constructor and remain no-op for token events"() {
87-
when:
88-
new DefaultRestAuthenticationEventPublisher(null).publishTokenCreation(accessToken)
89-
90-
then:
91-
noExceptionThrown()
92-
0 * eventPublisher.publishEvent(_)
93-
}
94-
9586
void "should not execute parent publishEvent when publisher is not set"() {
9687
when:
9788
new DefaultRestAuthenticationEventPublisher().publishAuthenticationSuccess(accessToken)

0 commit comments

Comments
 (0)