Skip to content
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

fix: delete all entities linked to a domain when the domain is deleted #1620

Draft
wants to merge 1 commit into
base: 3.10.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ protected void doStop() throws Exception {

logger.info("Dispose event listener for flow events for domain {}", domain.getName());
eventManager.unsubscribeForEvents(this, FlowEvent.class, domain.getId());

Set<String> flowIds = new HashSet(flows.keySet());
flowIds.forEach(id -> removeFlow(id));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

Expand Down Expand Up @@ -107,6 +104,9 @@ protected void doStop() throws Exception {

LOGGER.info("Dispose event listener for bot detection events for domain {}", domain.getName());
eventManager.unsubscribeForEvents(this, BotDetectionEvent.class, domain.getId());

Set<String> botIds = new HashSet<>(this.botDetections.keySet());
botIds.forEach(this::removeBotDetection);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ private void stopComponents() {
components.add(CrossDomainManager.class);
components.add(ClientManager.class);
components.add(CertificateManager.class);
components.add(FlowManager.class);

components.forEach(componentClass -> {
LifecycleComponent lifecyclecomponent = applicationContext.getBean(componentClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.gravitee.am.model.common.Page;
import io.gravitee.am.model.uma.policy.AccessPolicy;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;

Expand All @@ -30,6 +31,7 @@
public interface AccessPolicyRepository extends CrudRepository<AccessPolicy, String> {

Single<Page<AccessPolicy>> findByDomain(String domain, int page, int size);
Completable deleteByDomain(String domain);
Flowable<AccessPolicy> findByDomainAndResource(String domain, String resource);
Flowable<AccessPolicy> findByResources(List<String> resources);
Single<Long> countByResource(String resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public interface AlertNotifierRepository extends CrudRepository<AlertNotifier, S
*/
Flowable<AlertNotifier> findAll(ReferenceType referenceType, String referenceId);

Completable deleteByReference(ReferenceType referenceType, String referenceId);

/**
* Find all the alert notifier attached to the specified reference and matching the specified criteria.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.gravitee.am.model.alert.AlertTrigger;
import io.gravitee.am.repository.common.CrudRepository;
import io.gravitee.am.repository.management.api.search.AlertTriggerCriteria;
import io.reactivex.Completable;
import io.reactivex.Flowable;

/**
Expand All @@ -36,6 +37,8 @@ public interface AlertTriggerRepository extends CrudRepository<AlertTrigger, Str
*/
Flowable<AlertTrigger> findAll(ReferenceType referenceType, String referenceId);

Completable deleteByReference(ReferenceType referenceType, String referenceId);

/**
* Find all alert triggers for a given reference type and id and matching specified criteria.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.gravitee.am.model.BotDetection;
import io.gravitee.am.model.ReferenceType;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;

Expand All @@ -33,4 +34,6 @@ public interface BotDetectionRepository extends CrudRepository<BotDetection, Str

Flowable<BotDetection> findByReference(ReferenceType referenceType, String referenceId);

Completable deleteByReference(ReferenceType referenceType, String referenceId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.gravitee.am.model.Certificate;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;

Expand All @@ -31,4 +32,6 @@ public interface CertificateRepository extends CrudRepository<Certificate, Strin
Flowable<Certificate> findAll();

Flowable<Certificate> findByDomain(String domain);

Completable deleteByDomain(String domain);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.gravitee.am.model.common.Page;
import io.gravitee.am.repository.common.CrudRepository;
import io.gravitee.am.repository.management.api.search.FilterCriteria;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;
Expand Down Expand Up @@ -48,4 +49,5 @@ public interface CommonUserRepository extends CrudRepository<User, String> {

Maybe<User> findById(ReferenceType referenceType, String referenceId, String userId);

Completable deleteByReference(ReferenceType referenceType, String referenceId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.gravitee.am.model.Email;
import io.gravitee.am.model.ReferenceType;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;
Expand Down Expand Up @@ -45,4 +46,6 @@ public interface EmailRepository extends CrudRepository<Email, String> {
Maybe<Email> findByDomainAndClientAndTemplate(String domain, String client, String template);

Maybe<Email> findById(ReferenceType referenceType, String referenceId, String id);

Completable deleteByReference(ReferenceType referenceType, String referenceId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.gravitee.am.model.ExtensionGrant;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;
Expand All @@ -31,5 +32,7 @@ public interface ExtensionGrantRepository extends CrudRepository<ExtensionGrant,

Flowable<ExtensionGrant> findByDomain(String domain);

Completable deleteByDomain(String domain);

Maybe<ExtensionGrant> findByDomainAndName(String domain, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.gravitee.am.model.Factor;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;

Expand All @@ -32,4 +33,6 @@ public interface FactorRepository extends CrudRepository<Factor, String> {

Flowable<Factor> findByDomain(String domain);

Completable deleteByDomain(String domain);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.gravitee.am.model.flow.Flow;
import io.gravitee.am.model.flow.Type;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;
Expand All @@ -35,5 +36,7 @@ public interface FlowRepository extends CrudRepository<Flow, String> {

Flowable<Flow> findAll(ReferenceType referenceType, String referenceId);

Completable deleteByReference(ReferenceType referenceType, String referenceId);

Flowable<Flow> findByApplication(ReferenceType referenceType, String referenceId, String application);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.gravitee.am.model.Form;
import io.gravitee.am.model.ReferenceType;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;
Expand All @@ -32,6 +33,8 @@ public interface FormRepository extends CrudRepository<Form, String> {

Flowable<Form> findAll(ReferenceType referenceType, String referenceId);

Completable deleteByReference(ReferenceType referenceType, String referenceId);

Flowable<Form> findAll(ReferenceType referenceType);

Flowable<Form> findByClient(ReferenceType referenceType, String referenceId, String client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.gravitee.am.model.ReferenceType;
import io.gravitee.am.model.common.Page;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;
Expand All @@ -35,6 +36,8 @@ public interface GroupRepository extends CrudRepository<Group, String> {

Flowable<Group> findAll(ReferenceType referenceType, String referenceId);

Completable deleteByReference(ReferenceType referenceType, String referenceId);

Single<Page<Group>> findAll(ReferenceType referenceType, String referenceId, int page, int size);

Flowable<Group> findByIdIn(List<String> ids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.gravitee.am.model.IdentityProvider;
import io.gravitee.am.model.ReferenceType;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;
Expand All @@ -32,6 +33,8 @@ public interface IdentityProviderRepository extends CrudRepository<IdentityProvi

Flowable<IdentityProvider> findAll(ReferenceType referenceType, String referenceId);

Completable deleteByReference(ReferenceType referenceType, String referenceId);

Flowable<IdentityProvider> findAll(ReferenceType referenceType);

Flowable<IdentityProvider> findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.gravitee.am.model.membership.MemberType;
import io.gravitee.am.repository.common.CrudRepository;
import io.gravitee.am.repository.management.api.search.MembershipCriteria;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;
Expand All @@ -34,6 +35,8 @@ public interface MembershipRepository extends CrudRepository<Membership, String>

Flowable<Membership> findByReference(String referenceId, ReferenceType referenceType);

Completable deleteByReference(ReferenceType referenceType, String referenceId);

Flowable<Membership> findByMember(String memberId, MemberType memberType);

Flowable<Membership> findByCriteria(ReferenceType referenceType, String referenceId, MembershipCriteria criteria);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

import io.gravitee.am.model.Reporter;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;

import java.util.List;

/**
* @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com)
Expand All @@ -31,4 +29,6 @@ public interface ReporterRepository extends CrudRepository<Reporter, String> {
Flowable<Reporter> findAll();

Flowable<Reporter> findByDomain(String domain);

Completable deleteByDomain(String domain);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.gravitee.am.model.Role;
import io.gravitee.am.model.common.Page;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;
Expand All @@ -34,6 +35,8 @@ public interface RoleRepository extends CrudRepository<Role, String> {

Flowable<Role> findAll(ReferenceType referenceType, String referenceId);

Completable deleteByReference(ReferenceType referenceType, String referenceId);

Single<Page<Role>> findAll(ReferenceType referenceType, String referenceId, int page, int size);

Single<Page<Role>> search(ReferenceType referenceType, String referenceId, String query, int page, int size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.gravitee.am.model.common.Page;
import io.gravitee.am.model.oauth2.Scope;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;
Expand All @@ -33,6 +34,8 @@ public interface ScopeRepository extends CrudRepository<Scope, String> {

Single<Page<Scope>> findByDomain(String domain, int page, int size);

Completable deleteByDomain(String domain);

Single<Page<Scope>> search(String domain, String query, int page, int size);

Maybe<Scope> findByDomainAndKey(String domain, String key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.gravitee.am.model.ReferenceType;
import io.gravitee.am.model.resource.ServiceResource;
import io.gravitee.am.repository.common.CrudRepository;
import io.reactivex.Completable;
import io.reactivex.Flowable;

/**
Expand All @@ -28,4 +29,6 @@ public interface ServiceResourceRepository extends CrudRepository<ServiceResourc

Flowable<ServiceResource> findByReference(ReferenceType referenceType, String referenceId);

Completable deleteByReference(ReferenceType referenceType, String referenceId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
import io.gravitee.am.model.User;
import io.gravitee.am.model.analytics.AnalyticsQuery;
import io.gravitee.am.model.common.Page;
import io.gravitee.am.repository.common.CrudRepository;
import io.gravitee.am.repository.management.api.search.FilterCriteria;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com)
Expand Down Expand Up @@ -60,4 +58,5 @@ public interface UserRepository extends CommonUserRepository {
Single<Long> countByApplication(String domain, String application);

Single<Map<Object, Object>> statistics(AnalyticsQuery query);

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public interface ScopeApprovalRepository extends CrudRepository<ScopeApproval, S

Completable deleteByDomainAndUser(String domain, String user);

Completable deleteByDomain(String domain);

default Completable purgeExpiredData() {
return Completable.complete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@

import static org.springframework.data.relational.core.query.Criteria.where;
import static org.springframework.data.relational.core.query.CriteriaDefinition.from;
import static reactor.adapter.rxjava.RxJava2Adapter.fluxToFlowable;
import static reactor.adapter.rxjava.RxJava2Adapter.monoToSingle;
import static reactor.adapter.rxjava.RxJava2Adapter.*;

/**
* @author Eric LELEU (eric.leleu at graviteesource.com)
Expand Down Expand Up @@ -156,4 +155,10 @@ public Completable delete(String id) {
LOGGER.debug("delete AccessPolicy with id {}", id);
return accessPolicyRepository.deleteById(id);
}

@Override
public Completable deleteByDomain(String domain) {
LOGGER.debug("delete AccessPolicy with domain {}", domain);
return monoToCompletable(dbClient.delete().from(JdbcAccessPolicy.class).matching(from(where("domain").is(domain))).fetch().rowsUpdated());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ public Completable delete(String id) {
return this.alertNotifierRepository.deleteById(id);
}

@Override
public Completable deleteByReference(ReferenceType referenceType, String referenceId) {
LOGGER.debug("deleteByReference({}, {})", referenceType, referenceId);
return monoToCompletable(dbClient.delete().from(JdbcAlertNotifier.class)
.matching(from(where("reference_type").is(referenceType.name())
.and(where("reference_id").is(referenceId))))
.fetch().rowsUpdated());
}

@Override
public Flowable<AlertNotifier> findAll(ReferenceType referenceType, String referenceId) {
return findByCriteria(referenceType, referenceId, new AlertNotifierCriteria());
Expand Down
Loading