Removing the aspect and trying to implement the application repository directly
This commit is contained in:
parent
29ae5fd360
commit
5b09427b6c
|
|
@ -27,8 +27,8 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
//@Aspect
|
||||
//@Component
|
||||
@Slf4j
|
||||
public class AclAspect {
|
||||
|
||||
|
|
|
|||
|
|
@ -90,17 +90,17 @@ public class SoftDeleteMongoQueryLookupStrategy implements QueryLookupStrategy {
|
|||
|
||||
@Override
|
||||
protected Query createQuery(ConvertingParameterAccessor accessor) {
|
||||
SecurityContext securityContext = SecurityContextHolder.getContext();
|
||||
// User userPrincipal = (User) ReactiveSecurityContextHolder.getContext()
|
||||
// .switchIfEmpty(Mono.error(new Exception("no context")))
|
||||
// .map(ctx -> ctx.getAuthentication())
|
||||
// .map(auth -> auth.getPrincipal())
|
||||
// .map(principal -> {
|
||||
// if (principal instanceof User) {
|
||||
// return (User) principal;
|
||||
// }
|
||||
// return new User();
|
||||
// }).block();
|
||||
// SecurityContext securityContext = SecurityContextHolder.getContext();
|
||||
User userPrincipal = ReactiveSecurityContextHolder.getContext()
|
||||
.switchIfEmpty(Mono.error(new Exception("no context")))
|
||||
.map(ctx -> ctx.getAuthentication())
|
||||
.map(auth -> auth.getPrincipal())
|
||||
.map(principal -> {
|
||||
if (principal instanceof User) {
|
||||
return (User) principal;
|
||||
}
|
||||
return new User();
|
||||
}).block();
|
||||
AclPermission aclPermission = method.getAnnotation(AclPermission.class);
|
||||
if (aclPermission != null) {
|
||||
log.debug("Got principal: {}", aclPermission.principal());
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.appsmith.server.services.ApplicationService;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
|
|
|||
|
|
@ -3,23 +3,32 @@ package com.appsmith.server.repositories;
|
|||
import com.appsmith.server.domains.Application;
|
||||
import com.appsmith.server.services.AclEntity;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Repository
|
||||
@NoRepositoryBean
|
||||
@AclEntity("applications")
|
||||
public interface ApplicationRepository extends BaseRepository<Application, String> {
|
||||
|
||||
default Mono<Application> findByIdAndOrganizationId(String id, String orgId){
|
||||
default Mono<Application> findByIdAndOrganizationId(String id, String orgId) {
|
||||
System.out.println("In the custom implementation");
|
||||
return Mono.empty();
|
||||
return ReactiveSecurityContextHolder.getContext()
|
||||
.map(ctx -> ctx.getAuthentication())
|
||||
.map(auth -> auth.getPrincipal())
|
||||
.flatMap(principal -> {
|
||||
System.out.println("Got principal: " + principal);
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
Mono<Application> findByName(String name);
|
||||
|
||||
@Override
|
||||
Flux<Application> findAll(Example example);
|
||||
// @Override
|
||||
// Flux<Application> findAll(Example example);
|
||||
|
||||
@Override
|
||||
Mono<Application> findById(String id);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package com.appsmith.server.repositories;
|
||||
|
||||
import com.appsmith.server.domains.Application;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import static org.springframework.data.mongodb.core.query.Criteria.where;
|
||||
|
||||
@Component
|
||||
public class ApplicationRepositoryImpl extends BaseRepositoryImpl<Application, String> implements ApplicationRepository {
|
||||
|
||||
@Autowired
|
||||
public ApplicationRepositoryImpl(@NonNull MongoEntityInformation<Application, String> entityInformation,
|
||||
@NonNull ReactiveMongoOperations mongoOperations) {
|
||||
super(entityInformation, mongoOperations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Application> findByName(String name) {
|
||||
Query query = new Query();
|
||||
query.addCriteria(notDeleted());
|
||||
|
||||
Annotation[] annotations = entityInformation.getJavaType().getAnnotations();
|
||||
return mongoOperations.query(entityInformation.getJavaType())
|
||||
.inCollection(entityInformation.getCollectionName())
|
||||
.matching(query)
|
||||
.one();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Application> findAll(Example example) {
|
||||
Query query = new Query(notDeleted());
|
||||
Annotation[] annotations = entityInformation.getJavaType().getAnnotations();
|
||||
return mongoOperations.find(query, entityInformation.getJavaType(), entityInformation.getCollectionName());
|
||||
}
|
||||
}
|
||||
|
|
@ -38,8 +38,8 @@ import static org.springframework.data.mongodb.core.query.Criteria.where;
|
|||
public class BaseRepositoryImpl<T extends BaseDomain, ID extends Serializable> extends SimpleReactiveMongoRepository<T, ID>
|
||||
implements BaseRepository<T, ID> {
|
||||
|
||||
private final MongoEntityInformation<T, ID> entityInformation;
|
||||
private final ReactiveMongoOperations mongoOperations;
|
||||
protected final MongoEntityInformation<T, ID> entityInformation;
|
||||
protected final ReactiveMongoOperations mongoOperations;
|
||||
|
||||
public BaseRepositoryImpl(@NonNull MongoEntityInformation<T, ID> entityInformation,
|
||||
@NonNull ReactiveMongoOperations mongoOperations) {
|
||||
|
|
@ -48,14 +48,14 @@ public class BaseRepositoryImpl<T extends BaseDomain, ID extends Serializable> e
|
|||
this.mongoOperations = mongoOperations;
|
||||
}
|
||||
|
||||
private Criteria notDeleted() {
|
||||
protected Criteria notDeleted() {
|
||||
return new Criteria().orOperator(
|
||||
where("deleted").exists(false),
|
||||
where("deleted").is(false)
|
||||
);
|
||||
}
|
||||
|
||||
private Criteria getIdCriteria(Object id) {
|
||||
protected Criteria getIdCriteria(Object id) {
|
||||
return where(entityInformation.getIdAttribute()).is(id);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user