Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring
Conflicts: dmp-frontend/src/assets/config/config.json
This commit is contained in:
commit
3dee4857f8
|
@ -46,5 +46,6 @@ ELK.Docker/shared/data-elk/
|
||||||
.settings/
|
.settings/
|
||||||
bin/
|
bin/
|
||||||
*.classpath
|
*.classpath
|
||||||
|
.run
|
||||||
openDMP/dmp-backend/uploads/
|
openDMP/dmp-backend/uploads/
|
||||||
openDMP/dmp-backend/tmp/
|
openDMP/dmp-backend/tmp/
|
||||||
|
|
|
@ -27,6 +27,28 @@
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>dmp-backend</groupId>
|
||||||
|
<artifactId>queryable</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>gr.cite</groupId>
|
||||||
|
<artifactId>validation</artifactId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>gr.cite</groupId>
|
||||||
|
<artifactId>oidc-authz</artifactId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
|
@ -5,9 +5,8 @@ import gr.cite.tools.logging.EventId;
|
||||||
public class AuditableAction {
|
public class AuditableAction {
|
||||||
|
|
||||||
public static final EventId DescriptionTemplateType_Query = new EventId(1000, "DescriptionTemplateType_Query");
|
public static final EventId DescriptionTemplateType_Query = new EventId(1000, "DescriptionTemplateType_Query");
|
||||||
|
public static final EventId DescriptionTemplateType_Lookup = new EventId(1001, "DescriptionTemplateType_Lookup");
|
||||||
public static final EventId DescriptionTemplateType_Persist = new EventId(1001, "DescriptionTemplateType_Persist");
|
public static final EventId DescriptionTemplateType_Persist = new EventId(1002, "DescriptionTemplateType_Persist");
|
||||||
|
public static final EventId DescriptionTemplateType_Delete = new EventId(1003, "DescriptionTemplateType_Delete");
|
||||||
public static final EventId DescriptionTemplateType_Delete = new EventId(1002, "DescriptionTemplateType_Delete");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package eu.eudat.authorization;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
public enum AuthorizationFlags {
|
||||||
|
None, Permission, Owner;
|
||||||
|
public static final EnumSet<AuthorizationFlags> OwnerOrPermission = EnumSet.of(Owner, Permission);
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package eu.eudat.authorization;
|
||||||
|
|
||||||
|
import gr.cite.commons.web.authz.policy.AuthorizationRequirement;
|
||||||
|
|
||||||
|
public class OwnedAuthorizationRequirement implements AuthorizationRequirement {
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package eu.eudat.authorization;
|
||||||
|
|
||||||
|
import gr.cite.commons.web.authz.policy.AuthorizationResource;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class OwnedResource extends AuthorizationResource {
|
||||||
|
private List<UUID> userIds;
|
||||||
|
|
||||||
|
public OwnedResource(UUID userId) {
|
||||||
|
this(List.of(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public OwnedResource(List<UUID> userIds) {
|
||||||
|
this.userIds = userIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getUserIds() {
|
||||||
|
return userIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserIds(List<UUID> userIds) {
|
||||||
|
this.userIds = userIds;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package eu.eudat.authorization;
|
||||||
|
|
||||||
|
public final class Permission {
|
||||||
|
|
||||||
|
//DescriptionTemplateType
|
||||||
|
public static String BrowseDescriptionTemplateType = "BrowseDescriptionTemplateType";
|
||||||
|
public static String EditDescriptionTemplateType = "EditDescriptionTemplateType";
|
||||||
|
public static String DeleteDescriptionTemplateType = "DeleteDescriptionTemplateType";
|
||||||
|
|
||||||
|
// UI Pages
|
||||||
|
public static String ViewDescriptionTemplateTypePage = "ViewDescriptionTemplateTypePage";
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package eu.eudat.commons;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
|
||||||
|
public class JsonHandlingService {
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
public JsonHandlingService() {
|
||||||
|
this.objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.registerModule(new JavaTimeModule());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJson(Object item) throws JsonProcessingException {
|
||||||
|
if (item == null) return null;
|
||||||
|
return objectMapper.writeValueAsString(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJsonSafe(Object item) {
|
||||||
|
if (item == null) return null;
|
||||||
|
try {
|
||||||
|
return objectMapper.writeValueAsString(item);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T fromJson(Class<T> type, String json) throws JsonProcessingException {
|
||||||
|
if (json == null) return null;
|
||||||
|
return objectMapper.readValue(json, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T fromJsonSafe(Class<T> type, String json) {
|
||||||
|
if (json == null) return null;
|
||||||
|
try {
|
||||||
|
return objectMapper.readValue(json, type);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,43 +1,28 @@
|
||||||
package eu.eudat.commons.enums;
|
package eu.eudat.commons.enums;
|
||||||
|
|
||||||
public enum DescriptionTemplateTypeStatus {
|
import eu.eudat.data.converters.enums.DatabaseEnum;
|
||||||
|
|
||||||
SAVED((short) 0), FINALIZED((short) 1), DELETED((short) 99);
|
import java.util.Map;
|
||||||
|
|
||||||
private final short value;
|
public enum DescriptionTemplateTypeStatus implements DatabaseEnum<Short> {
|
||||||
|
|
||||||
DescriptionTemplateTypeStatus(short value) {
|
Draft((short) 0),
|
||||||
|
Finalized((short) 1);
|
||||||
|
|
||||||
|
private final Short value;
|
||||||
|
|
||||||
|
DescriptionTemplateTypeStatus(Short value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getValue() {
|
public Short getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DescriptionTemplateTypeStatus fromInteger(int value) {
|
private static final Map<Short, DescriptionTemplateTypeStatus> map = EnumUtils.getEnumValueMap(DescriptionTemplateTypeStatus.class);
|
||||||
switch (value) {
|
|
||||||
case 0:
|
|
||||||
return SAVED;
|
|
||||||
case 1:
|
|
||||||
return FINALIZED;
|
|
||||||
case 99:
|
|
||||||
return DELETED;
|
|
||||||
default:
|
|
||||||
throw new RuntimeException("Unsupported Description Template Type Status");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DescriptionTemplateTypeStatus fromLabel(String value) {
|
public static DescriptionTemplateTypeStatus of(Short i) {
|
||||||
switch (value) {
|
return map.get(i);
|
||||||
case "SAVED":
|
|
||||||
return SAVED;
|
|
||||||
case "FINALISED":
|
|
||||||
return FINALIZED;
|
|
||||||
case "DELETED":
|
|
||||||
return DELETED;
|
|
||||||
default:
|
|
||||||
throw new RuntimeException("Unsupported Description Template Type Status");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package eu.eudat.commons.enums;
|
||||||
|
|
||||||
|
import eu.eudat.data.converters.enums.DatabaseEnum;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class EnumUtils {
|
||||||
|
public static <EnumType extends Enum<EnumType> & DatabaseEnum<EnumValue>, EnumValue> Map<EnumValue, EnumType> getEnumValueMap(Class<EnumType> enumType){
|
||||||
|
HashMap<EnumValue, EnumType> map = new HashMap<>();
|
||||||
|
for (EnumType v : enumType.getEnumConstants()) {
|
||||||
|
map.put(v.getValue(), v);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package eu.eudat.commons.enums;
|
||||||
|
|
||||||
|
import eu.eudat.data.converters.enums.DatabaseEnum;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public enum IsActive implements DatabaseEnum<Short> {
|
||||||
|
|
||||||
|
Inactive((short)0),
|
||||||
|
Active( (short)1);
|
||||||
|
|
||||||
|
private final Short value;
|
||||||
|
|
||||||
|
IsActive(Short value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Short getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Map<Short, IsActive> map = EnumUtils.getEnumValueMap(IsActive.class);
|
||||||
|
|
||||||
|
public static IsActive of(Short i) {
|
||||||
|
return map.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package eu.eudat.commons.enums;
|
||||||
|
|
||||||
|
import eu.eudat.data.converters.enums.DatabaseEnum;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public enum ProviderType implements DatabaseEnum<Integer> {
|
||||||
|
|
||||||
|
Google (1),
|
||||||
|
Facebook ( 2),
|
||||||
|
Twitter ( 3),
|
||||||
|
LinkedIn (4),
|
||||||
|
NativeLogin ( 5),
|
||||||
|
B2Access ( 6),
|
||||||
|
ORCID (7),
|
||||||
|
OpenAire ( 8),
|
||||||
|
Configurable ( 9),
|
||||||
|
Zenodo (10),
|
||||||
|
Keycloack ( 128);
|
||||||
|
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
ProviderType(Integer value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getValue() { return this.value; }
|
||||||
|
|
||||||
|
private static final Map<Integer, ProviderType> map = EnumUtils.getEnumValueMap(ProviderType.class);
|
||||||
|
public static ProviderType of(Integer i) {
|
||||||
|
return map.get(i);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.commons.scope;
|
package eu.eudat.commons.scope.user;
|
||||||
|
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
|
@ -0,0 +1,11 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
|
||||||
|
public class EnumNotNull implements ConstraintValidator<ValidEnum,Object> {
|
||||||
|
@Override
|
||||||
|
public boolean isValid(Object value, ConstraintValidatorContext context) {
|
||||||
|
return value != null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
|
||||||
|
import jakarta.validation.Constraint;
|
||||||
|
import jakarta.validation.Payload;
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
@Constraint( validatedBy = { FieldNotNullIfOtherSetValidator.class } )
|
||||||
|
@Documented
|
||||||
|
@Target( { ElementType.TYPE } )
|
||||||
|
@Retention( RetentionPolicy.RUNTIME )
|
||||||
|
public @interface FieldNotNullIfOtherSet {
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
String notNullField() default "id";
|
||||||
|
String otherSetField() default "hash";
|
||||||
|
String failOn() default "hash";
|
||||||
|
|
||||||
|
String message() default "hash is required if id is set";
|
||||||
|
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeanWrapperImpl;
|
||||||
|
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class FieldNotNullIfOtherSetValidator implements ConstraintValidator<FieldNotNullIfOtherSet, Object> {
|
||||||
|
|
||||||
|
private String notNullField;
|
||||||
|
private String otherSetField;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(FieldNotNullIfOtherSet constraintAnnotation) {
|
||||||
|
this.notNullField = constraintAnnotation.notNullField();
|
||||||
|
this.otherSetField = constraintAnnotation.otherSetField();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(Object entity, ConstraintValidatorContext context) {
|
||||||
|
Object notNullValue = new BeanWrapperImpl(entity)
|
||||||
|
.getPropertyValue(this.notNullField);
|
||||||
|
Object otherSetValue = new BeanWrapperImpl(entity)
|
||||||
|
.getPropertyValue(this.otherSetField);
|
||||||
|
|
||||||
|
boolean hashIsString = Objects.equals(new BeanWrapperImpl(entity)
|
||||||
|
.getPropertyType(this.otherSetField), String.class);
|
||||||
|
|
||||||
|
boolean hashValueEmpty = otherSetValue == null || (hashIsString && ((String)otherSetValue).isBlank());
|
||||||
|
|
||||||
|
if (notNullValue != null && hashValueEmpty) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
import jakarta.validation.Constraint;
|
||||||
|
import jakarta.validation.Payload;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Constraint(validatedBy = FieldsValueMatchValidator.class)
|
||||||
|
@Target({ ElementType.TYPE })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface FieldsValueMatch {
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
String field();
|
||||||
|
String fieldMatch();
|
||||||
|
String failOn();
|
||||||
|
|
||||||
|
String message() default "Fields values don't match!";
|
||||||
|
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
|
||||||
|
@Target({ ElementType.TYPE })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@interface List {
|
||||||
|
FieldsValueMatch[] value();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeanWrapperImpl;
|
||||||
|
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
|
||||||
|
public class FieldsValueMatchValidator implements ConstraintValidator<FieldsValueMatch, Object> {
|
||||||
|
|
||||||
|
private String field;
|
||||||
|
private String fieldMatch;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(FieldsValueMatch constraintAnnotation) {
|
||||||
|
this.field = constraintAnnotation.field();
|
||||||
|
this.fieldMatch = constraintAnnotation.fieldMatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(Object entity, ConstraintValidatorContext context) {
|
||||||
|
|
||||||
|
Object fieldValue = new BeanWrapperImpl(entity).getPropertyValue(field);
|
||||||
|
Object fieldMatchValue = new BeanWrapperImpl(entity).getPropertyValue(fieldMatch);
|
||||||
|
|
||||||
|
if (fieldValue != null) {
|
||||||
|
return fieldValue.equals(fieldMatchValue);
|
||||||
|
} else {
|
||||||
|
return fieldMatchValue == null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
import jakarta.validation.Constraint;
|
||||||
|
import jakarta.validation.Payload;
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
|
||||||
|
@Constraint(validatedBy = EnumNotNull.class)
|
||||||
|
@Documented
|
||||||
|
@Target({ ElementType.FIELD })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface ValidEnum {
|
||||||
|
String message() default "enum is required";
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
|
||||||
|
import jakarta.validation.Constraint;
|
||||||
|
import jakarta.validation.Payload;
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
@Constraint( validatedBy = { ValidIdValidator.class } )
|
||||||
|
@Documented
|
||||||
|
@Target( { ElementType.FIELD } )
|
||||||
|
@Retention( RetentionPolicy.RUNTIME )
|
||||||
|
public @interface ValidId {
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
String message() default "id set but not valid";
|
||||||
|
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
import eu.eudat.convention.ConventionService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ValidIdValidator implements ConstraintValidator<ValidId, Object> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConventionService conventionService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(ValidId constraintAnnotation) { }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
|
||||||
|
if(o == null) return true;
|
||||||
|
else if(o instanceof UUID){
|
||||||
|
UUID uuidId = (UUID)o;
|
||||||
|
return this.conventionService.isValidGuid(uuidId);
|
||||||
|
}
|
||||||
|
else if(o instanceof Integer){
|
||||||
|
Integer intId = (Integer)o;
|
||||||
|
return this.conventionService.isValidId(intId);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
String stringId = o.toString();
|
||||||
|
UUID uuidId = null;
|
||||||
|
try {
|
||||||
|
uuidId = UUID.fromString(stringId);
|
||||||
|
}catch (Exception ex){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.conventionService.isValidGuid(uuidId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,20 +3,17 @@ package eu.eudat.commons.validation;
|
||||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||||
import gr.cite.tools.exception.MyValidationException;
|
import gr.cite.tools.exception.MyValidationException;
|
||||||
import gr.cite.tools.validation.BaseValidationService;
|
import gr.cite.tools.validation.BaseValidationService;
|
||||||
import jakarta.validation.Validator;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
|
||||||
import org.springframework.context.annotation.Scope;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import jakarta.validation.Validator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
||||||
public class ValidationServiceImpl extends BaseValidationService {
|
public class ValidationServiceImpl extends BaseValidationService {
|
||||||
|
|
||||||
private ErrorThesaurusProperties errors;
|
private final ErrorThesaurusProperties errors;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ValidationServiceImpl(Validator validator, ErrorThesaurusProperties errors) {
|
public ValidationServiceImpl(Validator validator, ErrorThesaurusProperties errors) {
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package eu.eudat.data.entities;
|
package eu.eudat.data;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.ProviderType;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
import eu.eudat.data.converters.DateToUTCConverter;
|
import eu.eudat.data.converters.DateToUTCConverter;
|
||||||
import eu.eudat.data.entities.helpers.EntityBinder;
|
|
||||||
import eu.eudat.queryable.queryableentity.DataEntity;
|
|
||||||
|
|
||||||
|
import eu.eudat.data.converters.enums.ProviderTypeConverter;
|
||||||
|
import eu.eudat.data.converters.enums.IsActiveConverter;
|
||||||
|
import eu.eudat.data.helpers.EntityBinder;
|
||||||
|
import eu.eudat.queryable.queryableentity.DataEntity;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -12,29 +16,30 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Credential\"")
|
@Table(name = "\"Credential\"")
|
||||||
@NamedEntityGraphs({
|
//@NamedEntityGraphs({
|
||||||
@NamedEntityGraph(
|
// @NamedEntityGraph(
|
||||||
name = "credentialUserInfo",
|
// name = "credentialUserInfo",
|
||||||
attributeNodes = {@NamedAttributeNode("userInfo")})
|
// attributeNodes = {@NamedAttributeNode("userInfo")})
|
||||||
})
|
//})
|
||||||
public class Credential implements DataEntity<Credential, UUID> {
|
public class CredentialEntity implements DataEntity<CredentialEntity, UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||||
private UUID id;
|
private UUID id;
|
||||||
public final static String _id = "id";
|
public final static String _id = "id";
|
||||||
|
|
||||||
@ManyToOne
|
@Column(name = "\"UserId\"", columnDefinition = "uuid", nullable = false)
|
||||||
@JoinColumn(name = "\"UserId\"", nullable = false)
|
private UUID userId;
|
||||||
private UserInfo userInfo;
|
public final static String _userId = "userId";
|
||||||
public final static String _userInfo = "userInfo"; //TODO: Authn
|
|
||||||
|
|
||||||
@Column(name = "\"Status\"", nullable = false)
|
@Column(name = "\"Status\"", nullable = false)
|
||||||
private Integer status;
|
@Convert(converter = IsActiveConverter.class)
|
||||||
public final static String _status = "status";
|
private IsActive isActive;
|
||||||
|
public final static String _isActive = "isActive";
|
||||||
|
|
||||||
@Column(name = "\"Provider\"", nullable = false)
|
@Column(name = "\"Provider\"", nullable = false)
|
||||||
private Integer provider;
|
@Convert(converter = ProviderTypeConverter.class)
|
||||||
|
private ProviderType provider;
|
||||||
public final static String _provider = "provider";
|
public final static String _provider = "provider";
|
||||||
|
|
||||||
@Column(name = "\"Public\"", nullable = false)
|
@Column(name = "\"Public\"", nullable = false)
|
||||||
|
@ -71,27 +76,27 @@ public class Credential implements DataEntity<Credential, UUID> {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserInfo getUserInfo() {
|
public UUID getUserId() {
|
||||||
return userInfo;
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserInfo(UserInfo userInfo) {
|
public void setUserId(UUID userId) {
|
||||||
this.userInfo = userInfo;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getStatus() {
|
public IsActive getIsActive() {
|
||||||
return status;
|
return isActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(Integer status) {
|
public void setIsActive(IsActive isActive) {
|
||||||
this.status = status;
|
this.isActive = isActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getProvider() {
|
public ProviderType getProvider() {
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProvider(Integer provider) {
|
public void setProvider(ProviderType provider) {
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,19 +153,19 @@ public class Credential implements DataEntity<Credential, UUID> {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
Credential that = (Credential) o;
|
CredentialEntity that = (CredentialEntity) o;
|
||||||
|
|
||||||
return provider.intValue() == that.provider.intValue();
|
return provider.getValue() == that.provider.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return provider.intValue();
|
return provider.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Credential entity) {
|
public void update(CredentialEntity entity) {
|
||||||
this.status = entity.status;
|
this.isActive = entity.isActive;
|
||||||
this.publicValue = entity.getPublicValue();
|
this.publicValue = entity.getPublicValue();
|
||||||
this.email = entity.getEmail();
|
this.email = entity.getEmail();
|
||||||
this.secret = entity.getSecret();
|
this.secret = entity.getSecret();
|
||||||
|
@ -173,7 +178,7 @@ public class Credential implements DataEntity<Credential, UUID> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Credential buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
|
public CredentialEntity buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
|
||||||
String currentBase = base.isEmpty() ? "" : base + ".";
|
String currentBase = base.isEmpty() ? "" : base + ".";
|
||||||
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
|
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
|
||||||
return this;
|
return this;
|
|
@ -1,31 +1,45 @@
|
||||||
package eu.eudat.data;
|
package eu.eudat.data;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.data.converters.enums.DescriptionTemplateTypeStatusConverter;
|
||||||
|
import eu.eudat.data.converters.enums.IsActiveConverter;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DescriptionTemplateType\"")
|
@Table(name = "\"DescriptionTemplateType\"")
|
||||||
public class DescriptionTemplateTypeEntity implements BaseEntity {
|
public class DescriptionTemplateTypeEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
|
||||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
|
||||||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
public final static String _id = "id";
|
||||||
|
|
||||||
public static final String _id = "id";
|
@Column(name = "name", length = 500, nullable = false)
|
||||||
|
|
||||||
@Column(name = "\"Name\"", nullable = false)
|
|
||||||
private String name;
|
private String name;
|
||||||
|
public final static String _name = "name";
|
||||||
|
|
||||||
public static final String _name = "name";
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private Instant createdAt;
|
||||||
|
public final static String _createdAt = "createdAt";
|
||||||
|
|
||||||
@Column(name = "\"Status\"", nullable = false)
|
@Column(name = "updated_at", nullable = false)
|
||||||
private Short status;
|
private Instant updatedAt;
|
||||||
|
public final static String _updatedAt = "updatedAt";
|
||||||
|
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
@Convert(converter = IsActiveConverter.class)
|
||||||
|
private IsActive isActive;
|
||||||
|
public final static String _isActive = "isActive";
|
||||||
|
|
||||||
|
@Column(name = "status", nullable = false)
|
||||||
|
@Convert(converter = DescriptionTemplateTypeStatusConverter.class)
|
||||||
|
private DescriptionTemplateTypeStatus status;
|
||||||
|
public final static String _status = "status";
|
||||||
|
|
||||||
public static final String _status = "status";
|
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -43,12 +57,35 @@ public class DescriptionTemplateTypeEntity implements BaseEntity {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Short getStatus() {
|
public Instant getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(Instant createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instant getUpdatedAt() {
|
||||||
|
return updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatedAt(Instant updatedAt) {
|
||||||
|
this.updatedAt = updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IsActive getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(IsActive isActive) {
|
||||||
|
this.isActive = isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptionTemplateTypeStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
public void setStatus(DescriptionTemplateTypeStatus status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package eu.eudat.data.converters;
|
||||||
|
|
||||||
|
import jakarta.persistence.AttributeConverter;
|
||||||
|
import jakarta.persistence.Converter;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 9/25/2018.
|
||||||
|
*/
|
||||||
|
@Converter
|
||||||
|
public class DateToUTCConverter implements AttributeConverter<Date, Date> {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(DateToUTCConverter.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Date convertToDatabaseColumn(Date attribute) {
|
||||||
|
if(attribute == null) return null;
|
||||||
|
DateFormat formatterIST = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
formatterIST.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
try {
|
||||||
|
String date = formatterIST.format(attribute);
|
||||||
|
return formatterIST.parse(date);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Date convertToEntityAttribute(Date dbData) {
|
||||||
|
if(dbData == null) return null;
|
||||||
|
DateFormat formatterIST = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
formatterIST.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
try {
|
||||||
|
String date = formatterIST.format(dbData);
|
||||||
|
return formatterIST.parse(date);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package eu.eudat.data.converters.enums;
|
||||||
|
|
||||||
|
public interface DatabaseEnum<T> {
|
||||||
|
T getValue();
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package eu.eudat.data.converters.enums;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.ProviderType;
|
||||||
|
import jakarta.persistence.AttributeConverter;
|
||||||
|
import jakarta.persistence.Converter;
|
||||||
|
|
||||||
|
@Converter
|
||||||
|
public abstract class DatabaseEnumConverter<EnumType extends DatabaseEnum<T>, T> implements AttributeConverter<EnumType, T> {
|
||||||
|
protected abstract EnumType of(T dbData);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T convertToDatabaseColumn(EnumType value) {
|
||||||
|
if (value == null) throw new IllegalArgumentException("value");
|
||||||
|
return value.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumType convertToEntityAttribute(T dbData) {
|
||||||
|
return this.of(dbData);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package eu.eudat.data.converters.enums;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import jakarta.persistence.Converter;
|
||||||
|
|
||||||
|
@Converter
|
||||||
|
public class DescriptionTemplateTypeStatusConverter extends DatabaseEnumConverter<DescriptionTemplateTypeStatus, Short> {
|
||||||
|
public DescriptionTemplateTypeStatus of(Short i) {
|
||||||
|
return DescriptionTemplateTypeStatus.of(i);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package eu.eudat.data.converters.enums;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import jakarta.persistence.Converter;
|
||||||
|
|
||||||
|
@Converter
|
||||||
|
public class IsActiveConverter extends DatabaseEnumConverter<IsActive, Short> {
|
||||||
|
public IsActive of(Short i) {
|
||||||
|
return IsActive.of(i);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package eu.eudat.data.converters.enums;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.ProviderType;
|
||||||
|
import jakarta.persistence.AttributeConverter;
|
||||||
|
import jakarta.persistence.Converter;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Converter
|
||||||
|
public class ProviderTypeConverter extends DatabaseEnumConverter<ProviderType, Integer> {
|
||||||
|
public ProviderType of(Integer i) {
|
||||||
|
return ProviderType.of(i);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package eu.eudat.data.helpers;
|
||||||
|
|
||||||
|
import jakarta.persistence.Tuple;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class EntityBinder {
|
||||||
|
public static <T> T fromTuple(List<Tuple> tuple, String path) {
|
||||||
|
try {
|
||||||
|
return (T) tuple.get(0).get(path);
|
||||||
|
}catch (IllegalArgumentException illegalArgument){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package eu.eudat.event;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class DescriptionTemplateTypeTouchedEvent {
|
||||||
|
public DescriptionTemplateTypeTouchedEvent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptionTemplateTypeTouchedEvent(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package eu.eudat.event;
|
||||||
|
|
||||||
|
import gr.cite.commons.web.oidc.apikey.events.ApiKeyStaleEvent;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EventBroker {
|
||||||
|
@Autowired
|
||||||
|
private ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
|
public void emitApiKeyStale(String apiKey) {
|
||||||
|
this.applicationEventPublisher.publishEvent(new ApiKeyStaleEvent(apiKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void emit(ApiKeyStaleEvent event) {
|
||||||
|
this.applicationEventPublisher.publishEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void emit(TenantTouchedEvent event) {
|
||||||
|
this.applicationEventPublisher.publishEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void emit(UserTouchedEvent event) {
|
||||||
|
this.applicationEventPublisher.publishEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void emit(UserAddedToTenantEvent event) {
|
||||||
|
this.applicationEventPublisher.publishEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void emit(UserRemovedFromTenantEvent event) {
|
||||||
|
this.applicationEventPublisher.publishEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void emit(DescriptionTemplateTypeTouchedEvent event) {
|
||||||
|
this.applicationEventPublisher.publishEvent(event);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package eu.eudat.event;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class TenantTouchedEvent {
|
||||||
|
public TenantTouchedEvent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public TenantTouchedEvent(UUID tenantId, String tenantCode, String previousTenantCode) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
this.tenantCode = tenantCode;
|
||||||
|
this.previousTenantCode = previousTenantCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
private UUID tenantId;
|
||||||
|
private String tenantCode;
|
||||||
|
private String previousTenantCode;
|
||||||
|
|
||||||
|
public UUID getTenantId() {
|
||||||
|
return tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantId(UUID tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTenantCode() {
|
||||||
|
return tenantCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantCode(String tenantCode) {
|
||||||
|
this.tenantCode = tenantCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPreviousTenantCode() {
|
||||||
|
return previousTenantCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviousTenantCode(String previousTenantCode) {
|
||||||
|
this.previousTenantCode = previousTenantCode;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package eu.eudat.event;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class UserAddedToTenantEvent {
|
||||||
|
public UserAddedToTenantEvent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserAddedToTenantEvent(UUID userId, UUID tenantId) {
|
||||||
|
this.userId = userId;
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private UUID userId;
|
||||||
|
private UUID tenantId;
|
||||||
|
|
||||||
|
public UUID getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(UUID userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getTenantId() {
|
||||||
|
return tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantId(UUID tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package eu.eudat.event;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class UserRemovedFromTenantEvent {
|
||||||
|
public UserRemovedFromTenantEvent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserRemovedFromTenantEvent(UUID userId, UUID tenantId) {
|
||||||
|
this.userId = userId;
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private UUID userId;
|
||||||
|
private UUID tenantId;
|
||||||
|
|
||||||
|
public UUID getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(UUID userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getTenantId() {
|
||||||
|
return tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantId(UUID tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package eu.eudat.event;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class UserTouchedEvent {
|
||||||
|
public UserTouchedEvent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserTouchedEvent(UUID userId, String subjectId, String previousSubjectId) {
|
||||||
|
this.userId = userId;
|
||||||
|
this.subjectId = subjectId;
|
||||||
|
this.previousSubjectId = previousSubjectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private UUID userId;
|
||||||
|
private String subjectId;
|
||||||
|
private String previousSubjectId;
|
||||||
|
|
||||||
|
public UUID getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(UUID userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubjectId() {
|
||||||
|
return subjectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubjectId(String subjectId) {
|
||||||
|
this.subjectId = subjectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPreviousSubjectId() {
|
||||||
|
return previousSubjectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviousSubjectId(String previousSubjectId) {
|
||||||
|
this.previousSubjectId = previousSubjectId;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,33 @@
|
||||||
package eu.eudat.model;
|
package eu.eudat.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
|
||||||
public class DescriptionTemplateType {
|
public class DescriptionTemplateType {
|
||||||
|
|
||||||
|
public final static String _id = "id";
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
|
||||||
|
public final static String _name = "name";
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private Short status;
|
public final static String _createdAt = "createdAt";
|
||||||
|
private Instant createdAt;
|
||||||
|
|
||||||
|
public final static String _updatedAt = "updatedAt";
|
||||||
|
private Instant updatedAt;
|
||||||
|
|
||||||
|
public final static String _isActive = "isActive";
|
||||||
|
private IsActive isActive;
|
||||||
|
|
||||||
|
public final static String _status = "status";
|
||||||
|
private DescriptionTemplateTypeStatus status;
|
||||||
|
|
||||||
|
public final static String _hash = "hash";
|
||||||
|
private String hash;
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -29,12 +45,43 @@ public class DescriptionTemplateType {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Short getStatus() {
|
public Instant getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(Instant createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instant getUpdatedAt() {
|
||||||
|
return updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatedAt(Instant updatedAt) {
|
||||||
|
this.updatedAt = updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IsActive getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(IsActive isActive) {
|
||||||
|
this.isActive = isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptionTemplateTypeStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
public void setStatus(DescriptionTemplateTypeStatus status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getHash() {
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHash(String hash) {
|
||||||
|
this.hash = hash;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package eu.eudat.model.builder;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
import gr.cite.tools.data.builder.Builder;
|
import gr.cite.tools.data.builder.Builder;
|
||||||
import gr.cite.tools.data.query.QueryBase;
|
import gr.cite.tools.data.query.QueryBase;
|
||||||
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
|
|
||||||
|
@ -12,9 +13,7 @@ import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public abstract class BaseBuilder<M, D> implements Builder {
|
public abstract class BaseBuilder<M, D> implements Builder {
|
||||||
|
|
||||||
protected final LoggerService logger;
|
protected final LoggerService logger;
|
||||||
|
|
||||||
protected final ConventionService conventionService;
|
protected final ConventionService conventionService;
|
||||||
|
|
||||||
public BaseBuilder(
|
public BaseBuilder(
|
||||||
|
@ -25,55 +24,49 @@ public abstract class BaseBuilder<M, D> implements Builder {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public M build(FieldSet directives, D data) {
|
public M build(FieldSet directives, D data) throws MyApplicationException {
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
return null;
|
//this.logger.Debug(new MapLogEntry("requested build for null item requesting fields").And("fields", directives));
|
||||||
|
// return default(M);
|
||||||
|
M model = null;
|
||||||
|
return null; //TODO
|
||||||
}
|
}
|
||||||
List<M> models = this.build(directives == null ? getFullFieldSet() : directives, List.of(data));
|
List<M> models = this.build(directives, Arrays.asList(data));
|
||||||
return models.stream().findFirst().orElse(null);
|
return models.stream().findFirst().orElse(null); //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract List<M> build(FieldSet directives, List<D> data);
|
public abstract List<M> build(FieldSet directives, List<D> datas) throws MyApplicationException;
|
||||||
|
|
||||||
/**
|
public <K> Map<K, M> asForeignKey(QueryBase<D> query, FieldSet directives, Function<M, K> keySelector) throws MyApplicationException {
|
||||||
* Provides all the fields that can be projected on the entity listings associated with this builder
|
|
||||||
*
|
|
||||||
* @return The field set
|
|
||||||
*/
|
|
||||||
public abstract FieldSet getFullFieldSet();
|
|
||||||
|
|
||||||
public <K> Map<K, M> asForeignKey(QueryBase<D> query, FieldSet directives, Function<M, K> keySelector) {
|
|
||||||
this.logger.trace("Building references from query");
|
this.logger.trace("Building references from query");
|
||||||
List<D> data = query.collectAs(directives);
|
List<D> datas = query.collectAs(directives);
|
||||||
this.logger.trace("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0));
|
this.logger.debug("collected {} items to build", Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
|
||||||
return this.asForeignKey(data, directives, keySelector);
|
return this.asForeignKey(datas, directives, keySelector);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <K> Map<K, M> asForeignKey(List<D> data, FieldSet directives, Function<M, K> keySelector) {
|
public <K> Map<K, M> asForeignKey(List<D> datas, FieldSet directives, Function<M, K> keySelector) throws MyApplicationException {
|
||||||
this.logger.trace("building references");
|
this.logger.trace("building references");
|
||||||
List<M> models = this.build(directives, data);
|
List<M> models = this.build(directives, datas);
|
||||||
this.logger.trace("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0));
|
this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(e -> e.size()).orElse(0), Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
|
||||||
assert models != null;
|
Map<K, M> map = models.stream().collect(Collectors.toMap(o -> keySelector.apply(o), o -> o));
|
||||||
return models.stream().collect(Collectors.toMap(keySelector, o -> o));
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <K> Map<K, List<M>> asMasterKey(QueryBase<D> query, FieldSet directives, Function<M, K> keySelector) {
|
public <K> Map<K, List<M>> asMasterKey(QueryBase<D> query, FieldSet directives, Function<M, K> keySelector) throws MyApplicationException {
|
||||||
this.logger.trace("Building details from query");
|
this.logger.trace("Building details from query");
|
||||||
List<D> data = query.collectAs(directives);
|
List<D> datas = query.collectAs(directives);
|
||||||
this.logger.trace("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0));
|
this.logger.debug("collected {} items to build", Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
|
||||||
return this.asMasterKey(data, directives, keySelector);
|
return this.asMasterKey(datas, directives, keySelector);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <K> Map<K, List<M>> asMasterKey(List<D> data, FieldSet directives, Function<M, K> keySelector) {
|
public <K> Map<K, List<M>> asMasterKey(List<D> datas, FieldSet directives, Function<M, K> keySelector) throws MyApplicationException {
|
||||||
this.logger.trace("building details");
|
this.logger.trace("building details");
|
||||||
List<M> models = this.build(directives, data);
|
List<M> models = this.build(directives, datas);
|
||||||
this.logger.trace("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0));
|
this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(e -> e.size()).orElse(0), Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
|
||||||
Map<K, List<M>> map = new HashMap<>();
|
Map<K, List<M>> map = new HashMap<>();
|
||||||
assert models != null;
|
|
||||||
for (M model : models) {
|
for (M model : models) {
|
||||||
K key = keySelector.apply(model);
|
K key = keySelector.apply(model);
|
||||||
if (!map.containsKey(key))
|
if (!map.containsKey(key)) map.put(key, new ArrayList<M>());
|
||||||
map.put(key, new ArrayList<M>());
|
|
||||||
map.get(key).add(model);
|
map.get(key).add(model);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
@ -81,12 +74,13 @@ public abstract class BaseBuilder<M, D> implements Builder {
|
||||||
|
|
||||||
public <FK, FM> Map<FK, FM> asEmpty(List<FK> keys, Function<FK, FM> mapper, Function<FM, FK> keySelector) {
|
public <FK, FM> Map<FK, FM> asEmpty(List<FK> keys, Function<FK, FM> mapper, Function<FM, FK> keySelector) {
|
||||||
this.logger.trace("building static references");
|
this.logger.trace("building static references");
|
||||||
List<FM> models = keys.stream().map(mapper).collect(Collectors.toList());
|
List<FM> models = keys.stream().map(x -> mapper.apply(x)).collect(Collectors.toList());
|
||||||
this.logger.trace("mapping {} build items from {} requested", Optional.of(models).map(List::size).orElse(0), Optional.of(keys).map(List::size));
|
this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(x -> x.size()).orElse(0), Optional.ofNullable(keys).map(x -> x.size()));
|
||||||
return models.stream().collect(Collectors.toMap(keySelector, o -> o));
|
Map<FK, FM> map = models.stream().collect(Collectors.toMap(o -> keySelector.apply(o), o -> o));
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String hashValue(Instant value) {
|
protected String hashValue(Instant value) throws MyApplicationException {
|
||||||
return this.conventionService.hashValue(value);
|
return this.conventionService.hashValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,3 +93,4 @@ public abstract class BaseBuilder<M, D> implements Builder {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,56 +1,62 @@
|
||||||
package eu.eudat.model.builder;
|
package eu.eudat.model.builder;
|
||||||
|
|
||||||
|
import eu.eudat.authorization.AuthorizationFlags;
|
||||||
|
import eu.eudat.commons.JsonHandlingService;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
||||||
import eu.eudat.model.DescriptionTemplateType;
|
import eu.eudat.model.DescriptionTemplateType;
|
||||||
|
import gr.cite.tools.data.builder.BuilderFactory;
|
||||||
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
|
import gr.cite.tools.logging.DataLogEntry;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public class DescriptionTemplateTypeBuilder extends BaseBuilder<DescriptionTemplateType, DescriptionTemplateTypeEntity> {
|
public class DescriptionTemplateTypeBuilder extends BaseBuilder<DescriptionTemplateType, DescriptionTemplateTypeEntity> {
|
||||||
|
|
||||||
public DescriptionTemplateTypeBuilder(ConventionService conventionService) {
|
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DescriptionTemplateTypeBuilder(
|
||||||
|
ConventionService conventionService) {
|
||||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeBuilder.class)));
|
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeBuilder.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DescriptionTemplateTypeBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||||
|
this.authorize = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DescriptionTemplateType> build(FieldSet directives, List<DescriptionTemplateTypeEntity> data) {
|
public List<DescriptionTemplateType> build(FieldSet fields, List<DescriptionTemplateTypeEntity> datas) throws MyApplicationException {
|
||||||
if (directives == null || directives.isEmpty())
|
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(datas).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
|
||||||
return new ArrayList<>();
|
this.logger.trace(new DataLogEntry("requested fields", fields));
|
||||||
|
if (fields == null || datas == null || fields.isEmpty()) return new ArrayList<>();
|
||||||
|
|
||||||
List<DescriptionTemplateType> models = new ArrayList<>(100);
|
List<DescriptionTemplateType> models = new ArrayList<>();
|
||||||
|
for (DescriptionTemplateTypeEntity d : datas) {
|
||||||
if (data == null)
|
|
||||||
return models;
|
|
||||||
for (DescriptionTemplateTypeEntity d : data) {
|
|
||||||
DescriptionTemplateType m = new DescriptionTemplateType();
|
DescriptionTemplateType m = new DescriptionTemplateType();
|
||||||
if (directives.hasField(this.asIndexer(DescriptionTemplateTypeEntity._id)))
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._id))) m.setId(d.getId());
|
||||||
m.setId(d.getId());
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._name))) m.setName(d.getName());
|
||||||
if (directives.hasField(this.asIndexer(DescriptionTemplateTypeEntity._name)))
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._createdAt))) m.setCreatedAt(d.getCreatedAt());
|
||||||
m.setName(d.getName());
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
|
||||||
if (directives.hasField(this.asIndexer(DescriptionTemplateTypeEntity._status)))
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._isActive))) m.setIsActive(d.getIsActive());
|
||||||
m.setStatus(d.getStatus());
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._status))) m.setStatus(d.getStatus());
|
||||||
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
|
||||||
models.add(m);
|
models.add(m);
|
||||||
}
|
}
|
||||||
|
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public FieldSet getFullFieldSet() {
|
|
||||||
BaseFieldSet fieldSet = new BaseFieldSet();
|
|
||||||
fieldSet.setFields(Set.of(
|
|
||||||
DescriptionTemplateTypeEntity._id,
|
|
||||||
DescriptionTemplateTypeEntity._name,
|
|
||||||
DescriptionTemplateTypeEntity._status
|
|
||||||
));
|
|
||||||
return fieldSet;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package eu.eudat.model.censorship;
|
package eu.eudat.model.censorship;
|
||||||
|
|
||||||
|
import eu.eudat.authorization.Permission;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
import gr.cite.tools.logging.DataLogEntry;
|
import gr.cite.tools.logging.DataLogEntry;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
|
@ -9,20 +11,24 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public class DescriptionTemplateTypeCensor extends BaseCensor{
|
public class DescriptionTemplateTypeCensor extends BaseCensor{
|
||||||
|
|
||||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeCensor.class));
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeCensor.class));
|
||||||
|
protected final AuthorizationService authService;
|
||||||
public DescriptionTemplateTypeCensor(ConventionService conventionService) {
|
public DescriptionTemplateTypeCensor(ConventionService conventionService, AuthorizationService authService) {
|
||||||
super(conventionService);
|
super(conventionService);
|
||||||
|
this.authService = authService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void censor(FieldSet fields) {
|
public void censor(FieldSet fields, UUID userId) {
|
||||||
logger.debug(new DataLogEntry("censoring fields", fields));
|
logger.debug(new DataLogEntry("censoring fields", fields));
|
||||||
if (fields.isEmpty())
|
if (fields.isEmpty()) return;
|
||||||
return;
|
|
||||||
|
this.authService.authorizeForce(Permission.BrowseDescriptionTemplateType);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
package eu.eudat.model.deleter;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
||||||
|
import eu.eudat.query.DescriptionTemplateTypeQuery;
|
||||||
|
import gr.cite.tools.data.deleter.Deleter;
|
||||||
|
import gr.cite.tools.data.deleter.DeleterFactory;
|
||||||
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
import gr.cite.tools.logging.LoggerService;
|
||||||
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.management.InvalidApplicationException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
|
public class DescriptionTemplateTypeDeleter implements Deleter {
|
||||||
|
|
||||||
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeDeleter.class));
|
||||||
|
|
||||||
|
private final EntityManager entityManager;
|
||||||
|
protected final QueryFactory queryFactory;
|
||||||
|
protected final DeleterFactory deleterFactory;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DescriptionTemplateTypeDeleter(
|
||||||
|
EntityManager entityManager,
|
||||||
|
QueryFactory queryFactory,
|
||||||
|
DeleterFactory deleterFactory
|
||||||
|
) {
|
||||||
|
this.entityManager = entityManager;
|
||||||
|
this.queryFactory = queryFactory;
|
||||||
|
this.deleterFactory = deleterFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
|
||||||
|
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
|
||||||
|
List<DescriptionTemplateTypeEntity> data = this.queryFactory.query(DescriptionTemplateTypeQuery.class).ids(ids).collect();
|
||||||
|
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
|
this.deleteAndSave(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAndSave(List<DescriptionTemplateTypeEntity> data) throws InvalidApplicationException {
|
||||||
|
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
|
this.delete(data);
|
||||||
|
logger.trace("saving changes");
|
||||||
|
this.entityManager.flush();
|
||||||
|
logger.trace("changes saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(List<DescriptionTemplateTypeEntity> data) throws InvalidApplicationException {
|
||||||
|
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
|
if (data == null || data.isEmpty()) return;
|
||||||
|
|
||||||
|
Instant now = Instant.now();
|
||||||
|
|
||||||
|
for (DescriptionTemplateTypeEntity item : data) {
|
||||||
|
logger.trace("deleting item {}", item.getId());
|
||||||
|
item.setIsActive(IsActive.Inactive);
|
||||||
|
item.setUpdatedAt(now);
|
||||||
|
logger.trace("updating item");
|
||||||
|
this.entityManager.merge(item);
|
||||||
|
logger.trace("updated item");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
||||||
|
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||||
|
import eu.eudat.commons.validation.ValidId;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
||||||
|
public class DescriptionTemplateTypePersist {
|
||||||
|
|
||||||
|
@ValidId(message = "{validation.invalidid}")
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@NotNull(message = "{validation.empty}")
|
||||||
|
@NotEmpty(message = "{validation.empty}")
|
||||||
|
@Size(max = 500, message = "{validation.largerthanmax}")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String hash;
|
||||||
|
|
||||||
|
@NotNull(message = "{validation.empty}")
|
||||||
|
private DescriptionTemplateTypeStatus status;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHash() {
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHash(String hash) {
|
||||||
|
this.hash = hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptionTemplateTypeStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(DescriptionTemplateTypeStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
package eu.eudat.query;
|
||||||
|
|
||||||
|
import eu.eudat.data.CredentialEntity;
|
||||||
|
import gr.cite.tools.data.query.FieldResolver;
|
||||||
|
import gr.cite.tools.data.query.QueryBase;
|
||||||
|
import gr.cite.tools.data.query.QueryContext;
|
||||||
|
import jakarta.persistence.Tuple;
|
||||||
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||||
|
import jakarta.persistence.criteria.Predicate;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
|
public class CredentialQuery extends QueryBase<CredentialEntity> {
|
||||||
|
|
||||||
|
private Collection<UUID> ids;
|
||||||
|
|
||||||
|
private Collection<UUID> userIds;
|
||||||
|
|
||||||
|
private Collection<Short> statuses;
|
||||||
|
|
||||||
|
public CredentialQuery ids(UUID value) {
|
||||||
|
this.ids = List.of(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CredentialQuery ids(UUID... value) {
|
||||||
|
this.ids = Arrays.asList(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CredentialQuery ids(List<UUID> value) {
|
||||||
|
this.ids = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public CredentialQuery userIds(UUID value) {
|
||||||
|
this.userIds = List.of(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CredentialQuery userIds(UUID... value) {
|
||||||
|
this.userIds = Arrays.asList(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CredentialQuery userIds(List<UUID> value) {
|
||||||
|
this.userIds = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CredentialQuery statuses(Short value) {
|
||||||
|
this.statuses = List.of(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CredentialQuery statuses(Short... value) {
|
||||||
|
this.statuses = Arrays.asList(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CredentialQuery statuses(List<Short> value) {
|
||||||
|
this.statuses = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean isFalseQuery() {
|
||||||
|
return this.isEmpty(this.ids) || this.isEmpty(this.userIds) || this.isEmpty(this.statuses);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<CredentialEntity> entityClass() {
|
||||||
|
return CredentialEntity.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
|
||||||
|
List<Predicate> predicates = new ArrayList<>();
|
||||||
|
|
||||||
|
if (this.ids != null) {
|
||||||
|
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(CredentialEntity._id));
|
||||||
|
for (UUID item : this.ids)
|
||||||
|
inClause.value(item);
|
||||||
|
predicates.add(inClause);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.userIds != null) {
|
||||||
|
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(CredentialEntity._userId));
|
||||||
|
for (UUID item : this.userIds)
|
||||||
|
inClause.value(item);
|
||||||
|
predicates.add(inClause);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.statuses != null) {
|
||||||
|
CriteriaBuilder.In<Short> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(CredentialEntity._isActive));
|
||||||
|
for (Short item : this.statuses)
|
||||||
|
inClause.value(item);
|
||||||
|
predicates.add(inClause);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!predicates.isEmpty()) {
|
||||||
|
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
|
||||||
|
return queryContext.CriteriaBuilder.and(predicatesArray);
|
||||||
|
} else {
|
||||||
|
return queryContext.CriteriaBuilder.and();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String fieldNameOf(FieldResolver item) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CredentialEntity convert(Tuple tuple, Set<String> columns) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,12 @@
|
||||||
package eu.eudat.query;
|
package eu.eudat.query;
|
||||||
|
|
||||||
|
import eu.eudat.authorization.AuthorizationFlags;
|
||||||
|
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
||||||
|
import eu.eudat.model.DescriptionTemplateType;
|
||||||
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||||
import gr.cite.tools.data.query.FieldResolver;
|
import gr.cite.tools.data.query.FieldResolver;
|
||||||
import gr.cite.tools.data.query.QueryBase;
|
import gr.cite.tools.data.query.QueryBase;
|
||||||
import gr.cite.tools.data.query.QueryContext;
|
import gr.cite.tools.data.query.QueryContext;
|
||||||
|
@ -11,17 +17,24 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public class DescriptionTemplateTypeQuery extends QueryBase<DescriptionTemplateTypeEntity> {
|
public class DescriptionTemplateTypeQuery extends QueryBase<DescriptionTemplateTypeEntity> {
|
||||||
|
|
||||||
|
private String like;
|
||||||
private Collection<UUID> ids;
|
private Collection<UUID> ids;
|
||||||
|
private Collection<IsActive> isActives;
|
||||||
|
private Collection<DescriptionTemplateTypeStatus> statuses;
|
||||||
|
private Collection<UUID> excludedIds;
|
||||||
|
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||||
|
|
||||||
private Collection<String> names;
|
public DescriptionTemplateTypeQuery like(String value) {
|
||||||
|
this.like = value;
|
||||||
private Collection<Short> statuses;
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery ids(UUID value) {
|
public DescriptionTemplateTypeQuery ids(UUID value) {
|
||||||
this.ids = List.of(value);
|
this.ids = List.of(value);
|
||||||
|
@ -33,44 +46,70 @@ public class DescriptionTemplateTypeQuery extends QueryBase<DescriptionTemplateT
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery ids(List<UUID> value) {
|
public DescriptionTemplateTypeQuery ids(Collection<UUID> values) {
|
||||||
this.ids = value;
|
this.ids = values;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery names(String value) {
|
public DescriptionTemplateTypeQuery isActive(IsActive value) {
|
||||||
this.names = List.of(value);
|
this.isActives = List.of(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery names(String... value) {
|
public DescriptionTemplateTypeQuery isActive(IsActive... value) {
|
||||||
this.names = Arrays.asList(value);
|
this.isActives = Arrays.asList(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery names(List<String> value) {
|
public DescriptionTemplateTypeQuery isActive(Collection<IsActive> values) {
|
||||||
this.names = value;
|
this.isActives = values;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery statuses(Short value) {
|
public DescriptionTemplateTypeQuery statuses(DescriptionTemplateTypeStatus value) {
|
||||||
this.statuses = List.of(value);
|
this.statuses = List.of(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery statuses(Short... value) {
|
public DescriptionTemplateTypeQuery statuses(DescriptionTemplateTypeStatus... value) {
|
||||||
this.statuses = Arrays.asList(value);
|
this.statuses = Arrays.asList(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery statuses(List<Short> value) {
|
public DescriptionTemplateTypeQuery statuses(Collection<DescriptionTemplateTypeStatus> values) {
|
||||||
this.statuses = value;
|
this.statuses = values;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public DescriptionTemplateTypeQuery excludedIds(Collection<UUID> values) {
|
||||||
protected Boolean isFalseQuery() {
|
this.excludedIds = values;
|
||||||
return Boolean.FALSE;
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptionTemplateTypeQuery excludedIds(UUID value) {
|
||||||
|
this.excludedIds = List.of(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptionTemplateTypeQuery excludedIds(UUID... value) {
|
||||||
|
this.excludedIds = Arrays.asList(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptionTemplateTypeQuery authorize(EnumSet<AuthorizationFlags> values) {
|
||||||
|
this.authorize = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final UserScope userScope;
|
||||||
|
private final AuthorizationService authService;
|
||||||
|
|
||||||
|
public DescriptionTemplateTypeQuery(
|
||||||
|
UserScope userScope,
|
||||||
|
AuthorizationService authService
|
||||||
|
) {
|
||||||
|
this.userScope = userScope;
|
||||||
|
this.authService = authService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,46 +118,66 @@ public class DescriptionTemplateTypeQuery extends QueryBase<DescriptionTemplateT
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
|
protected Boolean isFalseQuery() {
|
||||||
List<Predicate> predicates = new ArrayList<>();
|
return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds) || this.isEmpty(this.statuses);
|
||||||
|
|
||||||
if (this.ids != null) {
|
|
||||||
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._id));
|
|
||||||
for (UUID item : this.ids)
|
|
||||||
inClause.value(item);
|
|
||||||
predicates.add(inClause);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.names != null) {
|
@Override
|
||||||
CriteriaBuilder.In<String> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._name));
|
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
|
||||||
for (String item : this.names)
|
List<Predicate> predicates = new ArrayList<>();
|
||||||
inClause.value(item);
|
if (this.ids != null) {
|
||||||
|
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._id));
|
||||||
|
for (UUID item : this.ids) inClause.value(item);
|
||||||
|
predicates.add(inClause);
|
||||||
|
}
|
||||||
|
if (this.like != null && !this.like.isEmpty()) {
|
||||||
|
predicates.add(queryContext.CriteriaBuilder.like(queryContext.Root.get(DescriptionTemplateTypeEntity._name), this.like));
|
||||||
|
}
|
||||||
|
if (this.isActives != null) {
|
||||||
|
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._isActive));
|
||||||
|
for (IsActive item : this.isActives) inClause.value(item);
|
||||||
predicates.add(inClause);
|
predicates.add(inClause);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.statuses != null) {
|
if (this.statuses != null) {
|
||||||
CriteriaBuilder.In<Short> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._status));
|
CriteriaBuilder.In<DescriptionTemplateTypeStatus> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._status));
|
||||||
for (Short item : this.statuses)
|
for (DescriptionTemplateTypeStatus item : this.statuses) inClause.value(item);
|
||||||
inClause.value(item);
|
|
||||||
predicates.add(inClause);
|
predicates.add(inClause);
|
||||||
}
|
}
|
||||||
|
if (this.excludedIds != null) {
|
||||||
if (!predicates.isEmpty()) {
|
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._id));
|
||||||
|
for (UUID item : this.excludedIds) notInClause.value(item);
|
||||||
|
predicates.add(notInClause.not());
|
||||||
|
}
|
||||||
|
if (predicates.size() > 0) {
|
||||||
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
|
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
|
||||||
return queryContext.CriteriaBuilder.and(predicatesArray);
|
return queryContext.CriteriaBuilder.and(predicatesArray);
|
||||||
} else {
|
} else {
|
||||||
return queryContext.CriteriaBuilder.and();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String fieldNameOf(FieldResolver item) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DescriptionTemplateTypeEntity convert(Tuple tuple, Set<String> columns) {
|
protected DescriptionTemplateTypeEntity convert(Tuple tuple, Set<String> columns) {
|
||||||
return null;
|
DescriptionTemplateTypeEntity item = new DescriptionTemplateTypeEntity();
|
||||||
|
item.setId(QueryBase.convertSafe(tuple, columns, DescriptionTemplateTypeEntity._id, UUID.class));
|
||||||
|
item.setName(QueryBase.convertSafe(tuple, columns, DescriptionTemplateTypeEntity._name, String.class));
|
||||||
|
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DescriptionTemplateTypeEntity._createdAt, Instant.class));
|
||||||
|
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, DescriptionTemplateTypeEntity._updatedAt, Instant.class));
|
||||||
|
item.setIsActive(QueryBase.convertSafe(tuple, columns, DescriptionTemplateTypeEntity._isActive, IsActive.class));
|
||||||
|
item.setStatus(QueryBase.convertSafe(tuple, columns, DescriptionTemplateTypeEntity._status, DescriptionTemplateTypeStatus.class));
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String fieldNameOf(FieldResolver item) {
|
||||||
|
if (item.match(DescriptionTemplateType._id)) return DescriptionTemplateType._id;
|
||||||
|
else if (item.match(DescriptionTemplateType._name)) return DescriptionTemplateType._name;
|
||||||
|
else if (item.match(DescriptionTemplateType._createdAt)) return DescriptionTemplateType._createdAt;
|
||||||
|
else if (item.match(DescriptionTemplateType._updatedAt)) return DescriptionTemplateType._updatedAt;
|
||||||
|
else if (item.match(DescriptionTemplateType._isActive)) return DescriptionTemplateType._isActive;
|
||||||
|
else if (item.match(DescriptionTemplateType._status)) return DescriptionTemplateType._status;
|
||||||
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +1,63 @@
|
||||||
package eu.eudat.query.lookup;
|
package eu.eudat.query.lookup;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
import eu.eudat.query.DescriptionTemplateTypeQuery;
|
import eu.eudat.query.DescriptionTemplateTypeQuery;
|
||||||
import gr.cite.tools.data.query.Lookup;
|
import gr.cite.tools.data.query.Lookup;
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DescriptionTemplateTypeLookup extends Lookup {
|
public class DescriptionTemplateTypeLookup extends Lookup {
|
||||||
|
|
||||||
private String name;
|
private String like;
|
||||||
|
private List<IsActive> isActive;
|
||||||
|
private List<DescriptionTemplateTypeStatus> statuses;
|
||||||
|
private List<UUID> ids;
|
||||||
|
private List<UUID> excludedIds;
|
||||||
|
|
||||||
private Short status;
|
public String getLike() {
|
||||||
|
return like;
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setLike(String like) {
|
||||||
this.name = name;
|
this.like = like;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Short getStatus() {
|
public List<IsActive> getIsActive() {
|
||||||
return status;
|
return isActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
public void setIsActive(List<IsActive> isActive) {
|
||||||
this.status = status;
|
this.isActive = isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getIds() {
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIds(List<UUID> ids) {
|
||||||
|
this.ids = ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getExcludedIds() {
|
||||||
|
return excludedIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcludedIds(List<UUID> excludeIds) {
|
||||||
|
this.excludedIds = excludeIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery enrich(QueryFactory queryFactory) {
|
public DescriptionTemplateTypeQuery enrich(QueryFactory queryFactory) {
|
||||||
DescriptionTemplateTypeQuery query = queryFactory.query(DescriptionTemplateTypeQuery.class);
|
DescriptionTemplateTypeQuery query = queryFactory.query(DescriptionTemplateTypeQuery.class);
|
||||||
if (name != null) query.names(name);
|
if (this.like != null) query.like(this.like);
|
||||||
if (status != null ) query.statuses(status);
|
if (this.isActive != null) query.isActive(this.isActive);
|
||||||
|
if (this.statuses != null) query.statuses(this.statuses);
|
||||||
|
if (this.ids != null) query.ids(this.ids);
|
||||||
|
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
|
||||||
|
|
||||||
enrichCommon(query);
|
this.enrichCommon(query);
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,116 +1,18 @@
|
||||||
package eu.eudat.service;
|
package eu.eudat.service;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
|
||||||
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
|
||||||
import eu.eudat.model.DescriptionTemplateType;
|
import eu.eudat.model.DescriptionTemplateType;
|
||||||
import eu.eudat.model.builder.DescriptionTemplateTypeBuilder;
|
import eu.eudat.model.persist.DescriptionTemplateTypePersist;
|
||||||
import eu.eudat.query.DescriptionTemplateTypeQuery;
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
import eu.eudat.query.lookup.DescriptionTemplateTypeLookup;
|
import gr.cite.tools.exception.MyForbiddenException;
|
||||||
import gr.cite.tools.data.builder.BuilderFactory;
|
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
|
||||||
import gr.cite.tools.exception.MyNotFoundException;
|
import gr.cite.tools.exception.MyNotFoundException;
|
||||||
import jakarta.persistence.EntityManager;
|
import gr.cite.tools.exception.MyValidationException;
|
||||||
import jakarta.persistence.PersistenceContext;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
|
||||||
import org.springframework.transaction.TransactionDefinition;
|
|
||||||
import org.springframework.transaction.TransactionStatus;
|
|
||||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
|
||||||
|
|
||||||
import java.util.List;
|
import javax.management.InvalidApplicationException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
public interface DescriptionTemplateTypeService {
|
||||||
public class DescriptionTemplateTypeService {
|
DescriptionTemplateType persist(DescriptionTemplateTypePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
|
||||||
|
|
||||||
private final ApplicationContext applicationContext;
|
|
||||||
|
|
||||||
private final BuilderFactory builderFactory;
|
|
||||||
|
|
||||||
private final QueryFactory queryFactory;
|
|
||||||
|
|
||||||
private final PlatformTransactionManager transactionManager;
|
|
||||||
|
|
||||||
@PersistenceContext
|
|
||||||
private EntityManager entityManager;
|
|
||||||
|
|
||||||
public DescriptionTemplateTypeService(ApplicationContext applicationContext, BuilderFactory builderFactory, QueryFactory queryFactory, PlatformTransactionManager platformTransactionManager) {
|
|
||||||
this.applicationContext = applicationContext;
|
|
||||||
this.builderFactory = builderFactory;
|
|
||||||
this.queryFactory = queryFactory;
|
|
||||||
this.transactionManager = platformTransactionManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DescriptionTemplateType> query(DescriptionTemplateTypeLookup lookup) {
|
|
||||||
DescriptionTemplateTypeQuery query = lookup.enrich(queryFactory);
|
|
||||||
List<DescriptionTemplateTypeEntity> data = query.collectAs(lookup.getProject());
|
|
||||||
|
|
||||||
return builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(lookup.getProject(), data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DescriptionTemplateType get(UUID id) {
|
|
||||||
DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
|
|
||||||
|
|
||||||
return builderFactory
|
|
||||||
.builder(DescriptionTemplateTypeBuilder.class)
|
|
||||||
.build(null, query.ids(id).first());
|
|
||||||
}
|
|
||||||
|
|
||||||
public DescriptionTemplateTypeEntity getEntityByName(String name) {
|
|
||||||
DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
|
|
||||||
|
|
||||||
return query.names(name).first();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DescriptionTemplateType persist(DescriptionTemplateType payload) {
|
|
||||||
DescriptionTemplateTypeEntity created = new DescriptionTemplateTypeEntity();
|
|
||||||
created.setName(payload.getName());
|
|
||||||
created.setStatus(DescriptionTemplateTypeStatus.SAVED.getValue());
|
|
||||||
|
|
||||||
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
|
|
||||||
definition.setName(UUID.randomUUID().toString());
|
|
||||||
definition.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
|
|
||||||
definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
|
|
||||||
TransactionStatus status = null;
|
|
||||||
try {
|
|
||||||
status = transactionManager.getTransaction(definition);
|
|
||||||
entityManager.persist(created);
|
|
||||||
|
|
||||||
entityManager.flush();
|
|
||||||
transactionManager.commit(status);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
if (status != null)
|
|
||||||
transactionManager.rollback(status);
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
|
|
||||||
|
|
||||||
return builderFactory
|
|
||||||
.builder(DescriptionTemplateTypeBuilder.class)
|
|
||||||
.build(null, query.ids(created.getId()).first());
|
|
||||||
}
|
|
||||||
|
|
||||||
public DescriptionTemplateType update(DescriptionTemplateType payload) {
|
|
||||||
DescriptionTemplateTypeEntity entity = entityManager.find(DescriptionTemplateTypeEntity.class, payload.getId());
|
|
||||||
entity.setName(payload.getName());
|
|
||||||
entity.setStatus(payload.getStatus());
|
|
||||||
entityManager.merge(entity);
|
|
||||||
entityManager.flush();
|
|
||||||
|
|
||||||
return builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(null, entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean delete(UUID id) {
|
|
||||||
DescriptionTemplateTypeEntity entity = entityManager.find(DescriptionTemplateTypeEntity.class, id);
|
|
||||||
if (entity == null)
|
|
||||||
return false;
|
|
||||||
entity.setStatus(DescriptionTemplateTypeStatus.DELETED.getValue());
|
|
||||||
entityManager.merge(entity);
|
|
||||||
entityManager.flush();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,119 @@
|
||||||
|
package eu.eudat.service;
|
||||||
|
|
||||||
|
import eu.eudat.authorization.AuthorizationFlags;
|
||||||
|
import eu.eudat.authorization.Permission;
|
||||||
|
import eu.eudat.commons.JsonHandlingService;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.convention.ConventionService;
|
||||||
|
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
||||||
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||||
|
import eu.eudat.event.DescriptionTemplateTypeTouchedEvent;
|
||||||
|
import eu.eudat.event.EventBroker;
|
||||||
|
import eu.eudat.model.DescriptionTemplateType;
|
||||||
|
import eu.eudat.model.builder.DescriptionTemplateTypeBuilder;
|
||||||
|
import eu.eudat.model.deleter.DescriptionTemplateTypeDeleter;
|
||||||
|
import eu.eudat.model.persist.DescriptionTemplateTypePersist;
|
||||||
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||||
|
import gr.cite.tools.data.builder.BuilderFactory;
|
||||||
|
import gr.cite.tools.data.deleter.DeleterFactory;
|
||||||
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
|
import gr.cite.tools.exception.MyForbiddenException;
|
||||||
|
import gr.cite.tools.exception.MyNotFoundException;
|
||||||
|
import gr.cite.tools.exception.MyValidationException;
|
||||||
|
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||||
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
|
import gr.cite.tools.logging.LoggerService;
|
||||||
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.context.annotation.RequestScope;
|
||||||
|
|
||||||
|
import javax.management.InvalidApplicationException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequestScope
|
||||||
|
public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTypeService {
|
||||||
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeServiceImpl.class));
|
||||||
|
|
||||||
|
private final EntityManager entityManager;
|
||||||
|
private final AuthorizationService authorizationService;
|
||||||
|
private final DeleterFactory deleterFactory;
|
||||||
|
private final BuilderFactory builderFactory;
|
||||||
|
private final ConventionService conventionService;
|
||||||
|
private final ErrorThesaurusProperties errors;
|
||||||
|
private final MessageSource messageSource;
|
||||||
|
private final EventBroker eventBroker;
|
||||||
|
private final QueryFactory queryFactory;
|
||||||
|
private final JsonHandlingService jsonHandlingService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DescriptionTemplateTypeServiceImpl(
|
||||||
|
EntityManager entityManager,
|
||||||
|
AuthorizationService authorizationService,
|
||||||
|
DeleterFactory deleterFactory,
|
||||||
|
BuilderFactory builderFactory,
|
||||||
|
ConventionService conventionService,
|
||||||
|
ErrorThesaurusProperties errors,
|
||||||
|
MessageSource messageSource,
|
||||||
|
EventBroker eventBroker,
|
||||||
|
QueryFactory queryFactory,
|
||||||
|
JsonHandlingService jsonHandlingService) {
|
||||||
|
this.entityManager = entityManager;
|
||||||
|
this.authorizationService = authorizationService;
|
||||||
|
this.deleterFactory = deleterFactory;
|
||||||
|
this.builderFactory = builderFactory;
|
||||||
|
this.conventionService = conventionService;
|
||||||
|
this.errors = errors;
|
||||||
|
this.messageSource = messageSource;
|
||||||
|
this.eventBroker = eventBroker;
|
||||||
|
this.queryFactory = queryFactory;
|
||||||
|
this.jsonHandlingService = jsonHandlingService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptionTemplateType persist(DescriptionTemplateTypePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException {
|
||||||
|
logger.debug(new MapLogEntry("persisting data descriptionTemplateType").And("model", model).And("fields", fields));
|
||||||
|
|
||||||
|
this.authorizationService.authorizeForce(Permission.EditDescriptionTemplateType);
|
||||||
|
|
||||||
|
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
|
||||||
|
|
||||||
|
DescriptionTemplateTypeEntity data;
|
||||||
|
if (isUpdate) {
|
||||||
|
data = this.entityManager.find(DescriptionTemplateTypeEntity.class, model.getId());
|
||||||
|
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
} else {
|
||||||
|
data = new DescriptionTemplateTypeEntity();
|
||||||
|
data.setId(UUID.randomUUID());
|
||||||
|
data.setIsActive(IsActive.Active);
|
||||||
|
data.setCreatedAt(Instant.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
data.setName(model.getName());
|
||||||
|
data.setStatus(model.getStatus());
|
||||||
|
data.setUpdatedAt(Instant.now());
|
||||||
|
if (isUpdate) this.entityManager.merge(data);
|
||||||
|
else this.entityManager.persist(data);
|
||||||
|
|
||||||
|
this.entityManager.flush();
|
||||||
|
|
||||||
|
this.eventBroker.emit(new DescriptionTemplateTypeTouchedEvent(data.getId()));
|
||||||
|
return this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(BaseFieldSet.build(fields, DescriptionTemplateType._id), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
|
||||||
|
logger.debug("deleting dataset: {}", id);
|
||||||
|
|
||||||
|
this.authorizationService.authorizeForce(Permission.DeleteDescriptionTemplateType);
|
||||||
|
|
||||||
|
this.deleterFactory.deleter(DescriptionTemplateTypeDeleter.class).deleteAndSaveByIds(List.of(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package eu.eudat.data.dao.entities.security;
|
package eu.eudat.data.dao.entities.security;
|
||||||
|
|
||||||
|
import eu.eudat.data.CredentialEntity;
|
||||||
import eu.eudat.data.dao.DatabaseAccessLayer;
|
import eu.eudat.data.dao.DatabaseAccessLayer;
|
||||||
import eu.eudat.data.entities.Credential;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
public interface CredentialDao extends DatabaseAccessLayer<Credential, UUID> {
|
public interface CredentialDao extends DatabaseAccessLayer<CredentialEntity, UUID> {
|
||||||
|
|
||||||
Credential getLoggedInCredentials(String username, String secret, Integer provider);
|
CredentialEntity getLoggedInCredentials(String username, String secret, Integer provider);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package eu.eudat.data.dao.entities.security;
|
package eu.eudat.data.dao.entities.security;
|
||||||
|
|
||||||
|
import eu.eudat.data.CredentialEntity;
|
||||||
import eu.eudat.data.dao.DatabaseAccess;
|
import eu.eudat.data.dao.DatabaseAccess;
|
||||||
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
||||||
import eu.eudat.data.entities.Credential;
|
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -12,26 +12,26 @@ import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
@Component("credentialDao")
|
@Component("credentialDao")
|
||||||
public class CredentialDaoImpl extends DatabaseAccess<Credential> implements CredentialDao {
|
public class CredentialDaoImpl extends DatabaseAccess<CredentialEntity> implements CredentialDao {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public CredentialDaoImpl(DatabaseService<Credential> databaseService) {
|
public CredentialDaoImpl(DatabaseService<CredentialEntity> databaseService) {
|
||||||
super(databaseService);
|
super(databaseService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Credential createOrUpdate(Credential item) {
|
public CredentialEntity createOrUpdate(CredentialEntity item) {
|
||||||
return this.getDatabaseService().createOrUpdate(item, Credential.class);
|
return this.getDatabaseService().createOrUpdate(item, CredentialEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Credential find(UUID id) {
|
public CredentialEntity find(UUID id) {
|
||||||
return this.getDatabaseService().getQueryable(Credential.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingleOrDefault();
|
return this.getDatabaseService().getQueryable(CredentialEntity.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingleOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Credential getLoggedInCredentials(String username, String secret, Integer provider) {
|
public CredentialEntity getLoggedInCredentials(String username, String secret, Integer provider) {
|
||||||
return this.getDatabaseService().getQueryable(Credential.class).where(((builder, root) ->
|
return this.getDatabaseService().getQueryable(CredentialEntity.class).where(((builder, root) ->
|
||||||
builder.and(
|
builder.and(
|
||||||
builder.equal(root.get("publicValue"), username),
|
builder.equal(root.get("publicValue"), username),
|
||||||
builder.equal(root.get("secret"), secret),
|
builder.equal(root.get("secret"), secret),
|
||||||
|
@ -40,22 +40,22 @@ public class CredentialDaoImpl extends DatabaseAccess<Credential> implements Cre
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(Credential item) {
|
public void delete(CredentialEntity item) {
|
||||||
this.getDatabaseService().delete(item);
|
this.getDatabaseService().delete(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryableList<Credential> asQueryable() {
|
public QueryableList<CredentialEntity> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(Credential.class);
|
return this.getDatabaseService().getQueryable(CredentialEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Credential> createOrUpdateAsync(Credential item) {
|
public CompletableFuture<CredentialEntity> createOrUpdateAsync(CredentialEntity item) {
|
||||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Credential find(UUID id, String hint) {
|
public CredentialEntity find(UUID id, String hint) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.data.entities;
|
package eu.eudat.data.entities;
|
||||||
|
|
||||||
|
import eu.eudat.data.CredentialEntity;
|
||||||
import eu.eudat.data.converters.DateToUTCConverter;
|
import eu.eudat.data.converters.DateToUTCConverter;
|
||||||
import eu.eudat.data.entities.helpers.EntityBinder;
|
import eu.eudat.data.entities.helpers.EntityBinder;
|
||||||
import eu.eudat.queryable.queryableentity.DataEntity;
|
import eu.eudat.queryable.queryableentity.DataEntity;
|
||||||
|
@ -15,7 +16,7 @@ import java.util.*;
|
||||||
@NamedEntityGraphs({
|
@NamedEntityGraphs({
|
||||||
@NamedEntityGraph(
|
@NamedEntityGraph(
|
||||||
name = "userInfo",
|
name = "userInfo",
|
||||||
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials"), @NamedAttributeNode("additionalinfo")}),
|
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("additionalinfo")}),
|
||||||
})
|
})
|
||||||
public class UserInfo implements DataEntity<UserInfo, UUID> {
|
public class UserInfo implements DataEntity<UserInfo, UUID> {
|
||||||
|
|
||||||
|
@ -76,8 +77,9 @@ public class UserInfo implements DataEntity<UserInfo, UUID> {
|
||||||
)
|
)
|
||||||
private Set<DMP> dmps;
|
private Set<DMP> dmps;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "userInfo", fetch = FetchType.LAZY)
|
@OneToMany(fetch = FetchType.LAZY)
|
||||||
private Set<Credential> credentials = new HashSet<>();
|
@JoinColumn(name = "Id")
|
||||||
|
private Set<CredentialEntity> credentialEntities = new HashSet<>();
|
||||||
|
|
||||||
@OneToMany(mappedBy = "userInfo", fetch = FetchType.LAZY)
|
@OneToMany(mappedBy = "userInfo", fetch = FetchType.LAZY)
|
||||||
private Set<UserRole> userRoles = new HashSet<>();
|
private Set<UserRole> userRoles = new HashSet<>();
|
||||||
|
@ -168,12 +170,12 @@ public class UserInfo implements DataEntity<UserInfo, UUID> {
|
||||||
this.additionalinfo = additionalinfo;
|
this.additionalinfo = additionalinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Credential> getCredentials() {
|
public Set<CredentialEntity> getCredentials() {
|
||||||
return credentials;
|
return credentialEntities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCredentials(Set<Credential> credentials) {
|
public void setCredentials(Set<CredentialEntity> credentialEntities) {
|
||||||
this.credentials = credentials;
|
this.credentialEntities = credentialEntities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<UserRole> getUserRoles() {
|
public Set<UserRole> getUserRoles() {
|
||||||
|
|
|
@ -301,7 +301,10 @@
|
||||||
<groupId>io.micrometer</groupId>
|
<groupId>io.micrometer</groupId>
|
||||||
<artifactId>micrometer-core</artifactId>
|
<artifactId>micrometer-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
<!--CITE DEPENDENCIES-->
|
<!--CITE DEPENDENCIES-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>gr.cite</groupId>
|
<groupId>gr.cite</groupId>
|
||||||
|
@ -334,6 +337,12 @@
|
||||||
<version>2.1.0</version>
|
<version>2.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>gr.cite</groupId>
|
||||||
|
<artifactId>oidc-authz</artifactId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat;
|
package eu.eudat;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||||
|
@ -28,6 +29,7 @@ public class EuDatApplication extends SpringBootServletInitializer {
|
||||||
@Primary
|
@Primary
|
||||||
public ObjectMapper primaryObjectMapper() {
|
public ObjectMapper primaryObjectMapper() {
|
||||||
return JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
return JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||||
|
.serializationInclusion(JsonInclude.Include.NON_NULL)
|
||||||
.addModule(new JavaTimeModule()).build();
|
.addModule(new JavaTimeModule()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package eu.eudat.authorization;
|
||||||
|
|
||||||
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
|
import gr.cite.commons.web.authz.handler.AuthorizationHandler;
|
||||||
|
import gr.cite.commons.web.authz.handler.AuthorizationHandlerContext;
|
||||||
|
import gr.cite.commons.web.authz.policy.AuthorizationRequirement;
|
||||||
|
import gr.cite.commons.web.oidc.principal.MyPrincipal;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component("ownedAuthorizationHandler")
|
||||||
|
public class OwnedAuthorizationHandler extends AuthorizationHandler<OwnedAuthorizationRequirement> {
|
||||||
|
|
||||||
|
private final UserScope userScope;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public OwnedAuthorizationHandler(UserScope userScope) {
|
||||||
|
this.userScope = userScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int handleRequirement(AuthorizationHandlerContext context, Object resource, AuthorizationRequirement requirement) {
|
||||||
|
OwnedAuthorizationRequirement req = (OwnedAuthorizationRequirement) requirement;
|
||||||
|
|
||||||
|
OwnedResource rs = (OwnedResource) resource;
|
||||||
|
|
||||||
|
boolean isAuthenticated = ((MyPrincipal) context.getPrincipal()).isAuthenticated();
|
||||||
|
if (!isAuthenticated) return ACCESS_NOT_DETERMINED;
|
||||||
|
|
||||||
|
if (this.userScope.getUserIdSafe() == null) return ACCESS_NOT_DETERMINED;
|
||||||
|
|
||||||
|
if (rs != null && rs.getUserIds() != null && rs.getUserIds().contains(this.userScope.getUserIdSafe())) return ACCESS_GRANTED;
|
||||||
|
|
||||||
|
return ACCESS_NOT_DETERMINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends AuthorizationRequirement> supporting() {
|
||||||
|
return OwnedAuthorizationRequirement.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,16 @@
|
||||||
package eu.eudat.configurations;
|
package eu.eudat.configurations;
|
||||||
|
|
||||||
|
|
||||||
|
import eu.eudat.authorization.OwnedAuthorizationHandler;
|
||||||
|
import eu.eudat.authorization.OwnedAuthorizationRequirement;
|
||||||
|
import eu.eudat.authorization.OwnedResource;
|
||||||
|
import gr.cite.commons.web.authz.handler.AuthorizationHandler;
|
||||||
|
import gr.cite.commons.web.authz.handler.PermissionClientAuthorizationHandler;
|
||||||
|
import gr.cite.commons.web.authz.policy.AuthorizationRequirement;
|
||||||
|
import gr.cite.commons.web.authz.policy.AuthorizationRequirementMapper;
|
||||||
|
import gr.cite.commons.web.authz.policy.AuthorizationResource;
|
||||||
|
import gr.cite.commons.web.authz.policy.resolver.AuthorizationPolicyConfigurer;
|
||||||
|
import gr.cite.commons.web.authz.policy.resolver.AuthorizationPolicyResolverStrategy;
|
||||||
import gr.cite.commons.web.oidc.configuration.WebSecurityProperties;
|
import gr.cite.commons.web.oidc.configuration.WebSecurityProperties;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
@ -17,6 +27,7 @@ import org.springframework.security.web.authentication.preauth.AbstractPreAuthen
|
||||||
|
|
||||||
import jakarta.servlet.Filter;
|
import jakarta.servlet.Filter;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -27,14 +38,17 @@ public class SecurityConfiguration {
|
||||||
private final WebSecurityProperties webSecurityProperties;
|
private final WebSecurityProperties webSecurityProperties;
|
||||||
private final AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver;
|
private final AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver;
|
||||||
private final Filter apiKeyFilter;
|
private final Filter apiKeyFilter;
|
||||||
|
private final OwnedAuthorizationHandler ownedAuthorizationHandler;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public SecurityConfiguration(WebSecurityProperties webSecurityProperties,
|
public SecurityConfiguration(WebSecurityProperties webSecurityProperties,
|
||||||
@Qualifier("tokenAuthenticationResolver") AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver,
|
@Qualifier("tokenAuthenticationResolver") AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver,
|
||||||
@Qualifier("apiKeyFilter") Filter apiKeyFilter) {
|
@Qualifier("apiKeyFilter") Filter apiKeyFilter,
|
||||||
|
@Qualifier("ownedAuthorizationHandler") OwnedAuthorizationHandler ownedAuthorizationHandler) {
|
||||||
this.webSecurityProperties = webSecurityProperties;
|
this.webSecurityProperties = webSecurityProperties;
|
||||||
this.authenticationManagerResolver = authenticationManagerResolver;
|
this.authenticationManagerResolver = authenticationManagerResolver;
|
||||||
this.apiKeyFilter = apiKeyFilter;
|
this.apiKeyFilter = apiKeyFilter;
|
||||||
|
this.ownedAuthorizationHandler = ownedAuthorizationHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -45,67 +59,68 @@ public class SecurityConfiguration {
|
||||||
.headers(httpSecurityHeadersConfigurer -> httpSecurityHeadersConfigurer.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable))
|
.headers(httpSecurityHeadersConfigurer -> httpSecurityHeadersConfigurer.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable))
|
||||||
.addFilterBefore(apiKeyFilter, AbstractPreAuthenticatedProcessingFilter.class)
|
.addFilterBefore(apiKeyFilter, AbstractPreAuthenticatedProcessingFilter.class)
|
||||||
.authorizeHttpRequests(authRequest ->
|
.authorizeHttpRequests(authRequest ->
|
||||||
authRequest.requestMatchers(buildAntPatterns(webSecurityProperties.getAllowedEndpoints())).anonymous()
|
authRequest.requestMatchers(buildAntPatterns(webSecurityProperties.getAllowedEndpoints())).permitAll() //TODO: Authz
|
||||||
.requestMatchers(buildAntPatterns(webSecurityProperties.getAuthorizedEndpoints())).authenticated())
|
.requestMatchers(buildAntPatterns(webSecurityProperties.getAuthorizedEndpoints())).permitAll())
|
||||||
.sessionManagement( sessionManagementConfigurer-> sessionManagementConfigurer.sessionCreationPolicy(SessionCreationPolicy.NEVER))
|
.sessionManagement( sessionManagementConfigurer-> sessionManagementConfigurer.sessionCreationPolicy(SessionCreationPolicy.NEVER))
|
||||||
.oauth2ResourceServer(oauth2 -> oauth2.authenticationManagerResolver(authenticationManagerResolver));
|
.oauth2ResourceServer(oauth2 -> oauth2.authenticationManagerResolver(authenticationManagerResolver));
|
||||||
return tempHttp.build();
|
return tempHttp.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Bean
|
@Bean
|
||||||
// AuthorizationPolicyConfigurer authorizationPolicyConfigurer() {
|
AuthorizationPolicyConfigurer authorizationPolicyConfigurer() {
|
||||||
// return new AuthorizationPolicyConfigurer() {
|
return new AuthorizationPolicyConfigurer() {
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public AuthorizationPolicyResolverStrategy strategy() {
|
public AuthorizationPolicyResolverStrategy strategy() {
|
||||||
// return AuthorizationPolicyResolverStrategy.STRICT_CONSENSUS_BASED;
|
return AuthorizationPolicyResolverStrategy.STRICT_CONSENSUS_BASED;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// //Here you can register your custom authorization handlers, which will get used as well as the existing ones
|
//Here you can register your custom authorization handlers, which will get used as well as the existing ones
|
||||||
// //This is optional and can be omitted
|
//This is optional and can be omitted
|
||||||
// //If not set / set to null, only the default authorization handlers will be used
|
//If not set / set to null, only the default authorization handlers will be used
|
||||||
// @Override
|
@Override
|
||||||
// public List<AuthorizationHandler<? extends AuthorizationRequirement>> addCustomHandlers() {
|
public List<AuthorizationHandler<? extends AuthorizationRequirement>> addCustomHandlers() {
|
||||||
// return null;
|
return List.of( ownedAuthorizationHandler);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// //Here you can register your custom authorization requirements (if any)
|
//Here you can register your custom authorization requirements (if any)
|
||||||
// //This is optional and can be omitted
|
//This is optional and can be omitted
|
||||||
// //If not set / set to null, only the default authorization requirements will be used
|
//If not set / set to null, only the default authorization requirements will be used
|
||||||
// @Override
|
@Override
|
||||||
// public List<? extends AuthorizationRequirement> extendRequirements() {
|
public List<? extends AuthorizationRequirement> extendRequirements() {
|
||||||
// return List.of(
|
return List.of(
|
||||||
//// new TimeOfDayAuthorizationRequirement(new TimeOfDay("08:00","16:00"), true)
|
// new TimeOfDayAuthorizationRequirement(new TimeOfDay("08:00","16:00"), true)
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// //Here you can select handlers you want to disable by providing the classes they are implemented by
|
//Here you can select handlers you want to disable by providing the classes they are implemented by
|
||||||
// //You can disable any handler (including any custom one)
|
//You can disable any handler (including any custom one)
|
||||||
// //This is optional and can be omitted
|
//This is optional and can be omitted
|
||||||
// //If not set / set to null, all the handlers will be invoked, based on their requirement support
|
//If not set / set to null, all the handlers will be invoked, based on their requirement support
|
||||||
// //In the example below, the default client handler will be ignored by the resolver
|
//In the example below, the default client handler will be ignored by the resolver
|
||||||
// @Override
|
@Override
|
||||||
// public List<Class<? extends AuthorizationHandler<? extends AuthorizationRequirement>>> disableHandlers() {
|
public List<Class<? extends AuthorizationHandler<? extends AuthorizationRequirement>>> disableHandlers() {
|
||||||
// return List.of(PermissionClientAuthorizationHandler.class);
|
return List.of(PermissionClientAuthorizationHandler.class);
|
||||||
// }
|
}
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Bean
|
@Bean
|
||||||
// AuthorizationRequirementMapper authorizationRequirementMapper() {
|
AuthorizationRequirementMapper authorizationRequirementMapper() {
|
||||||
// return new AuthorizationRequirementMapper() {
|
return new AuthorizationRequirementMapper() {
|
||||||
// @Override
|
@Override
|
||||||
// public AuthorizationRequirement map(AuthorizationResource resource, boolean matchAll, String[] permissions) {
|
public AuthorizationRequirement map(AuthorizationResource resource, boolean matchAll, String[] permissions) {
|
||||||
// Class<?> type = resource.getClass();
|
Class<?> type = resource.getClass();
|
||||||
// if (!AuthorizationResource.class.isAssignableFrom(type)) throw new IllegalArgumentException("resource");
|
if (!AuthorizationResource.class.isAssignableFrom(type)) throw new IllegalArgumentException("resource");
|
||||||
//
|
|
||||||
// if (OwnedResource.class.equals(type)) {
|
if (OwnedResource.class.equals(type)) {
|
||||||
// return new OwnedAuthorizationRequirement();
|
return new OwnedAuthorizationRequirement();
|
||||||
// }
|
}
|
||||||
// throw new IllegalArgumentException("resource");
|
throw new IllegalArgumentException("resource");
|
||||||
// }
|
}
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
|
||||||
private String[] buildAntPatterns(Set<String> endpoints) {
|
private String[] buildAntPatterns(Set<String> endpoints) {
|
||||||
if (endpoints == null) {
|
if (endpoints == null) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.eudat.configurations;
|
package eu.eudat.configurations;
|
||||||
|
|
||||||
import eu.eudat.commons.scope.UserScope;
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
import eu.eudat.interceptors.UserInterceptor;
|
import eu.eudat.interceptors.UserInterceptor;
|
||||||
import eu.eudat.logic.handlers.PrincipalArgumentResolver;
|
import eu.eudat.logic.handlers.PrincipalArgumentResolver;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class Admin extends BaseController {
|
||||||
DatasetProfile shortenProfile = profile.toShort();
|
DatasetProfile shortenProfile = profile.toShort();
|
||||||
DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext(), descriptionTemplateTypeService);
|
DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext(), descriptionTemplateTypeService);
|
||||||
// modelDefinition.setType(getApiContext().getOperationsContext().getDatabaseRepository().getDescriptionTemplateTypeDao().findFromName(profile.getType()));
|
// modelDefinition.setType(getApiContext().getOperationsContext().getDatabaseRepository().getDescriptionTemplateTypeDao().findFromName(profile.getType()));
|
||||||
modelDefinition.setType(descriptionTemplateTypeService.getEntityByName(profile.getType()));
|
//TODO: dtziotzios modelDefinition.setType(descriptionTemplateTypeService.getEntityByName(profile.getType()));
|
||||||
modelDefinition.setGroupId(UUID.randomUUID());
|
modelDefinition.setGroupId(UUID.randomUUID());
|
||||||
modelDefinition.setVersion((short) 0);
|
modelDefinition.setVersion((short) 0);
|
||||||
|
|
||||||
|
|
|
@ -33,12 +33,6 @@ public class DashBoardController extends BaseController {
|
||||||
this.dashBoardManager = dashBoardManager;
|
this.dashBoardManager = dashBoardManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/getStatistics"}, produces = "application/json")
|
|
||||||
public ResponseEntity<ResponseItem<DashBoardStatistics>> getStatistics() {
|
|
||||||
DashBoardStatistics statistics = dashBoardManager.getStatistics();
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/me/getStatistics"}, produces = "application/json")
|
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/me/getStatistics"}, produces = "application/json")
|
||||||
public ResponseEntity<ResponseItem<DashBoardStatistics>> getStatistics(Principal principal) throws IOException {
|
public ResponseEntity<ResponseItem<DashBoardStatistics>> getStatistics(Principal principal) throws IOException {
|
||||||
DashBoardStatistics statistics = dashBoardManager.getMeStatistics(principal);
|
DashBoardStatistics statistics = dashBoardManager.getMeStatistics(principal);
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package eu.eudat.controllers;
|
package eu.eudat.controllers;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.types.ApiMessageCode;
|
import eu.eudat.types.ApiMessageCode;
|
||||||
|
import eu.eudat.types.Authorities;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
|
@ -12,7 +14,6 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
|
@ -26,29 +27,9 @@ public class LanguageController {
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "{lang}", method = RequestMethod.GET)
|
|
||||||
public ResponseEntity getLanguage(@PathVariable String lang) throws IOException {
|
|
||||||
|
|
||||||
String fileName = this.environment.getProperty("language.path") + lang + ".json";
|
|
||||||
InputStream is = new FileInputStream(fileName);
|
|
||||||
|
|
||||||
HttpHeaders responseHeaders = new HttpHeaders();
|
|
||||||
responseHeaders.setContentLength(is.available());
|
|
||||||
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName);
|
|
||||||
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
|
|
||||||
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
|
|
||||||
|
|
||||||
byte[] content = new byte[is.available()];
|
|
||||||
is.read(content);
|
|
||||||
is.close();
|
|
||||||
|
|
||||||
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = "update/{lang}", method = RequestMethod.POST)
|
@RequestMapping(value = "update/{lang}", method = RequestMethod.POST)
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<String>> updateLang(@PathVariable String lang, @RequestBody String json) throws Exception {
|
ResponseEntity<ResponseItem<String>> updateLang(@PathVariable String lang, @RequestBody String json, @ClaimedAuthorities(claims = {Authorities.ADMIN}) Principal principal) throws Exception {
|
||||||
String fileName = this.environment.getProperty("language.path") + lang + ".json";
|
String fileName = this.environment.getProperty("language.path") + lang + ".json";
|
||||||
OutputStream os = new FileOutputStream(fileName);
|
OutputStream os = new FileOutputStream(fileName);
|
||||||
os.write(json.getBytes());
|
os.write(json.getBytes());
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package eu.eudat.controllers;
|
||||||
|
|
||||||
|
import eu.eudat.controllers.BaseController;
|
||||||
|
import eu.eudat.logic.managers.DashBoardManager;
|
||||||
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||||
|
import eu.eudat.logic.services.ApiContext;
|
||||||
|
import eu.eudat.models.data.dashboard.recent.RecentActivity;
|
||||||
|
import eu.eudat.models.data.dashboard.recent.model.RecentActivityModel;
|
||||||
|
import eu.eudat.models.data.dashboard.recent.tablerequest.RecentActivityTableRequest;
|
||||||
|
import eu.eudat.models.data.dashboard.searchbar.SearchBarItem;
|
||||||
|
import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics;
|
||||||
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
import eu.eudat.types.ApiMessageCode;
|
||||||
|
import eu.eudat.types.Authorities;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
|
@RequestMapping(value = {"/api/public/dashboard/"})
|
||||||
|
public class PublicDashBoardController extends BaseController {
|
||||||
|
|
||||||
|
private DashBoardManager dashBoardManager;
|
||||||
|
@Autowired
|
||||||
|
public PublicDashBoardController(ApiContext apiContext, DashBoardManager dashBoardManager) {
|
||||||
|
super(apiContext);
|
||||||
|
this.dashBoardManager = dashBoardManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = {"getStatistics"}, produces = "application/json")
|
||||||
|
public ResponseEntity<ResponseItem<DashBoardStatistics>> getStatistics() {
|
||||||
|
DashBoardStatistics statistics = dashBoardManager.getStatistics();
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package eu.eudat.controllers;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
|
@RequestMapping(value = {"/api/public/language/"})
|
||||||
|
public class PublicLanguageController {
|
||||||
|
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public PublicLanguageController(Environment environment) {
|
||||||
|
this.environment = environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "{lang}", method = RequestMethod.GET)
|
||||||
|
public ResponseEntity getLanguage(@PathVariable String lang) throws IOException {
|
||||||
|
|
||||||
|
String fileName = this.environment.getProperty("language.path") + lang + ".json";
|
||||||
|
InputStream is = new FileInputStream(fileName);
|
||||||
|
|
||||||
|
HttpHeaders responseHeaders = new HttpHeaders();
|
||||||
|
responseHeaders.setContentLength(is.available());
|
||||||
|
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName);
|
||||||
|
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
|
||||||
|
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
|
||||||
|
|
||||||
|
byte[] content = new byte[is.available()];
|
||||||
|
is.read(content);
|
||||||
|
is.close();
|
||||||
|
|
||||||
|
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +1,9 @@
|
||||||
package eu.eudat.controllers;
|
package eu.eudat.controllers;
|
||||||
|
|
||||||
import eu.eudat.data.query.items.table.userinfo.UserInfoTableRequestItem;
|
import eu.eudat.data.query.items.table.userinfo.UserInfoTableRequestItem;
|
||||||
import eu.eudat.exceptions.security.ExpiredTokenException;
|
|
||||||
import eu.eudat.exceptions.security.NonValidTokenException;
|
|
||||||
import eu.eudat.exceptions.security.NullEmailException;
|
|
||||||
import eu.eudat.logic.managers.UserManager;
|
import eu.eudat.logic.managers.UserManager;
|
||||||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.models.data.doi.DOIRequest;
|
|
||||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
@ -88,22 +84,6 @@ public class Users extends BaseController {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<UserListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<UserListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/registerDOIToken"}, consumes = "application/json", produces = "application/json")
|
|
||||||
public @ResponseBody
|
|
||||||
ResponseEntity<ResponseItem<UserProfile>> registerDOIToken(@RequestBody DOIRequest doiRequest, Principal principal) throws NullEmailException, IOException {
|
|
||||||
userManager.registerDOIToken(doiRequest, principal);
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().status(ApiMessageCode.NO_MESSAGE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@RequestMapping(method = RequestMethod.DELETE, value = {"/deleteDOIToken"}, consumes = "application/json", produces = "application/json")
|
|
||||||
public @ResponseBody
|
|
||||||
ResponseEntity<ResponseItem<UserProfile>> deleteDOIToken(Principal principal) throws NullEmailException, IOException {
|
|
||||||
userManager.deleteDOIToken(principal);
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().status(ApiMessageCode.NO_MESSAGE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/getCsv"})
|
@RequestMapping(method = RequestMethod.GET, value = {"/getCsv"})
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity exportCsv(@ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception {
|
ResponseEntity exportCsv(@ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception {
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package eu.eudat.controllers.v2;
|
|
||||||
|
|
||||||
import eu.eudat.model.result.QueryResult;
|
|
||||||
import gr.cite.tools.data.query.Lookup;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class BaseController {
|
|
||||||
|
|
||||||
public static <T, L extends Lookup> QueryResult<T> extractQueryResultWithCount(Function<L, List<T>> service, L lookup) {
|
|
||||||
return extractQueryResultWithCountWhen(service, lookup, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, L extends Lookup> QueryResult<T> extractQueryResultWithCountWhen(Function<L, List<T>> service, L lookup, Function<T, Boolean> when) {
|
|
||||||
List<T> result = service.apply(lookup);
|
|
||||||
lookup.setPage(null);
|
|
||||||
List<T> all = service.apply(lookup);
|
|
||||||
long count = all.size();
|
|
||||||
if (when == null) return new QueryResult<>(result, count);
|
|
||||||
long countOverride = count;
|
|
||||||
for (T item : all) {
|
|
||||||
if (!when.apply(item)) countOverride--;
|
|
||||||
}
|
|
||||||
return new QueryResult<>(result, count, countOverride);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, L extends Lookup> QueryResult<T> extractQueryResultWithCount(BiFunction<String, L, List<T>> service, String name, L lookup) {
|
|
||||||
List<T> result = service.apply(name, lookup);
|
|
||||||
lookup.setPage(null);
|
|
||||||
long count = service.apply(name, lookup).size();
|
|
||||||
return new QueryResult<>(result, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +1,33 @@
|
||||||
package eu.eudat.controllers.v2;
|
package eu.eudat.controllers.v2;
|
||||||
|
|
||||||
import eu.eudat.audit.AuditableAction;
|
import eu.eudat.audit.AuditableAction;
|
||||||
|
import eu.eudat.authorization.AuthorizationFlags;
|
||||||
|
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
||||||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||||
import eu.eudat.model.DescriptionTemplateType;
|
import eu.eudat.model.DescriptionTemplateType;
|
||||||
|
import eu.eudat.model.builder.DescriptionTemplateTypeBuilder;
|
||||||
import eu.eudat.model.censorship.DescriptionTemplateTypeCensor;
|
import eu.eudat.model.censorship.DescriptionTemplateTypeCensor;
|
||||||
|
import eu.eudat.model.persist.DescriptionTemplateTypePersist;
|
||||||
import eu.eudat.model.result.QueryResult;
|
import eu.eudat.model.result.QueryResult;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
import eu.eudat.query.DescriptionTemplateTypeQuery;
|
||||||
import eu.eudat.query.lookup.DescriptionTemplateTypeLookup;
|
import eu.eudat.query.lookup.DescriptionTemplateTypeLookup;
|
||||||
import eu.eudat.service.DescriptionTemplateTypeService;
|
import eu.eudat.service.DescriptionTemplateTypeService;
|
||||||
import eu.eudat.types.Authorities;
|
import eu.eudat.types.Authorities;
|
||||||
import gr.cite.tools.auditing.AuditService;
|
import gr.cite.tools.auditing.AuditService;
|
||||||
|
import gr.cite.tools.data.builder.BuilderFactory;
|
||||||
import gr.cite.tools.data.censor.CensorFactory;
|
import gr.cite.tools.data.censor.CensorFactory;
|
||||||
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
|
import gr.cite.tools.exception.MyForbiddenException;
|
||||||
import gr.cite.tools.exception.MyNotFoundException;
|
import gr.cite.tools.exception.MyNotFoundException;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import gr.cite.tools.logging.MapLogEntry;
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
|
import gr.cite.tools.validation.MyValidate;
|
||||||
|
import org.opensaml.xml.signature.Q;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -24,99 +36,98 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.AbstractMap;
|
import javax.management.InvalidApplicationException;
|
||||||
import java.util.Map;
|
import java.io.IOException;
|
||||||
import java.util.UUID;
|
import java.util.*;
|
||||||
|
|
||||||
import static eu.eudat.controllers.v2.BaseController.extractQueryResultWithCount;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@Transactional
|
@RequestMapping(path = "api/description-template-type")
|
||||||
@RequestMapping(path = "api/v2/descriptionTemplateType", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
public class DescriptionTemplateTypeV2Controller {
|
public class DescriptionTemplateTypeV2Controller {
|
||||||
|
|
||||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeV2Controller.class));
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeV2Controller.class));
|
||||||
|
|
||||||
|
private final BuilderFactory builderFactory;
|
||||||
private final AuditService auditService;
|
private final AuditService auditService;
|
||||||
|
|
||||||
private final DescriptionTemplateTypeService descriptionTemplateTypeService;
|
private final DescriptionTemplateTypeService descriptionTemplateTypeService;
|
||||||
|
private final CensorFactory censorFactory;
|
||||||
|
private final QueryFactory queryFactory;
|
||||||
private final MessageSource messageSource;
|
private final MessageSource messageSource;
|
||||||
|
|
||||||
private final CensorFactory censorFactory;
|
@Autowired
|
||||||
|
public DescriptionTemplateTypeV2Controller(
|
||||||
public DescriptionTemplateTypeV2Controller(AuditService auditService, DescriptionTemplateTypeService descriptionTemplateTypeService, MessageSource messageSource, CensorFactory censorFactory) {
|
BuilderFactory builderFactory,
|
||||||
|
AuditService auditService,
|
||||||
|
DescriptionTemplateTypeService descriptionTemplateTypeService,
|
||||||
|
CensorFactory censorFactory,
|
||||||
|
QueryFactory queryFactory,
|
||||||
|
MessageSource messageSource) {
|
||||||
|
this.builderFactory = builderFactory;
|
||||||
this.auditService = auditService;
|
this.auditService = auditService;
|
||||||
this.descriptionTemplateTypeService = descriptionTemplateTypeService;
|
this.descriptionTemplateTypeService = descriptionTemplateTypeService;
|
||||||
this.messageSource = messageSource;
|
|
||||||
this.censorFactory = censorFactory;
|
this.censorFactory = censorFactory;
|
||||||
|
this.queryFactory = queryFactory;
|
||||||
|
this.messageSource = messageSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("query")
|
@PostMapping("query")
|
||||||
public QueryResult<DescriptionTemplateType> query(@RequestBody DescriptionTemplateTypeLookup lookup, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal ignoredPrincipal) {
|
public QueryResult<DescriptionTemplateType> Query(@RequestBody DescriptionTemplateTypeLookup lookup) throws MyApplicationException, MyForbiddenException {
|
||||||
logger.debug("querying {}", DescriptionTemplateType.class.getSimpleName());
|
logger.debug("querying {}", DescriptionTemplateType.class.getSimpleName());
|
||||||
|
|
||||||
censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(lookup.getProject());
|
this.censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(lookup.getProject(), null);
|
||||||
|
|
||||||
auditService.track(AuditableAction.DescriptionTemplateType_Query, "lookup", lookup);
|
DescriptionTemplateTypeQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission);
|
||||||
|
|
||||||
return extractQueryResultWithCount(descriptionTemplateTypeService::query, lookup);
|
List<DescriptionTemplateTypeEntity> data = query.collectAs(lookup.getProject());
|
||||||
|
List<DescriptionTemplateType> models = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data);
|
||||||
|
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
|
||||||
|
|
||||||
|
this.auditService.track(AuditableAction.DescriptionTemplateType_Query, "lookup", lookup);
|
||||||
|
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
||||||
|
|
||||||
|
return new QueryResult<>(models, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("{id}")
|
@GetMapping("{id}")
|
||||||
public QueryResult<DescriptionTemplateType> get(@PathVariable("id") UUID id, FieldSet fieldSet, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal ignoredPrincipal) {
|
public DescriptionTemplateType Get(@PathVariable("id") UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
|
||||||
logger.debug(new MapLogEntry("retrieving" + DescriptionTemplateType.class.getSimpleName()).And("id", id));
|
logger.debug(new MapLogEntry("retrieving" + DescriptionTemplateType.class.getSimpleName()).And("id", id).And("fields", fieldSet));
|
||||||
|
|
||||||
censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(fieldSet);
|
this.censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(fieldSet, null);
|
||||||
|
|
||||||
DescriptionTemplateType model = descriptionTemplateTypeService.get(id);
|
DescriptionTemplateTypeQuery query = this.queryFactory.query(DescriptionTemplateTypeQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id);
|
||||||
if (model == null)
|
DescriptionTemplateType model = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet));
|
||||||
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
|
||||||
auditService.track(AuditableAction.DescriptionTemplateType_Query, "id", id);
|
this.auditService.track(AuditableAction.DescriptionTemplateType_Lookup, Map.ofEntries(
|
||||||
|
new AbstractMap.SimpleEntry<String, Object>("id", id),
|
||||||
|
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
|
||||||
|
));
|
||||||
|
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
||||||
|
|
||||||
return new QueryResult<>(model);
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("persist")
|
@PostMapping("persist")
|
||||||
public QueryResult<DescriptionTemplateType> persist(@RequestBody DescriptionTemplateType payload, FieldSet fieldSet, @ClaimedAuthorities(claims = {Authorities.ADMIN}) Principal ignoredPrincipal) {
|
@Transactional
|
||||||
logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", payload).And("fieldSet", fieldSet));
|
public DescriptionTemplateType Persist(@MyValidate @RequestBody DescriptionTemplateTypePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
|
||||||
|
logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
|
||||||
|
DescriptionTemplateType persisted = this.descriptionTemplateTypeService.persist(model, fieldSet);
|
||||||
|
|
||||||
DescriptionTemplateType persisted = descriptionTemplateTypeService.persist(payload);
|
this.auditService.track(AuditableAction.DescriptionTemplateType_Persist, Map.ofEntries(
|
||||||
|
new AbstractMap.SimpleEntry<String, Object>("model", model),
|
||||||
auditService.track(AuditableAction.DescriptionTemplateType_Persist, Map.ofEntries(
|
|
||||||
new AbstractMap.SimpleEntry<String, Object>("model", payload),
|
|
||||||
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
|
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
|
||||||
));
|
));
|
||||||
|
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
||||||
return new QueryResult<>(persisted);
|
return persisted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("update")
|
@DeleteMapping("{id}")
|
||||||
public QueryResult<DescriptionTemplateType> update(@RequestBody DescriptionTemplateType payload, FieldSet fieldSet, @ClaimedAuthorities(claims = {Authorities.ADMIN}) Principal ignoredPrincipal) {
|
@Transactional
|
||||||
logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", payload).And("fieldSet", fieldSet));
|
public void Delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
|
||||||
|
logger.debug(new MapLogEntry("retrieving" + DescriptionTemplateType.class.getSimpleName()).And("id", id));
|
||||||
|
|
||||||
DescriptionTemplateType persisted = descriptionTemplateTypeService.update(payload);
|
this.descriptionTemplateTypeService.deleteAndSave(id);
|
||||||
|
|
||||||
auditService.track(AuditableAction.DescriptionTemplateType_Persist, Map.ofEntries(
|
this.auditService.track(AuditableAction.DescriptionTemplateType_Delete, "id", id);
|
||||||
new AbstractMap.SimpleEntry<String, Object>("model", payload),
|
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
||||||
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
|
|
||||||
));
|
|
||||||
|
|
||||||
return new QueryResult<>(persisted);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("delete/{id}")
|
|
||||||
public ResponseEntity<?> delete(@PathVariable(value = "id") UUID id, @ClaimedAuthorities(claims = {Authorities.ADMIN}) Principal ignoredPrincipal) {
|
|
||||||
logger.debug(new MapLogEntry("deleting" + DescriptionTemplateType.class.getSimpleName()).And("id", id));
|
|
||||||
|
|
||||||
auditService.track(AuditableAction.DescriptionTemplateType_Delete, "delete", id);
|
|
||||||
|
|
||||||
if (descriptionTemplateTypeService.delete(id))
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).build();
|
|
||||||
else
|
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,8 @@ public class PrincipalController {
|
||||||
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._authenticatedAt),
|
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._authenticatedAt),
|
||||||
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._expiresAt),
|
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._expiresAt),
|
||||||
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._more),
|
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._more),
|
||||||
Account._roles);
|
Account._roles,
|
||||||
|
Account._permissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
MyPrincipal principal = this.currentPrincipalResolver.currentPrincipal();
|
MyPrincipal principal = this.currentPrincipalResolver.currentPrincipal();
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package eu.eudat.interceptors;
|
package eu.eudat.interceptors;
|
||||||
|
|
||||||
|
|
||||||
import eu.eudat.commons.scope.UserScope;
|
import eu.eudat.commons.enums.ProviderType;
|
||||||
import eu.eudat.data.entities.Credential;
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
|
import eu.eudat.data.CredentialEntity;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
import eu.eudat.data.entities.UserRole;
|
import eu.eudat.data.entities.UserRole;
|
||||||
import eu.eudat.exceptions.security.NullEmailException;
|
import eu.eudat.exceptions.security.NullEmailException;
|
||||||
|
@ -68,7 +70,7 @@ public class UserInterceptor implements WebRequestInterceptor {
|
||||||
UUID userId = null;
|
UUID userId = null;
|
||||||
if (this.currentPrincipalResolver.currentPrincipal().isAuthenticated()) {
|
if (this.currentPrincipalResolver.currentPrincipal().isAuthenticated()) {
|
||||||
String subjectId = this.claimExtractor.subjectString(this.currentPrincipalResolver.currentPrincipal());
|
String subjectId = this.claimExtractor.subjectString(this.currentPrincipalResolver.currentPrincipal());
|
||||||
|
var aa = this.claimExtractor.roles(this.currentPrincipalResolver.currentPrincipal());
|
||||||
UserInterceptorCacheService.UserInterceptorCacheValue cacheValue = this.userInterceptorCacheService.lookup(this.userInterceptorCacheService.buildKey(subjectId));
|
UserInterceptorCacheService.UserInterceptorCacheValue cacheValue = this.userInterceptorCacheService.lookup(this.userInterceptorCacheService.buildKey(subjectId));
|
||||||
if (cacheValue != null) {
|
if (cacheValue != null) {
|
||||||
userId = cacheValue.getUserId();
|
userId = cacheValue.getUserId();
|
||||||
|
@ -94,15 +96,15 @@ public class UserInterceptor implements WebRequestInterceptor {
|
||||||
private UUID getUserIdFromDatabaseBySubject(String subjectId) {
|
private UUID getUserIdFromDatabaseBySubject(String subjectId) {
|
||||||
CriteriaBuilder credentialCriteriaBuilder = this.entityManager.getCriteriaBuilder();
|
CriteriaBuilder credentialCriteriaBuilder = this.entityManager.getCriteriaBuilder();
|
||||||
CriteriaQuery<Tuple> credentialQuery = credentialCriteriaBuilder.createQuery(Tuple.class);
|
CriteriaQuery<Tuple> credentialQuery = credentialCriteriaBuilder.createQuery(Tuple.class);
|
||||||
Root<Credential> credentialRoot = credentialQuery.from(Credential.class);
|
Root<CredentialEntity> credentialRoot = credentialQuery.from(CredentialEntity.class);
|
||||||
credentialQuery.where(
|
credentialQuery.where(
|
||||||
credentialCriteriaBuilder.and(
|
credentialCriteriaBuilder.and(
|
||||||
credentialCriteriaBuilder.equal(credentialRoot.get(Credential._externalId), subjectId),
|
credentialCriteriaBuilder.equal(credentialRoot.get(CredentialEntity._externalId), subjectId),
|
||||||
credentialCriteriaBuilder.equal(credentialRoot.get(Credential._status), 1), //TODO: Authn
|
credentialCriteriaBuilder.equal(credentialRoot.get(CredentialEntity._isActive), IsActive.Active),
|
||||||
credentialCriteriaBuilder.equal(credentialRoot.get(Credential._provider), 128)
|
credentialCriteriaBuilder.equal(credentialRoot.get(CredentialEntity._provider), ProviderType.Keycloack)
|
||||||
));
|
));
|
||||||
|
|
||||||
credentialQuery.multiselect(credentialRoot.get(Credential._userInfo).get(UserInfo._id).alias(UserInfo._id));
|
credentialQuery.multiselect(credentialRoot.get(CredentialEntity._userId).alias(UserInfo._id));
|
||||||
|
|
||||||
List<Tuple> results = this.entityManager.createQuery(credentialQuery).getResultList();
|
List<Tuple> results = this.entityManager.createQuery(credentialQuery).getResultList();
|
||||||
return this.getUUIDFromTuple(results, UserInfo._id);
|
return this.getUUIDFromTuple(results, UserInfo._id);
|
||||||
|
@ -194,17 +196,17 @@ public class UserInterceptor implements WebRequestInterceptor {
|
||||||
user.setAdditionalinfo("{\"data\":{\"avatar\":{\"url\":\"\"},\"zenodoToken\":\"\", \"expirationDate\": \"\", \"zenodoRefresh\": \"\", \"zenodoEmail\": \"\"}}"); //TODO: Authn
|
user.setAdditionalinfo("{\"data\":{\"avatar\":{\"url\":\"\"},\"zenodoToken\":\"\", \"expirationDate\": \"\", \"zenodoRefresh\": \"\", \"zenodoEmail\": \"\"}}"); //TODO: Authn
|
||||||
}
|
}
|
||||||
|
|
||||||
Credential credential = new Credential();
|
CredentialEntity credentialEntity = new CredentialEntity();
|
||||||
credential.setId(UUID.randomUUID());
|
credentialEntity.setId(UUID.randomUUID());
|
||||||
credential.setUserInfo(user);
|
credentialEntity.setUserId(user.getId());
|
||||||
credential.setSecret(subjectId);
|
credentialEntity.setSecret(subjectId);
|
||||||
credential.setCreationTime(new Date());
|
credentialEntity.setCreationTime(new Date());
|
||||||
credential.setLastUpdateTime(new Date());
|
credentialEntity.setLastUpdateTime(new Date());
|
||||||
credential.setStatus(1);
|
credentialEntity.setIsActive(IsActive.Active);
|
||||||
credential.setProvider(128);//TODO: Authn
|
credentialEntity.setProvider(ProviderType.Keycloack);//TODO: Authn
|
||||||
credential.setExternalId(subjectId);
|
credentialEntity.setExternalId(subjectId);
|
||||||
credential.setEmail(email);
|
credentialEntity.setEmail(email);
|
||||||
credential.setPublicValue(email);
|
credentialEntity.setPublicValue(email);
|
||||||
|
|
||||||
|
|
||||||
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
|
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
|
||||||
|
@ -218,12 +220,12 @@ public class UserInterceptor implements WebRequestInterceptor {
|
||||||
user = this.entityManager.merge(user);
|
user = this.entityManager.merge(user);
|
||||||
this.entityManager.flush();
|
this.entityManager.flush();
|
||||||
userRole.setUserInfo(user);
|
userRole.setUserInfo(user);
|
||||||
credential.setUserInfo(user);
|
credentialEntity.setUserId(user.getId());
|
||||||
this.entityManager.merge(userRole);
|
this.entityManager.merge(userRole);
|
||||||
this.entityManager.merge(credential);
|
this.entityManager.merge(credentialEntity);
|
||||||
} else {
|
} else {
|
||||||
this.entityManager.persist(user);
|
this.entityManager.persist(user);
|
||||||
this.entityManager.persist(credential);
|
this.entityManager.persist(credentialEntity);
|
||||||
}
|
}
|
||||||
this.entityManager.flush();
|
this.entityManager.flush();
|
||||||
transactionManager.commit(status);
|
transactionManager.commit(status);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package eu.eudat.logic.builders.entity;
|
package eu.eudat.logic.builders.entity;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.ProviderType;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.data.CredentialEntity;
|
||||||
import eu.eudat.logic.builders.Builder;
|
import eu.eudat.logic.builders.Builder;
|
||||||
import eu.eudat.data.entities.Credential;
|
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -10,15 +12,15 @@ import java.util.UUID;
|
||||||
/**
|
/**
|
||||||
* Created by ikalyvas on 2/15/2018.
|
* Created by ikalyvas on 2/15/2018.
|
||||||
*/
|
*/
|
||||||
public class CredentialBuilder extends Builder<Credential> {
|
public class CredentialBuilder extends Builder<CredentialEntity> {
|
||||||
|
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
|
||||||
private UserInfo userInfo;
|
private UserInfo userInfo;
|
||||||
|
|
||||||
private Integer status;
|
private IsActive isActive;
|
||||||
|
|
||||||
private Integer provider;
|
private ProviderType provider;
|
||||||
|
|
||||||
private String publicValue;
|
private String publicValue;
|
||||||
|
|
||||||
|
@ -42,12 +44,12 @@ public class CredentialBuilder extends Builder<Credential> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CredentialBuilder status(Integer status) {
|
public CredentialBuilder status(IsActive isActive) {
|
||||||
this.status = status;
|
this.isActive = isActive;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CredentialBuilder provider(Integer provider) {
|
public CredentialBuilder provider(ProviderType provider) {
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -82,15 +84,15 @@ public class CredentialBuilder extends Builder<Credential> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Credential build() {
|
public CredentialEntity build() {
|
||||||
Credential credential = new Credential();
|
CredentialEntity credential = new CredentialEntity();
|
||||||
credential.setStatus(status);
|
credential.setIsActive(isActive);
|
||||||
credential.setLastUpdateTime(lastUpdateTime);
|
credential.setLastUpdateTime(lastUpdateTime);
|
||||||
credential.setCreationTime(creationTime);
|
credential.setCreationTime(creationTime);
|
||||||
credential.setProvider(provider);
|
credential.setProvider(provider);
|
||||||
credential.setSecret(secret);
|
credential.setSecret(secret);
|
||||||
credential.setPublicValue(publicValue);
|
credential.setPublicValue(publicValue);
|
||||||
credential.setUserInfo(userInfo);
|
credential.setUserId(userInfo.getId());
|
||||||
credential.setId(id);
|
credential.setId(id);
|
||||||
credential.setExternalId(externalId);
|
credential.setExternalId(externalId);
|
||||||
credential.setEmail(email);
|
credential.setEmail(email);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.logic.builders.entity;
|
package eu.eudat.logic.builders.entity;
|
||||||
|
|
||||||
|
import eu.eudat.data.CredentialEntity;
|
||||||
import eu.eudat.logic.builders.Builder;
|
import eu.eudat.logic.builders.Builder;
|
||||||
import eu.eudat.data.entities.Credential;
|
|
||||||
import eu.eudat.data.entities.DMP;
|
import eu.eudat.data.entities.DMP;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
import eu.eudat.data.entities.UserRole;
|
import eu.eudat.data.entities.UserRole;
|
||||||
|
@ -36,7 +36,7 @@ public class UserInfoBuilder extends Builder<UserInfo> {
|
||||||
|
|
||||||
private Set<DMP> dmps;
|
private Set<DMP> dmps;
|
||||||
|
|
||||||
private Set<Credential> credentials = new HashSet<>();
|
private Set<CredentialEntity> credentials = new HashSet<>();
|
||||||
|
|
||||||
private Set<UserRole> userRoles = new HashSet<>();
|
private Set<UserRole> userRoles = new HashSet<>();
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ public class UserInfoBuilder extends Builder<UserInfo> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserInfoBuilder credentials(Set<Credential> credentials) {
|
public UserInfoBuilder credentials(Set<CredentialEntity> credentials) {
|
||||||
this.credentials = credentials;
|
this.credentials = credentials;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,6 @@ public class PrincipalBuilder extends Builder<Principal> {
|
||||||
private String culture;
|
private String culture;
|
||||||
private String language;
|
private String language;
|
||||||
private String timezone;
|
private String timezone;
|
||||||
private String zenodoToken;
|
|
||||||
private Instant zenodoDuration;
|
|
||||||
private String zenodoEmail;
|
|
||||||
private String zenodoRefresh;
|
|
||||||
|
|
||||||
public PrincipalBuilder id(UUID id) {
|
public PrincipalBuilder id(UUID id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -79,25 +75,6 @@ public class PrincipalBuilder extends Builder<Principal> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrincipalBuilder zenodoToken(String zenodoToken) {
|
|
||||||
this.zenodoToken = zenodoToken;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrincipalBuilder zenodoDuration(Instant zenodoDuration) {
|
|
||||||
this.zenodoDuration = zenodoDuration;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrincipalBuilder zenodoEmail(String zenodoEmail) {
|
|
||||||
this.zenodoEmail = zenodoEmail;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrincipalBuilder zenodoRefresh(String zenodoRefresh) {
|
|
||||||
this.zenodoRefresh = zenodoRefresh;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Principal build() {
|
public Principal build() {
|
||||||
|
@ -112,10 +89,6 @@ public class PrincipalBuilder extends Builder<Principal> {
|
||||||
principal.setCulture(culture);
|
principal.setCulture(culture);
|
||||||
principal.setLanguage(language);
|
principal.setLanguage(language);
|
||||||
principal.setTimezone(timezone);
|
principal.setTimezone(timezone);
|
||||||
principal.setZenodoToken(zenodoToken);
|
|
||||||
principal.setZenodoDuration(zenodoDuration);
|
|
||||||
principal.setZenodoEmail(zenodoEmail);
|
|
||||||
principal.setZenodoRefresh(zenodoRefresh);
|
|
||||||
return principal;
|
return principal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.eudat.logic.handlers;
|
package eu.eudat.logic.handlers;
|
||||||
|
|
||||||
import eu.eudat.commons.scope.UserScope;
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||||
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class AdminManager {
|
||||||
|
|
||||||
DescriptionTemplateTypeEntity type;
|
DescriptionTemplateTypeEntity type;
|
||||||
try {
|
try {
|
||||||
type = descriptionTemplateTypeService.getEntityByName(profile.getType());
|
//TODO: dtziotzios type = descriptionTemplateTypeService.getEntityByName(profile.getType());
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new Exception("Description template type '" + profile.getType() + "' could not be found.");
|
throw new Exception("Description template type '" + profile.getType() + "' could not be found.");
|
||||||
|
@ -47,7 +47,7 @@ public class AdminManager {
|
||||||
|
|
||||||
DescriptionTemplate descriptionTemplate = apiContext.getOperationsContext().getBuilderFactory().getBuilder(DatasetProfileBuilder.class).definition(xml).label(profile.getLabel())
|
DescriptionTemplate descriptionTemplate = apiContext.getOperationsContext().getBuilderFactory().getBuilder(DatasetProfileBuilder.class).definition(xml).label(profile.getLabel())
|
||||||
.status(profile.getStatus()).created(new Date()).description(profile.getDescription()).language(profile.getLanguage())
|
.status(profile.getStatus()).created(new Date()).description(profile.getDescription()).language(profile.getLanguage())
|
||||||
.type(type)
|
//TODO: dtziotzios .type(type)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (descriptionTemplate.getGroupId() == null) {
|
if (descriptionTemplate.getGroupId() == null) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import eu.eudat.data.entities.Credential;
|
import eu.eudat.data.CredentialEntity;
|
||||||
import eu.eudat.data.entities.EmailConfirmation;
|
import eu.eudat.data.entities.EmailConfirmation;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
||||||
|
@ -45,7 +45,7 @@ public class EmailConfirmationManager {
|
||||||
// Checks if mail is used by another user. If it is, merges the new the old.
|
// Checks if mail is used by another user. If it is, merges the new the old.
|
||||||
Long existingUsers = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).count();
|
Long existingUsers = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).count();
|
||||||
if (existingUsers > 0) {
|
if (existingUsers > 0) {
|
||||||
Credential credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userInfo"), user)).getSingle();
|
CredentialEntity credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userId"), user.getId())).getSingle();
|
||||||
credential.setEmail(loginConfirmationEmail.getEmail());
|
credential.setEmail(loginConfirmationEmail.getEmail());
|
||||||
databaseRepository.getCredentialDao().createOrUpdate(credential);
|
databaseRepository.getCredentialDao().createOrUpdate(credential);
|
||||||
UserInfo oldUser = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).getSingle();
|
UserInfo oldUser = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).getSingle();
|
||||||
|
@ -57,8 +57,8 @@ public class EmailConfirmationManager {
|
||||||
|
|
||||||
user.setEmail(loginConfirmationEmail.getEmail());
|
user.setEmail(loginConfirmationEmail.getEmail());
|
||||||
databaseRepository.getUserInfoDao().createOrUpdate(user);
|
databaseRepository.getUserInfoDao().createOrUpdate(user);
|
||||||
Credential credential = databaseRepository.getCredentialDao().asQueryable()
|
CredentialEntity credential = databaseRepository.getCredentialDao().asQueryable()
|
||||||
.where((builder, root) -> builder.equal(root.get("userInfo"), user)).getSingle();
|
.where((builder, root) -> builder.equal(root.get("userId"), user.getId())).getSingle();
|
||||||
if(credential.getEmail() == null){
|
if(credential.getEmail() == null){
|
||||||
credential.setEmail(user.getEmail());
|
credential.setEmail(user.getEmail());
|
||||||
databaseRepository.getCredentialDao().createOrUpdate(credential);
|
databaseRepository.getCredentialDao().createOrUpdate(credential);
|
||||||
|
@ -80,8 +80,8 @@ public class EmailConfirmationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeNewUserToOld(UserInfo newUser, UserInfo oldUser) {
|
private void mergeNewUserToOld(UserInfo newUser, UserInfo oldUser) {
|
||||||
Credential credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userInfo"), newUser)).getSingle();
|
CredentialEntity credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userId"), newUser.getId())).getSingle();
|
||||||
credential.setUserInfo(oldUser);
|
credential.setUserId(oldUser.getId());
|
||||||
databaseRepository.getCredentialDao().createOrUpdate(credential);
|
databaseRepository.getCredentialDao().createOrUpdate(credential);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import eu.eudat.data.entities.Credential;
|
import eu.eudat.data.CredentialEntity;
|
||||||
import eu.eudat.data.entities.EmailConfirmation;
|
import eu.eudat.data.entities.EmailConfirmation;
|
||||||
import eu.eudat.data.entities.UserDMP;
|
import eu.eudat.data.entities.UserDMP;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
|
@ -86,8 +86,8 @@ public class MergeEmailConfirmationManager {
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private void mergeNewUserToOld(UserInfo newUser, UserInfo oldUser, Integer provider) {
|
private void mergeNewUserToOld(UserInfo newUser, UserInfo oldUser, Integer provider) {
|
||||||
Credential credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.and(builder.equal(root.get("userInfo"), oldUser), builder.equal(root.get("provider"), provider))).getSingle();
|
CredentialEntity credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.and(builder.equal(root.get("userId"), oldUser.getId()), builder.equal(root.get("provider"), provider))).getSingle();
|
||||||
credential.setUserInfo(newUser);
|
credential.setUserId(newUser.getId());
|
||||||
databaseRepository.getCredentialDao().createOrUpdate(credential);
|
databaseRepository.getCredentialDao().createOrUpdate(credential);
|
||||||
List<UserDMP> userDmps = databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("user"), oldUser)).toList();
|
List<UserDMP> userDmps = databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("user"), oldUser)).toList();
|
||||||
userDmps.forEach(userDmp -> {
|
userDmps.forEach(userDmp -> {
|
||||||
|
@ -128,7 +128,7 @@ public class MergeEmailConfirmationManager {
|
||||||
}
|
}
|
||||||
oldUser.setUserStatus((short)1);
|
oldUser.setUserStatus((short)1);
|
||||||
oldUser.setEmail(null);
|
oldUser.setEmail(null);
|
||||||
List<Credential> credentials = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userInfo"), oldUser)).toList();
|
List<CredentialEntity> credentials = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userId"), oldUser.getId())).toList();
|
||||||
credentials.forEach(cred -> {
|
credentials.forEach(cred -> {
|
||||||
if (cred.getId() != credential.getId()) {
|
if (cred.getId() != credential.getId()) {
|
||||||
databaseRepository.getCredentialDao().delete(cred);
|
databaseRepository.getCredentialDao().delete(cred);
|
||||||
|
|
|
@ -2,7 +2,7 @@ package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.data.entities.Credential;
|
import eu.eudat.data.CredentialEntity;
|
||||||
import eu.eudat.data.entities.EmailConfirmation;
|
import eu.eudat.data.entities.EmailConfirmation;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
||||||
|
@ -64,7 +64,7 @@ public class UnlinkEmailConfirmationManager {
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private void unlinkUser(String emailTobeUnlinked, Integer provider){
|
private void unlinkUser(String emailTobeUnlinked, Integer provider){
|
||||||
Credential credential = databaseRepository.getCredentialDao().asQueryable()
|
CredentialEntity credential = databaseRepository.getCredentialDao().asQueryable()
|
||||||
.where((builder, root) -> builder.and(builder.equal(root.get("email"), emailTobeUnlinked), builder.equal(root.get("provider"), provider))).getSingle();
|
.where((builder, root) -> builder.and(builder.equal(root.get("email"), emailTobeUnlinked), builder.equal(root.get("provider"), provider))).getSingle();
|
||||||
if(credential != null) {
|
if(credential != null) {
|
||||||
databaseRepository.getCredentialDao().delete(credential);
|
databaseRepository.getCredentialDao().delete(credential);
|
||||||
|
|
|
@ -1,33 +1,28 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import eu.eudat.data.CredentialEntity;
|
||||||
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
|
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
|
||||||
import eu.eudat.data.dao.entities.UserInfoDao;
|
import eu.eudat.data.dao.entities.UserInfoDao;
|
||||||
import eu.eudat.data.entities.*;
|
import eu.eudat.data.entities.DMP;
|
||||||
|
import eu.eudat.data.entities.DescriptionTemplate;
|
||||||
|
import eu.eudat.data.entities.UserInfo;
|
||||||
|
import eu.eudat.data.entities.UserRole;
|
||||||
import eu.eudat.data.query.items.table.userinfo.UserInfoTableRequestItem;
|
import eu.eudat.data.query.items.table.userinfo.UserInfoTableRequestItem;
|
||||||
import eu.eudat.exceptions.security.NullEmailException;
|
|
||||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||||
import eu.eudat.logic.builders.entity.UserRoleBuilder;
|
import eu.eudat.logic.builders.entity.UserRoleBuilder;
|
||||||
import eu.eudat.logic.builders.model.models.DataTableDataBuilder;
|
import eu.eudat.logic.builders.model.models.DataTableDataBuilder;
|
||||||
import eu.eudat.logic.security.customproviders.Zenodo.ZenodoAccessType;
|
|
||||||
import eu.eudat.logic.security.customproviders.Zenodo.ZenodoCustomProvider;
|
|
||||||
import eu.eudat.logic.security.validators.zenodo.helpers.ZenodoResponseToken;
|
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
|
||||||
import eu.eudat.logic.utilities.builders.XmlBuilder;
|
import eu.eudat.logic.utilities.builders.XmlBuilder;
|
||||||
import eu.eudat.models.HintedModelFactory;
|
import eu.eudat.models.HintedModelFactory;
|
||||||
import eu.eudat.models.data.dmp.DataManagementPlan;
|
import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||||
import eu.eudat.models.data.doi.DOIRequest;
|
|
||||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||||
import eu.eudat.models.data.login.Credentials;
|
|
||||||
import eu.eudat.models.data.principal.PrincipalModel;
|
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.models.data.userinfo.UserCredential;
|
import eu.eudat.models.data.userinfo.UserCredential;
|
||||||
import eu.eudat.models.data.userinfo.UserListingModel;
|
import eu.eudat.models.data.userinfo.UserListingModel;
|
||||||
import eu.eudat.models.data.userinfo.UserProfile;
|
import eu.eudat.models.data.userinfo.UserProfile;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
import eu.eudat.types.Authorities;
|
import eu.eudat.types.Authorities;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -41,14 +36,8 @@ import org.springframework.stereotype.Component;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -57,13 +46,11 @@ public class UserManager {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(UserManager.class);
|
private static final Logger logger = LoggerFactory.getLogger(UserManager.class);
|
||||||
|
|
||||||
private ApiContext apiContext;
|
private ApiContext apiContext;
|
||||||
private ZenodoCustomProvider zenodoCustomProvider;
|
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public UserManager(ApiContext apiContext, ZenodoCustomProvider zenodoCustomProvider, Environment environment) {
|
public UserManager(ApiContext apiContext, Environment environment) {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
this.zenodoCustomProvider = zenodoCustomProvider;
|
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +76,7 @@ public class UserManager {
|
||||||
public List<UserCredential> getCredentials(UUID userId) {
|
public List<UserCredential> getCredentials(UUID userId) {
|
||||||
List<UserCredential> results = new ArrayList<>();
|
List<UserCredential> results = new ArrayList<>();
|
||||||
eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId);
|
eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId);
|
||||||
List<Credential> credentials = apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userInfo"), user)).toList();
|
List<CredentialEntity> credentials = apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userId"), user.getId())).toList();
|
||||||
credentials.forEach(credential -> {
|
credentials.forEach(credential -> {
|
||||||
UserCredential userCredential = new UserCredential();
|
UserCredential userCredential = new UserCredential();
|
||||||
userCredential.setEmail(credential.getEmail());
|
userCredential.setEmail(credential.getEmail());
|
||||||
|
@ -147,27 +134,6 @@ public class UserManager {
|
||||||
return dataTableData;
|
return dataTableData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerDOIToken(DOIRequest doiRequest, Principal principal) throws IOException { //TODO: Authn
|
|
||||||
ZenodoResponseToken responseToken = this.zenodoCustomProvider.getAccessToken(ZenodoAccessType.AUTHORIZATION_CODE,
|
|
||||||
doiRequest.getZenodoRequest().getCode(), this.environment.getProperty("zenodo.login.client_id"),
|
|
||||||
this.environment.getProperty("zenodo.login.client_secret"), doiRequest.getRedirectUri());
|
|
||||||
Map<String, Object> settings = new HashMap<>();
|
|
||||||
settings.put("zenodoEmail", responseToken.getEmail());
|
|
||||||
settings.put("zenodoRefresh", responseToken.getRefreshToken());
|
|
||||||
settings.put("zenodoToken", responseToken.getAccessToken());
|
|
||||||
settings.put("expirationDate", Instant.now().plusSeconds(responseToken.getExpiresIn()).toEpochMilli());
|
|
||||||
this.updateSettings(settings, principal);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteDOIToken(Principal principal) throws IOException {
|
|
||||||
Map<String, Object> settings = new HashMap<>();
|
|
||||||
settings.put("zenodoEmail", "");
|
|
||||||
settings.put("zenodoRefresh", "");
|
|
||||||
settings.put("zenodoToken", "");
|
|
||||||
settings.put("expirationDate", 0);
|
|
||||||
this.updateSettings(settings, principal);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponseEntity<byte[]> exportToCsv(Principal principal) throws IOException {
|
public ResponseEntity<byte[]> exportToCsv(Principal principal) throws IOException {
|
||||||
if (!principal.getAuthz().contains(Authorities.ADMIN))
|
if (!principal.getAuthz().contains(Authorities.ADMIN))
|
||||||
throw new UnauthorisedException();
|
throw new UnauthorisedException();
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package eu.eudat.logic.security.customproviders.Zenodo;
|
|
||||||
|
|
||||||
public enum ZenodoAccessType {
|
|
||||||
AUTHORIZATION_CODE("authorization_code", "code"),
|
|
||||||
REFRESH_TOKEN("refresh_token", "refresh_token");
|
|
||||||
|
|
||||||
private final String grantType;
|
|
||||||
private final String property;
|
|
||||||
|
|
||||||
ZenodoAccessType(String grantType, String property) {
|
|
||||||
this.grantType = grantType;
|
|
||||||
this.property = property;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGrantType() {
|
|
||||||
return grantType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getProperty() {
|
|
||||||
return property;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package eu.eudat.logic.security.customproviders.Zenodo;
|
|
||||||
|
|
||||||
import eu.eudat.logic.security.validators.zenodo.helpers.ZenodoResponseToken;
|
|
||||||
|
|
||||||
public interface ZenodoCustomProvider {
|
|
||||||
ZenodoResponseToken getAccessToken(ZenodoAccessType accessType, String code, String clientId, String clientSecret, String redirectUri);
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
package eu.eudat.logic.security.customproviders.Zenodo;
|
|
||||||
|
|
||||||
import eu.eudat.logic.security.validators.zenodo.helpers.ZenodoResponseToken;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.http.HttpEntity;
|
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
|
||||||
import org.springframework.util.MultiValueMap;
|
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Component("ZenodoCustomProvider")
|
|
||||||
public class ZenodoCustomProviderImpl implements ZenodoCustomProvider {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ZenodoCustomProviderImpl.class);
|
|
||||||
|
|
||||||
private Environment environment;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public ZenodoCustomProviderImpl(Environment environment) {
|
|
||||||
this.environment = environment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ZenodoResponseToken getAccessToken(ZenodoAccessType accessType, String code, String clientId, String clientSecret, String redirectUri) {
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
|
||||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
|
||||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
||||||
|
|
||||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
|
||||||
map.add("client_id", clientId);
|
|
||||||
map.add("client_secret", clientSecret);
|
|
||||||
map.add("grant_type", accessType.getGrantType());
|
|
||||||
map.add(accessType.getProperty(), code);
|
|
||||||
map.add("redirect_uri", redirectUri);
|
|
||||||
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Map<String, Object> values = restTemplate.postForObject(this.environment.getProperty("zenodo.login.access_token_url"), request, Map.class);
|
|
||||||
ZenodoResponseToken zenodoResponseToken = new ZenodoResponseToken();
|
|
||||||
Map<String, Object> user = (Map<String, Object>) values.get("user");
|
|
||||||
zenodoResponseToken.setUserId((String) user.get("id"));
|
|
||||||
zenodoResponseToken.setEmail((String) user.get("email"));
|
|
||||||
zenodoResponseToken.setExpiresIn((Integer) values.get("expires_in"));
|
|
||||||
zenodoResponseToken.setAccessToken((String) values.get("access_token"));
|
|
||||||
zenodoResponseToken.setRefreshToken((String) values.get("refresh_token"));
|
|
||||||
|
|
||||||
return zenodoResponseToken;
|
|
||||||
} catch (HttpClientErrorException ex) {
|
|
||||||
logger.error(ex.getResponseBodyAsString(), ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private HttpHeaders createBearerAuthHeaders(String accessToken) {
|
|
||||||
return new HttpHeaders() {{
|
|
||||||
String authHeader = "Bearer " + accessToken;
|
|
||||||
set("Authorization", authHeader);
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
package eu.eudat.logic.security.customproviders.Zenodo;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ZenodoUser {
|
|
||||||
private String userId;
|
|
||||||
private String email;
|
|
||||||
private String accessToken;
|
|
||||||
private Integer expiresIn;
|
|
||||||
private String refreshToken;
|
|
||||||
|
|
||||||
public String getUserId() {
|
|
||||||
return userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserId(String userId) {
|
|
||||||
this.userId = userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAccessToken() {
|
|
||||||
return accessToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAccessToken(String accessToken) {
|
|
||||||
this.accessToken = accessToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getExpiresIn() {
|
|
||||||
return expiresIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExpiresIn(Integer expiresIn) {
|
|
||||||
this.expiresIn = expiresIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRefreshToken() {
|
|
||||||
return refreshToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRefreshToken(String refreshToken) {
|
|
||||||
this.refreshToken = refreshToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ZenodoUser getZenodoUser(Object data) {
|
|
||||||
this.userId = (String) ((Map) data).get("userId");
|
|
||||||
this.email = (String) ((Map) data).get("email");
|
|
||||||
this.accessToken = (String) ((Map) data).get("accessToken");
|
|
||||||
this.expiresIn = (Integer) ((Map) data).get("expiresIn");
|
|
||||||
this.refreshToken = (String) ((Map) data).get("refreshToken");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package eu.eudat.logic.security.validators.zenodo.helpers;
|
|
||||||
|
|
||||||
public class ZenodoRequest {
|
|
||||||
private String code;
|
|
||||||
|
|
||||||
public String getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
public void setCode(String code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
package eu.eudat.logic.security.validators.zenodo.helpers;
|
|
||||||
|
|
||||||
public class ZenodoResponseToken {
|
|
||||||
private String userId;
|
|
||||||
private String email;
|
|
||||||
private Integer expiresIn;
|
|
||||||
private String accessToken;
|
|
||||||
private String refreshToken;
|
|
||||||
|
|
||||||
public String getUserId() {
|
|
||||||
return userId;
|
|
||||||
}
|
|
||||||
public void setUserId(String userId) {
|
|
||||||
this.userId = userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getExpiresIn() {
|
|
||||||
return expiresIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExpiresIn(Integer expiresIn) {
|
|
||||||
this.expiresIn = expiresIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAccessToken() {
|
|
||||||
return accessToken;
|
|
||||||
}
|
|
||||||
public void setAccessToken(String accessToken) {
|
|
||||||
this.accessToken = accessToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRefreshToken() {
|
|
||||||
return refreshToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRefreshToken(String refreshToken) {
|
|
||||||
this.refreshToken = refreshToken;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -49,10 +49,6 @@ public class NonVerifiedUserEmailAuthenticationService extends AbstractAuthentic
|
||||||
.culture("")
|
.culture("")
|
||||||
.language("")
|
.language("")
|
||||||
.timezone("")
|
.timezone("")
|
||||||
.zenodoToken("")
|
|
||||||
.zenodoDuration(Instant.now())
|
|
||||||
.zenodoEmail("")
|
|
||||||
.zenodoRefresh("")
|
|
||||||
.build();
|
.build();
|
||||||
principalItem.setAuthorities(new HashSet<>());
|
principalItem.setAuthorities(new HashSet<>());
|
||||||
principalItem.getAuthz().add(Authorities.USER);
|
principalItem.getAuthz().add(Authorities.USER);
|
||||||
|
|
|
@ -38,30 +38,6 @@ public class VerifiedUserAuthenticationService extends AbstractAuthenticationSer
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
avatarUrl = "";
|
avatarUrl = "";
|
||||||
}
|
}
|
||||||
String zenodoToken;
|
|
||||||
try {
|
|
||||||
zenodoToken = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoToken").asText() : "";
|
|
||||||
} catch (Exception e) {
|
|
||||||
zenodoToken = "";
|
|
||||||
}
|
|
||||||
Instant zenodoDuration;
|
|
||||||
try {
|
|
||||||
zenodoDuration = user.getAdditionalinfo() != null ? Instant.ofEpochMilli(new ObjectMapper().readTree(user.getAdditionalinfo()).get("expirationDate").asLong()) : Instant.now();
|
|
||||||
} catch (Exception e) {
|
|
||||||
zenodoDuration = Instant.now();
|
|
||||||
}
|
|
||||||
String zenodoEmail;
|
|
||||||
try {
|
|
||||||
zenodoEmail = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoEmail").asText() : "";
|
|
||||||
} catch (Exception e) {
|
|
||||||
zenodoEmail = "";
|
|
||||||
}
|
|
||||||
String zenodoRefresh;
|
|
||||||
try {
|
|
||||||
zenodoRefresh = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoRefresh").asText() : "";
|
|
||||||
} catch (Exception e) {
|
|
||||||
zenodoRefresh = "";
|
|
||||||
}
|
|
||||||
String culture;
|
String culture;
|
||||||
try {
|
try {
|
||||||
culture = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("culture").get("name").asText() : "";
|
culture = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("culture").get("name").asText() : "";
|
||||||
|
@ -89,10 +65,6 @@ public class VerifiedUserAuthenticationService extends AbstractAuthenticationSer
|
||||||
.culture(culture)
|
.culture(culture)
|
||||||
.language(language)
|
.language(language)
|
||||||
.timezone(timezone)
|
.timezone(timezone)
|
||||||
.zenodoToken(zenodoToken)
|
|
||||||
.zenodoDuration(zenodoDuration)
|
|
||||||
.zenodoEmail(zenodoEmail)
|
|
||||||
.zenodoRefresh(zenodoRefresh)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
List<UserRole> userRoles = apiContext.getOperationsContext().getDatabaseRepository().getUserRoleDao().getUserRoles(user);
|
List<UserRole> userRoles = apiContext.getOperationsContext().getDatabaseRepository().getUserRoleDao().getUserRoles(user);
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package eu.eudat.models.data.doi;
|
|
||||||
|
|
||||||
import eu.eudat.logic.security.validators.zenodo.helpers.ZenodoRequest;
|
|
||||||
|
|
||||||
public class DOIRequest {
|
|
||||||
|
|
||||||
private ZenodoRequest zenodoRequest;
|
|
||||||
private String redirectUri;
|
|
||||||
|
|
||||||
public ZenodoRequest getZenodoRequest() {
|
|
||||||
return zenodoRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZenodoRequest(ZenodoRequest zenodoRequest) {
|
|
||||||
this.zenodoRequest = zenodoRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRedirectUri() {
|
|
||||||
return redirectUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRedirectUri(String redirectUri) {
|
|
||||||
this.redirectUri = redirectUri;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,9 +8,6 @@ public class LoginProviderUser {
|
||||||
private String secret;
|
private String secret;
|
||||||
private String avatarUrl;
|
private String avatarUrl;
|
||||||
private boolean isVerified;
|
private boolean isVerified;
|
||||||
private String zenodoId;
|
|
||||||
private Integer zenodoExpire;
|
|
||||||
private String zenodoRefresh;
|
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -59,28 +56,4 @@ public class LoginProviderUser {
|
||||||
public void setAvatarUrl(String avatarUrl) {
|
public void setAvatarUrl(String avatarUrl) {
|
||||||
this.avatarUrl = avatarUrl;
|
this.avatarUrl = avatarUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getZenodoId() {
|
|
||||||
return zenodoId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZenodoId(String zenodoId) {
|
|
||||||
this.zenodoId = zenodoId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getZenodoExpire() {
|
|
||||||
return zenodoExpire;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZenodoExpire(Integer zenodoExpire) {
|
|
||||||
this.zenodoExpire = zenodoExpire;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getZenodoRefresh() {
|
|
||||||
return zenodoRefresh;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZenodoRefresh(String zenodoRefresh) {
|
|
||||||
this.zenodoRefresh = zenodoRefresh;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ public class PrincipalModel {
|
||||||
private String culture;
|
private String culture;
|
||||||
private String language;
|
private String language;
|
||||||
private String timezone;
|
private String timezone;
|
||||||
private String zenodoEmail;
|
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -105,14 +104,6 @@ public class PrincipalModel {
|
||||||
this.timezone = timezone;
|
this.timezone = timezone;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getZenodoEmail() {
|
|
||||||
return zenodoEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZenodoEmail(String zenodoEmail) {
|
|
||||||
this.zenodoEmail = zenodoEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PrincipalModel fromEntity(Principal principal) {
|
public static PrincipalModel fromEntity(Principal principal) {
|
||||||
PrincipalModel model = new PrincipalModel();
|
PrincipalModel model = new PrincipalModel();
|
||||||
model.setId(principal.getId());
|
model.setId(principal.getId());
|
||||||
|
@ -125,7 +116,6 @@ public class PrincipalModel {
|
||||||
model.setLanguage(principal.getLanguage());
|
model.setLanguage(principal.getLanguage());
|
||||||
model.setName(principal.getName());
|
model.setName(principal.getName());
|
||||||
model.setTimezone(principal.getTimezone());
|
model.setTimezone(principal.getTimezone());
|
||||||
model.setZenodoEmail(principal.getZenodoEmail());
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,6 @@ public class Principal {
|
||||||
private String culture;
|
private String culture;
|
||||||
private String language;
|
private String language;
|
||||||
private String timezone;
|
private String timezone;
|
||||||
private String zenodoToken;
|
|
||||||
private Instant zenodoDuration;
|
|
||||||
private String zenodoRefresh;
|
|
||||||
private String zenodoEmail;
|
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -100,38 +96,6 @@ public class Principal {
|
||||||
this.timezone = timezone;
|
this.timezone = timezone;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getZenodoToken() {
|
|
||||||
return zenodoToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZenodoToken(String zenodoToken) {
|
|
||||||
this.zenodoToken = zenodoToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Instant getZenodoDuration() {
|
|
||||||
return zenodoDuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZenodoDuration(Instant zenodoDuration) {
|
|
||||||
this.zenodoDuration = zenodoDuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getZenodoRefresh() {
|
|
||||||
return zenodoRefresh;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZenodoRefresh(String zenodoRefresh) {
|
|
||||||
this.zenodoRefresh = zenodoRefresh;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getZenodoEmail() {
|
|
||||||
return zenodoEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZenodoEmail(String zenodoEmail) {
|
|
||||||
this.zenodoEmail = zenodoEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public Set<Authorities> getAuthz() {
|
public Set<Authorities> getAuthz() {
|
||||||
return this.authorities;
|
return this.authorities;
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
package eu.eudat.models.data.userinfo;
|
package eu.eudat.models.data.userinfo;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.ProviderType;
|
||||||
|
|
||||||
public class UserCredential {
|
public class UserCredential {
|
||||||
private String email;
|
private String email;
|
||||||
private Integer provider;
|
private ProviderType provider;
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
public void setEmail(String email) {
|
public void setEmail(String email) {
|
||||||
this.email = email;
|
this.email = email;
|
||||||
}
|
}
|
||||||
public Integer getProvider() {
|
public ProviderType getProvider() {
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
public void setProvider(Integer provider) {
|
public void setProvider(ProviderType provider) {
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ public class UserProfile implements DataModel<eu.eudat.data.entities.UserInfo, U
|
||||||
private Date lastloggedin;
|
private Date lastloggedin;
|
||||||
//private String additionalinfo;
|
//private String additionalinfo;
|
||||||
private List<DataManagementPlan> associatedDmps;
|
private List<DataManagementPlan> associatedDmps;
|
||||||
private String zenodoEmail;
|
|
||||||
private Map<String, Object> language;
|
private Map<String, Object> language;
|
||||||
private String timezone;
|
private String timezone;
|
||||||
private Map<String, Object> culture;
|
private Map<String, Object> culture;
|
||||||
|
@ -92,13 +91,6 @@ public class UserProfile implements DataModel<eu.eudat.data.entities.UserInfo, U
|
||||||
this.associatedDmps = associatedDmps;
|
this.associatedDmps = associatedDmps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getZenodoEmail() {
|
|
||||||
return zenodoEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZenodoEmail(String zenodoEmail) {
|
|
||||||
this.zenodoEmail = zenodoEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Object> getLanguage() {
|
public Map<String, Object> getLanguage() {
|
||||||
return language;
|
return language;
|
||||||
|
@ -163,7 +155,6 @@ public class UserProfile implements DataModel<eu.eudat.data.entities.UserInfo, U
|
||||||
this.language = (Map)additionalInfo.get("language");
|
this.language = (Map)additionalInfo.get("language");
|
||||||
this.culture = (Map) additionalInfo.get("culture");
|
this.culture = (Map) additionalInfo.get("culture");
|
||||||
this.timezone = (String) additionalInfo.get("timezone");
|
this.timezone = (String) additionalInfo.get("timezone");
|
||||||
this.zenodoEmail = (String) additionalInfo.get("zenodoEmail");
|
|
||||||
this.avatarUrl = (String) additionalInfo.get("avatarUrl");
|
this.avatarUrl = (String) additionalInfo.get("avatarUrl");
|
||||||
this.organization = Organisation.fromMap((HashMap<String, Object>) additionalInfo.get("organization"));
|
this.organization = Organisation.fromMap((HashMap<String, Object>) additionalInfo.get("organization"));
|
||||||
this.roleOrganization = (String) additionalInfo.get("roleOrganization");
|
this.roleOrganization = (String) additionalInfo.get("roleOrganization");
|
||||||
|
|
|
@ -139,6 +139,9 @@ public class Account {
|
||||||
public final static String _principal = "principal";
|
public final static String _principal = "principal";
|
||||||
private PrincipalInfo principal;
|
private PrincipalInfo principal;
|
||||||
|
|
||||||
|
public final static String _permissions = "permissions";
|
||||||
|
private List<String> permissions;
|
||||||
|
|
||||||
public PrincipalInfo getPrincipal() {
|
public PrincipalInfo getPrincipal() {
|
||||||
return principal;
|
return principal;
|
||||||
}
|
}
|
||||||
|
@ -162,4 +165,16 @@ public class Account {
|
||||||
public void setRoles(List<Integer> roles) {
|
public void setRoles(List<Integer> roles) {
|
||||||
this.roles = roles;
|
this.roles = roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAuthenticated(Boolean authenticated) {
|
||||||
|
isAuthenticated = authenticated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getPermissions() {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissions(List<String> permissions) {
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package eu.eudat.models.v2;
|
package eu.eudat.models.v2;
|
||||||
|
|
||||||
import eu.eudat.commons.scope.UserScope;
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
import eu.eudat.data.entities.UserRole;
|
import eu.eudat.data.entities.UserRole;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.types.Authorities;
|
import gr.cite.commons.web.authz.configuration.AuthorizationConfiguration;
|
||||||
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
|
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
|
||||||
import gr.cite.commons.web.oidc.principal.MyPrincipal;
|
import gr.cite.commons.web.oidc.principal.MyPrincipal;
|
||||||
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractor;
|
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractor;
|
||||||
|
@ -24,11 +24,13 @@ public class AccountBuilder {
|
||||||
private final ClaimExtractor claimExtractor;
|
private final ClaimExtractor claimExtractor;
|
||||||
private final Set<String> excludeMoreClaim;
|
private final Set<String> excludeMoreClaim;
|
||||||
private final CurrentPrincipalResolver currentPrincipalResolver;
|
private final CurrentPrincipalResolver currentPrincipalResolver;
|
||||||
|
private final AuthorizationConfiguration authorizationConfiguration;
|
||||||
private final ApiContext apiContext;
|
private final ApiContext apiContext;
|
||||||
private final UserScope userScope;
|
private final UserScope userScope;
|
||||||
public AccountBuilder(ClaimExtractor claimExtractor, CurrentPrincipalResolver currentPrincipalResolver, ApiContext apiContext, UserScope userScope) {
|
public AccountBuilder(ClaimExtractor claimExtractor, CurrentPrincipalResolver currentPrincipalResolver, AuthorizationConfiguration authorizationConfiguration, ApiContext apiContext, UserScope userScope) {
|
||||||
this.claimExtractor = claimExtractor;
|
this.claimExtractor = claimExtractor;
|
||||||
this.currentPrincipalResolver = currentPrincipalResolver;
|
this.currentPrincipalResolver = currentPrincipalResolver;
|
||||||
|
this.authorizationConfiguration = authorizationConfiguration;
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
this.userScope = userScope;
|
this.userScope = userScope;
|
||||||
this.excludeMoreClaim = Set.of(
|
this.excludeMoreClaim = Set.of(
|
||||||
|
@ -93,6 +95,11 @@ public class AccountBuilder {
|
||||||
model.getRoles().add(item.getRole());
|
model.getRoles().add(item.getRole());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (fields.hasField(Account._permissions)) {
|
||||||
|
List<String> roles = claimExtractor.roles(currentPrincipalResolver.currentPrincipal());
|
||||||
|
Set<String> permissions = authorizationConfiguration.permissionsOfRoles(roles);
|
||||||
|
model.setPermissions(new ArrayList<>(permissions));
|
||||||
|
}
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ spring:
|
||||||
config:
|
config:
|
||||||
import: optional:classpath:config/app.env[.properties], optional:file:../config/app.env[.properties],
|
import: optional:classpath:config/app.env[.properties], optional:file:../config/app.env[.properties],
|
||||||
optional:classpath:config/db.yml[.yml], optional:classpath:config/db-${spring.profiles.active}.yml[.yml], optional:file:../config/db-${spring.profiles.active}.yml[.yml],
|
optional:classpath:config/db.yml[.yml], optional:classpath:config/db-${spring.profiles.active}.yml[.yml], optional:file:../config/db-${spring.profiles.active}.yml[.yml],
|
||||||
|
optional:classpath:config/permissions.yml[.yml], optional:classpath:config/permissions-${spring.profiles.active}.yml[.yml], optional:file:../config/permissions-${spring.profiles.active}.yml[.yml],
|
||||||
optional:classpath:config/security.yml[.yml], optional:classpath:config/security-${spring.profiles.active}.yml[.yml], optional:file:../config/security-${spring.profiles.active}.yml[.yml],
|
optional:classpath:config/security.yml[.yml], optional:classpath:config/security-${spring.profiles.active}.yml[.yml], optional:file:../config/security-${spring.profiles.active}.yml[.yml],
|
||||||
optional:classpath:config/server.yml[.yml], optional:classpath:config/server-${spring.profiles.active}.yml[.yml], optional:file:../config/server-${spring.profiles.active}.yml[.yml],
|
optional:classpath:config/server.yml[.yml], optional:classpath:config/server-${spring.profiles.active}.yml[.yml], optional:file:../config/server-${spring.profiles.active}.yml[.yml],
|
||||||
optional:classpath:config/logging.yml[.yml], optional:classpath:config/logging-${spring.profiles.active}.yml[.yml], optional:file:../config/logging-${spring.profiles.active}.yml[.yml],
|
optional:classpath:config/logging.yml[.yml], optional:classpath:config/logging-${spring.profiles.active}.yml[.yml], optional:file:../config/logging-${spring.profiles.active}.yml[.yml],
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
permissions:
|
||||||
|
extendedClaims: [ ]
|
||||||
|
policies:
|
||||||
|
# Users
|
||||||
|
BrowseDescriptionTemplateType:
|
||||||
|
roles:
|
||||||
|
- Admin
|
||||||
|
clients: [ ]
|
||||||
|
allowAnonymous: true
|
||||||
|
allowAuthenticated: false
|
||||||
|
EditDescriptionTemplateType:
|
||||||
|
roles:
|
||||||
|
- Admin
|
||||||
|
clients: [ ]
|
||||||
|
allowAnonymous: false
|
||||||
|
allowAuthenticated: false
|
||||||
|
DeleteDescriptionTemplateType:
|
||||||
|
roles:
|
||||||
|
- Admin
|
||||||
|
claims: [ ]
|
||||||
|
clients: [ ]
|
||||||
|
allowAnonymous: false
|
||||||
|
allowAuthenticated: false
|
||||||
|
|
||||||
|
# ViewPage Permissions
|
||||||
|
ViewDescriptionTemplateTypePage:
|
||||||
|
roles:
|
||||||
|
- Admin
|
||||||
|
clients: [ ]
|
||||||
|
allowAnonymous: false
|
||||||
|
allowAuthenticated: false
|
|
@ -18,12 +18,3 @@ web:
|
||||||
jwt:
|
jwt:
|
||||||
claims: [ role, x-role ]
|
claims: [ role, x-role ]
|
||||||
issuer-uri: ${IDP_ISSUER_URI:}
|
issuer-uri: ${IDP_ISSUER_URI:}
|
||||||
|
|
||||||
zenodo:
|
|
||||||
affiliation: ARGOS
|
|
||||||
community: argos
|
|
||||||
login:
|
|
||||||
access_token_url: ${ZENODO_ACCESS_TOKEN_URL:}
|
|
||||||
client_id: ${ZENODO_CLIENT_ID:}
|
|
||||||
client_secret: ${ZENODO_CLIENT_SECRET:}
|
|
||||||
redirect_uri: http://localhost:4200/login/external/zenodo
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
ALTER TABLE public."DescriptionTemplateType"
|
||||||
|
RENAME "ID" TO id;
|
||||||
|
|
||||||
|
ALTER TABLE public."DescriptionTemplateType"
|
||||||
|
RENAME "Name" TO name;
|
||||||
|
|
||||||
|
ALTER TABLE public."DescriptionTemplateType"
|
||||||
|
RENAME "Status" TO is_active;
|
||||||
|
|
||||||
|
ALTER TABLE public."DescriptionTemplateType"
|
||||||
|
ADD COLUMN created_at timestamp without time zone;
|
||||||
|
|
||||||
|
ALTER TABLE public."DescriptionTemplateType"
|
||||||
|
ADD COLUMN updated_at timestamp without time zone;
|
||||||
|
|
||||||
|
UPDATE public."DescriptionTemplateType" SET created_at = now();
|
||||||
|
UPDATE public."DescriptionTemplateType" SET updated_at = now();
|
||||||
|
|
||||||
|
ALTER TABLE public."DescriptionTemplateType"
|
||||||
|
ALTER COLUMN created_at SET NOT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE public."DescriptionTemplateType"
|
||||||
|
ALTER COLUMN updated_at SET NOT NULL;
|
|
@ -3,6 +3,7 @@ import { RouterModule, Routes } from '@angular/router';
|
||||||
import { ReloadHelperComponent } from '@app/ui/misc/reload-helper/reload-helper.component';
|
import { ReloadHelperComponent } from '@app/ui/misc/reload-helper/reload-helper.component';
|
||||||
import { Oauth2DialogComponent } from './ui/misc/oauth2-dialog/oauth2-dialog.component';
|
import { Oauth2DialogComponent } from './ui/misc/oauth2-dialog/oauth2-dialog.component';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
import { AppPermission } from './core/common/enum/permission.enum';
|
||||||
|
|
||||||
const appRoutes: Routes = [
|
const appRoutes: Routes = [
|
||||||
{
|
{
|
||||||
|
@ -102,9 +103,12 @@ const appRoutes: Routes = [
|
||||||
loadChildren: () => import('./ui/admin/description-types/description-types.module').then(m => m.DescriptionTypesModule),
|
loadChildren: () => import('./ui/admin/description-types/description-types.module').then(m => m.DescriptionTypesModule),
|
||||||
data: {
|
data: {
|
||||||
breadcrumb: true,
|
breadcrumb: true,
|
||||||
title: 'GENERAL.TITLES.DESCRIPTION-TYPES'
|
title: 'GENERAL.TITLES.DESCRIPTION-TYPES',
|
||||||
|
authContext: {
|
||||||
|
permissions: [AppPermission.ViewDescriptionTemplateTypePage]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'contact-support',
|
path: 'contact-support',
|
||||||
loadChildren: () => import('./ui/contact/contact.module').then(m => m.ContactModule),
|
loadChildren: () => import('./ui/contact/contact.module').then(m => m.ContactModule),
|
||||||
|
@ -237,13 +241,6 @@ const appRoutes: Routes = [
|
||||||
breadcrumb: true
|
breadcrumb: true
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: 'login/admin',
|
|
||||||
loadChildren: () => import('./ui/auth/admin-login/admin-login.module').then(m => m.AdminLoginModule),
|
|
||||||
data: {
|
|
||||||
breadcrumb: true
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: 'login',
|
path: 'login',
|
||||||
loadChildren: () => import('./ui/auth/login/login.module').then(m => m.LoginModule),
|
loadChildren: () => import('./ui/auth/login/login.module').then(m => m.LoginModule),
|
||||||
|
@ -255,14 +252,6 @@ const appRoutes: Routes = [
|
||||||
{ path: 'logout', loadChildren: () => import('./ui/auth/logout/logout.module').then(m => m.LogoutModule) },
|
{ path: 'logout', loadChildren: () => import('./ui/auth/logout/logout.module').then(m => m.LogoutModule) },
|
||||||
{ path: 'reload', component: ReloadHelperComponent },
|
{ path: 'reload', component: ReloadHelperComponent },
|
||||||
{ path: 'oauth2', component: Oauth2DialogComponent },
|
{ path: 'oauth2', component: Oauth2DialogComponent },
|
||||||
{
|
|
||||||
path: 'external',
|
|
||||||
loadChildren: () => import('./ui/external/external.module').then(m => m.ExternalModule),
|
|
||||||
data: {
|
|
||||||
breadcrumb: true,
|
|
||||||
|
|
||||||
},
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { ActivatedRouteSnapshot, CanActivate, CanLoad, Route, Router, RouterStateSnapshot } from '@angular/router';
|
import { ActivatedRouteSnapshot, CanActivate, CanLoad, Route, Router, RouterStateSnapshot } from '@angular/router';
|
||||||
import { AuthService } from './services/auth/auth.service';
|
import { AuthService, ResolutionContext } from './services/auth/auth.service';
|
||||||
import { from, Observable, of as observableOf } from 'rxjs';
|
import { from, Observable, of as observableOf } from 'rxjs';
|
||||||
import { catchError, map, tap } from 'rxjs/operators';
|
import { catchError, map, tap } from 'rxjs/operators';
|
||||||
|
|
||||||
|
@ -11,25 +11,32 @@ export class AuthGuard implements CanActivate, CanLoad {
|
||||||
|
|
||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
|
||||||
const url: string = state.url;
|
const url: string = state.url;
|
||||||
return this.applyGuard(url);
|
const authContext = route.data ? route.data['authContext'] as ResolutionContext : null;
|
||||||
|
return this.applyGuard(url, authContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
canLoad(route: Route): Observable<boolean> {
|
canLoad(route: Route): Observable<boolean> {
|
||||||
const url = `/${route.path}`;
|
const url = `/${route.path}`;
|
||||||
return this.applyGuard(url);
|
const authContext = route.data ? route.data['authContext'] as ResolutionContext : null;
|
||||||
|
return this.applyGuard(url, authContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private applyGuard(url: string) {
|
private applyGuard(url: string, authContext: ResolutionContext) {
|
||||||
return this.checkLogin(url).pipe(tap(loggedIn => {
|
return this.checkLogin(url, authContext).pipe(tap(loggedIn => {
|
||||||
if (!loggedIn) {
|
if (!loggedIn) {
|
||||||
this.router.navigate(['/unauthorized'], { queryParams: { returnUrl: url } });
|
this.router.navigate(['/unauthorized'], { queryParams: { returnUrl: url } });
|
||||||
} else {
|
} else {
|
||||||
return true;
|
const authorized = this.authService.hasAccessToken() && this.authService.authorize(authContext);
|
||||||
|
if(!authorized){
|
||||||
|
this.router.navigate(['/unauthorized']);
|
||||||
|
}else{
|
||||||
|
return authorized;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkLogin(url: string): Observable<boolean> {
|
private checkLogin(url: string, authContext: ResolutionContext): Observable<boolean> {
|
||||||
if (!this.authService.isLoggedIn()) { return observableOf(false); }
|
if (!this.authService.isLoggedIn()) { return observableOf(false); }
|
||||||
|
|
||||||
return this.authService.hasAccessToken()
|
return this.authService.hasAccessToken()
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
export enum AppPermission {
|
||||||
|
//DescriptionTemplateType
|
||||||
|
BrowseDescriptionTemplateType = "BrowseDescriptionTemplateType",
|
||||||
|
EditDescriptionTemplateType = "EditDescriptionTemplateType",
|
||||||
|
DeleteDescriptionTemplateType = "DeleteDescriptionTemplateType",
|
||||||
|
|
||||||
|
// UI Pages
|
||||||
|
ViewDescriptionTemplateTypePage = "ViewDescriptionTemplateTypePage"
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
export interface Credential {
|
|
||||||
username: string;
|
|
||||||
secret: string;
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
import { AuthProvider } from "../../common/enum/auth-provider";
|
|
||||||
|
|
||||||
export interface LoginInfo {
|
|
||||||
ticket: string;
|
|
||||||
provider: AuthProvider;
|
|
||||||
data?: any;
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue