Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring
This commit is contained in:
commit
f82501344c
|
@ -20,14 +20,16 @@ public class AffiliationCacheService extends CacheService<AffiliationCacheServic
|
||||||
public AffiliationCacheValue() {
|
public AffiliationCacheValue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AffiliationCacheValue(UUID userId, UUID entityId, String entityType, AffiliatedResource affiliatedResource) {
|
public AffiliationCacheValue(UUID tenantId, UUID userId, UUID entityId, String entityType, AffiliatedResource affiliatedResource) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
|
this.tenantId = tenantId;
|
||||||
this.entityId = entityId;
|
this.entityId = entityId;
|
||||||
this.entityType = entityType;
|
this.entityType = entityType;
|
||||||
this.affiliatedResource = affiliatedResource;
|
this.affiliatedResource = affiliatedResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private UUID userId;
|
private UUID userId;
|
||||||
|
private UUID tenantId;
|
||||||
private UUID entityId;
|
private UUID entityId;
|
||||||
private String entityType;
|
private String entityType;
|
||||||
private AffiliatedResource affiliatedResource;
|
private AffiliatedResource affiliatedResource;
|
||||||
|
@ -40,6 +42,14 @@ public class AffiliationCacheService extends CacheService<AffiliationCacheServic
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UUID getTenantId() {
|
||||||
|
return tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantId(UUID tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
public UUID getEntityId() {
|
public UUID getEntityId() {
|
||||||
return entityId;
|
return entityId;
|
||||||
}
|
}
|
||||||
|
@ -79,17 +89,18 @@ public class AffiliationCacheService extends CacheService<AffiliationCacheServic
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String keyOf(AffiliationCacheValue value) {
|
public String keyOf(AffiliationCacheValue value) {
|
||||||
return this.buildKey(value.getUserId(), value.getEntityId(), value.getEntityType());
|
return this.buildKey(value.getTenantId(), value.getUserId(), value.getEntityId(), value.getEntityType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String buildKey(UUID userId, UUID entityId, String entityType) {
|
public String buildKey(UUID tenantId, UUID userId, UUID entityId, String entityType) {
|
||||||
if (userId == null) throw new IllegalArgumentException("userId id is required");
|
if (userId == null) throw new IllegalArgumentException("userId id is required");
|
||||||
if (entityId == null) throw new IllegalArgumentException("entityId id is required");
|
if (entityId == null) throw new IllegalArgumentException("entityId id is required");
|
||||||
if (this.conventionService.isNullOrEmpty(entityType)) throw new IllegalArgumentException("entityType id is required");
|
if (this.conventionService.isNullOrEmpty(entityType)) throw new IllegalArgumentException("entityType id is required");
|
||||||
|
|
||||||
HashMap<String, String> keyParts = new HashMap<>();
|
HashMap<String, String> keyParts = new HashMap<>();
|
||||||
keyParts.put("$user$", userId.toString().replace("-", "").toLowerCase(Locale.ROOT));
|
keyParts.put("$user$", userId.toString().replace("-", "").toLowerCase(Locale.ROOT));
|
||||||
|
keyParts.put("$tenant$", tenantId == null ? "" : userId.toString().replace("-", "").toLowerCase(Locale.ROOT));
|
||||||
keyParts.put("$entity$", entityId.toString().replace("-", "").toLowerCase(Locale.ROOT));
|
keyParts.put("$entity$", entityId.toString().replace("-", "").toLowerCase(Locale.ROOT));
|
||||||
keyParts.put("$type$", entityType);
|
keyParts.put("$type$", entityType);
|
||||||
return this.generateKey(keyParts);
|
return this.generateKey(keyParts);
|
||||||
|
|
|
@ -3,6 +3,7 @@ package eu.eudat.authorization.authorizationcontentresolver;
|
||||||
import eu.eudat.authorization.AffiliatedResource;
|
import eu.eudat.authorization.AffiliatedResource;
|
||||||
import eu.eudat.authorization.PermissionNameProvider;
|
import eu.eudat.authorization.PermissionNameProvider;
|
||||||
import eu.eudat.commons.enums.IsActive;
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.commons.scope.tenant.TenantScope;
|
||||||
import eu.eudat.commons.scope.user.UserScope;
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
||||||
|
@ -19,6 +20,7 @@ import gr.cite.tools.fieldset.BaseFieldSet;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.context.annotation.RequestScope;
|
import org.springframework.web.context.annotation.RequestScope;
|
||||||
|
|
||||||
|
import javax.management.InvalidApplicationException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -27,11 +29,13 @@ import java.util.stream.Collectors;
|
||||||
public class AuthorizationContentResolverImpl implements AuthorizationContentResolver {
|
public class AuthorizationContentResolverImpl implements AuthorizationContentResolver {
|
||||||
private final QueryFactory queryFactory;
|
private final QueryFactory queryFactory;
|
||||||
private final UserScope userScope;
|
private final UserScope userScope;
|
||||||
|
private final TenantScope tenantScope;
|
||||||
private final AffiliationCacheService affiliationCacheService;
|
private final AffiliationCacheService affiliationCacheService;
|
||||||
private final PermissionNameProvider permissionNameProvider;
|
private final PermissionNameProvider permissionNameProvider;
|
||||||
public AuthorizationContentResolverImpl(QueryFactory queryFactory, UserScope userScope, AffiliationCacheService affiliationCacheService, PermissionNameProvider permissionNameProvider) {
|
public AuthorizationContentResolverImpl(QueryFactory queryFactory, UserScope userScope, TenantScope tenantScope, AffiliationCacheService affiliationCacheService, PermissionNameProvider permissionNameProvider) {
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
this.userScope = userScope;
|
this.userScope = userScope;
|
||||||
|
this.tenantScope = tenantScope;
|
||||||
this.affiliationCacheService = affiliationCacheService;
|
this.affiliationCacheService = affiliationCacheService;
|
||||||
this.permissionNameProvider = permissionNameProvider;
|
this.permissionNameProvider = permissionNameProvider;
|
||||||
}
|
}
|
||||||
|
@ -138,21 +142,31 @@ public class AuthorizationContentResolverImpl implements AuthorizationContentRes
|
||||||
return affiliatedResources;
|
return affiliatedResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<UUID> getAffiliatedFromCache(List<UUID> ids, UUID userId, Map<UUID, AffiliatedResource> affiliatedResources, String entityType){
|
private List<UUID> getAffiliatedFromCache(List<UUID> ids, UUID userId, Map<UUID, AffiliatedResource> affiliatedResources, String entityType) {
|
||||||
List<UUID> idsToResolve = new ArrayList<>();
|
List<UUID> idsToResolve = new ArrayList<>();
|
||||||
for (UUID id : ids){
|
for (UUID id : ids){
|
||||||
AffiliationCacheService.AffiliationCacheValue cacheValue = this.affiliationCacheService.lookup(this.affiliationCacheService.buildKey(userId, id, entityType));
|
AffiliationCacheService.AffiliationCacheValue cacheValue = null;
|
||||||
|
try {
|
||||||
|
cacheValue = this.affiliationCacheService.lookup(this.affiliationCacheService.buildKey(this.tenantScope.isSet() ? this.tenantScope.getTenant(): null, userId, id, entityType));
|
||||||
|
} catch (InvalidApplicationException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
if (cacheValue != null) affiliatedResources.put(id, cacheValue.getAffiliatedResource());
|
if (cacheValue != null) affiliatedResources.put(id, cacheValue.getAffiliatedResource());
|
||||||
else idsToResolve.add(id);
|
else idsToResolve.add(id);
|
||||||
}
|
}
|
||||||
return idsToResolve;
|
return idsToResolve;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureAffiliatedInCache(List<UUID> idsToResolve, UUID userId, Map<UUID, AffiliatedResource> affiliatedResources, String entityType){
|
private void ensureAffiliatedInCache(List<UUID> idsToResolve, UUID userId, Map<UUID, AffiliatedResource> affiliatedResources, String entityType) {
|
||||||
for (UUID id : idsToResolve){
|
for (UUID id : idsToResolve){
|
||||||
AffiliatedResource affiliatedResource = affiliatedResources.getOrDefault(id, null);
|
AffiliatedResource affiliatedResource = affiliatedResources.getOrDefault(id, null);
|
||||||
if (affiliatedResource != null) {
|
if (affiliatedResource != null) {
|
||||||
AffiliationCacheService.AffiliationCacheValue cacheValue = new AffiliationCacheService.AffiliationCacheValue(userId, id, entityType, affiliatedResource);
|
AffiliationCacheService.AffiliationCacheValue cacheValue = null;
|
||||||
|
try {
|
||||||
|
cacheValue = new AffiliationCacheService.AffiliationCacheValue(this.tenantScope.isSet() ? this.tenantScope.getTenant(): null, userId, id, entityType, affiliatedResource);
|
||||||
|
} catch (InvalidApplicationException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
this.affiliationCacheService.put(cacheValue);
|
this.affiliationCacheService.put(cacheValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,4 +110,4 @@ cache:
|
||||||
keyPattern: resolve_$keyhash$:v0
|
keyPattern: resolve_$keyhash$:v0
|
||||||
affiliation:
|
affiliation:
|
||||||
name: affiliation
|
name: affiliation
|
||||||
keyPattern: affiliation_$entity$_$user$_$type$:v0
|
keyPattern: affiliation_$entity$_$user$_$tenant$_$type$:v0
|
|
@ -10,11 +10,12 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>3.1.2</version>
|
<version>3.2.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>queryable</module>
|
<module>queryable</module>
|
||||||
|
<module>../dmp-backend/core</module>
|
||||||
<module>web</module>
|
<module>web</module>
|
||||||
<module>data</module>
|
<module>data</module>
|
||||||
<module>elastic</module>
|
<module>elastic</module>
|
||||||
|
@ -301,16 +302,26 @@
|
||||||
<groupId>io.micrometer</groupId>
|
<groupId>io.micrometer</groupId>
|
||||||
<artifactId>micrometer-core</artifactId>
|
<artifactId>micrometer-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jboss</groupId>
|
||||||
|
<artifactId>jandex</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!--CITE DEPENDENCIES-->
|
<!--CITE DEPENDENCIES-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>gr.cite</groupId>
|
<groupId>gr.cite</groupId>
|
||||||
<artifactId>data-tools</artifactId>
|
<artifactId>data-tools</artifactId>
|
||||||
<version>2.1.0</version>
|
<version>2.1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>gr.cite</groupId>
|
<groupId>gr.cite</groupId>
|
||||||
<artifactId>exceptions</artifactId>
|
<artifactId>exceptions</artifactId>
|
||||||
|
<version>2.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>gr.cite</groupId>
|
||||||
|
<artifactId>oidc-authz</artifactId>
|
||||||
<version>2.1.0</version>
|
<version>2.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
|
@ -387,7 +387,8 @@ public class RemoteFetcher {
|
||||||
JsonNode jsonBody = new ObjectMapper().readTree(replacedBody);
|
JsonNode jsonBody = new ObjectMapper().readTree(replacedBody);
|
||||||
entity = new HttpEntity<>(jsonBody, headers);
|
entity = new HttpEntity<>(jsonBody, headers);
|
||||||
|
|
||||||
response = restTemplate.exchange(replacedPath, HttpMethod.resolve(requestType), entity, String.class);
|
// response = restTemplate.exchange(replacedPath, HttpMethod.resolve(requestType), entity, String.class);
|
||||||
|
response = null;
|
||||||
if (response.getStatusCode() == HttpStatus.OK) {
|
if (response.getStatusCode() == HttpStatus.OK) {
|
||||||
if (response.getHeaders().get("Content-Type").get(0).contains("json")) {
|
if (response.getHeaders().get("Content-Type").get(0).contains("json")) {
|
||||||
DocumentContext jsonContext = JsonPath.parse(response.getBody());
|
DocumentContext jsonContext = JsonPath.parse(response.getBody());
|
||||||
|
@ -423,7 +424,8 @@ public class RemoteFetcher {
|
||||||
JsonNode jsonBody = new ObjectMapper().readTree(requestBody);
|
JsonNode jsonBody = new ObjectMapper().readTree(requestBody);
|
||||||
entity = new HttpEntity<>(jsonBody, headers);
|
entity = new HttpEntity<>(jsonBody, headers);
|
||||||
|
|
||||||
response = restTemplate.exchange(urlString, HttpMethod.resolve(requestType), entity, String.class);
|
// response = restTemplate.exchange(urlString, HttpMethod.resolve(requestType), entity, String.class);
|
||||||
|
response = null;
|
||||||
if (response.getStatusCode() == HttpStatus.OK) { // success
|
if (response.getStatusCode() == HttpStatus.OK) { // success
|
||||||
//do here all the parsing
|
//do here all the parsing
|
||||||
Results results = new Results();
|
Results results = new Results();
|
||||||
|
|
|
@ -25,6 +25,7 @@ import gr.cite.tools.data.query.QueryFactory;
|
||||||
import gr.cite.tools.exception.MyApplicationException;
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.ws.rs.NotSupportedException;
|
||||||
import jakarta.xml.bind.JAXBException;
|
import jakarta.xml.bind.JAXBException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -34,7 +35,6 @@ import org.w3c.dom.Document;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
import javax.management.InvalidApplicationException;
|
||||||
import javax.ws.rs.NotSupportedException;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
Loading…
Reference in New Issue