Delete api keys when user is deleted

This commit is contained in:
René Pfeuffer
2020-10-01 18:20:34 +02:00
parent 95bad28b0a
commit a6814fb938
2 changed files with 24 additions and 0 deletions

View File

@@ -24,6 +24,7 @@
package sonia.scm.security;
import com.github.legman.Subscribe;
import com.google.common.util.concurrent.Striped;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -31,8 +32,10 @@ import org.apache.shiro.authc.credential.PasswordService;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.util.ThreadContext;
import sonia.scm.ContextEntry;
import sonia.scm.HandlerEventType;
import sonia.scm.store.DataStore;
import sonia.scm.store.DataStoreFactory;
import sonia.scm.user.UserEvent;
import sonia.scm.user.UserPermissions;
import javax.inject.Inject;
@@ -176,6 +179,13 @@ public class ApiKeyService {
.anyMatch(key -> key.getDisplayName().equals(name));
}
@Subscribe
public void cleanupForDeletedUser(UserEvent userEvent) {
if (userEvent.getEventType() == HandlerEventType.DELETE) {
store.remove(userEvent.getItem().getId());
}
}
@Getter
@AllArgsConstructor
public static class CreationResult {