Skip to content

Commit 8baf419

Browse files
committed
Prevent duplicate AuthenticationSuccessEvent
An event would be published both for AuthenticationSuccessEvent and InteractiveAuthenticationSuccessEvent. The listen InteractiveAuthenticationSuccessEvent event was added in commit c173790 , because ODIC would not publish the AuthenticationSuccessEvent. This is now fixed in Spring (spring-projects/spring-security#6009) and therefore we don't have to listen for both events.
1 parent 721a8b6 commit 8baf419

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/service/UserService.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,6 @@ public void onApplicationEvent(AbstractAuthenticationEvent event) {
193193
this,
194194
userId,
195195
RequestContextHolder.currentRequestAttributes().getSessionId()));
196-
} else if (event instanceof AuthenticationSuccessEvent) {
197-
// } else if (event instanceof AuthenticationSuccessEvent || event instanceof InteractiveAuthenticationSuccessEvent) {
198-
String userName = source.getName();
199-
log.info(String.format("User logged in [user: %s]", userName));
200-
eventService.post(EventType.Login.toString(), userName, null);
201-
202-
String userId = getUserId(source);
203-
// TODO test for anonymous users
204-
applicationEventPublisher.publishEvent(new UserLoginEvent(
205-
this,
206-
userId,
207-
RequestContextHolder.currentRequestAttributes().getSessionId()));
208196
}
209197
}
210198

@@ -225,6 +213,22 @@ public void logout(Authentication auth) {
225213
false));
226214
}
227215

216+
@EventListener
217+
public void onAuthenticationSuccessEvent(AuthenticationSuccessEvent event) {
218+
Authentication auth = event.getAuthentication();
219+
String userName = auth.getName();
220+
221+
log.info(String.format("User logged in [user: %s]", userName));
222+
eventService.post(EventType.Login.toString(), userName, null);
223+
224+
// TODO test for anonymous users
225+
String userId = getUserId(auth);
226+
applicationEventPublisher.publishEvent(new UserLoginEvent(
227+
this,
228+
userId,
229+
RequestContextHolder.currentRequestAttributes().getSessionId()));
230+
}
231+
228232
@EventListener
229233
public void onSessionExpiredEvent(SessionExpiredEvent event) {
230234
Session session = event.getSession();

0 commit comments

Comments
 (0)