Skip to content

Publish an AuditEvent on logout #41278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Chu3laMan
Copy link
Contributor

No description provided.

@pivotal-cla
Copy link

@Chu3laMan Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 30, 2024
@pivotal-cla
Copy link

@Chu3laMan Thank you for signing the Contributor License Agreement!

Copy link
Member

@wilkinsona wilkinsona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @Chu3laMan. I've left a few comments for you to consider when you have a minute.

@@ -93,6 +99,18 @@ private void onAuthenticationSuccessEvent(AuthenticationSuccessEvent event) {
publish(new AuditEvent(event.getAuthentication().getName(), AUTHENTICATION_SUCCESS, data));
}

private void onLogoutSuccessEvent(LogoutSuccessEvent event) {
Map<String, Object> data = new LinkedHashMap<>();
if(event.getAuthentication() != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check isn't needed as getAuthentication() should never return null.

if(event.getAuthentication().getDetails() != null) {
data.put("details", event.getAuthentication().getDetails());
}
data.put("username", event.getAuthentication().getName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The username's already included in the event (it's its principal) so it doesn't needed to be included as a separate piece of data.

@@ -51,6 +52,8 @@ public class AuthenticationAuditListener extends AbstractAuthenticationAuditList
*/
public static final String AUTHENTICATION_SWITCH = "AUTHENTICATION_SWITCH";

public static final String LOGOUT_SUCCESS = "LOGOUT_SUCCESS";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some javadoc here that describes the constant. It should also be marked with @since 3.4.0.

@@ -73,6 +76,9 @@ else if (this.webListener != null && this.webListener.accepts(event)) {
else if (event instanceof AuthenticationSuccessEvent successEvent) {
onAuthenticationSuccessEvent(successEvent);
}
else if(event instanceof LogoutSuccessEvent logoutSuccessEvent) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the formatting. You can run ./gradlew spring-boot-project:spring-boot-actuator:format to correct it automatically.

@Chu3laMan
Copy link
Contributor Author

Thanks for the PR, @Chu3laMan. I've left a few comments for you to consider when you have a minute.

Thank you for your remarks, do not we need to handle error during logout phase in the same function?

@mhalbritter mhalbritter added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 3, 2024
@mhalbritter mhalbritter self-assigned this Jul 3, 2024
@mhalbritter mhalbritter added this to the 3.4.x milestone Jul 3, 2024
@mhalbritter
Copy link
Contributor

do not we need to handle error during logout phase in the same function?

I'm not sure I don't understand - what exactly do you mean?

mhalbritter pushed a commit that referenced this pull request Jul 3, 2024
mhalbritter added a commit that referenced this pull request Jul 3, 2024
@mhalbritter
Copy link
Contributor

mhalbritter commented Jul 3, 2024

I merged the PR - thank you very much and congratulations on your first contribution 🎉!

@mhalbritter mhalbritter modified the milestones: 3.4.x, 3.4.0-M1 Jul 3, 2024
@Chu3laMan
Copy link
Contributor Author

do not we need to handle error during logout phase in the same function?

I'm not sure I don't understand - what exactly do you mean?

I mean during the logout session, if an error occurred, don't we need to handle it via a custom event?

@Chu3laMan
Copy link
Contributor Author

I merged the PR - thank you very much and congratulations on your first contribution 🎉!

I really appreciate it, Thank you @philwebb , @wilkinsona, and @mhalbritter

@mhalbritter
Copy link
Contributor

do not we need to handle error during logout phase in the same function?

I'm not sure I don't understand - what exactly do you mean?

I mean during the logout session, if an error occurred, don't we need to handle it via a custom event?

This is all handled by Spring Security. This component in Boot only translates the Spring Security Events into audit events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants