task #9088 Authorization model should be changed to be Permission based

This commit is contained in:
Efstratios Giannopoulos 2023-10-19 10:44:20 +03:00
parent ce8ff28955
commit a235eb98f4
18 changed files with 122 additions and 420 deletions

View File

@ -181,20 +181,13 @@ public class DescriptionTemplateTypeQuery extends QueryBase<DescriptionTemplateT
@Override @Override
protected String fieldNameOf(FieldResolver item) { protected String fieldNameOf(FieldResolver item) {
if (item.match(DescriptionTemplateType._id)) if (item.match(DescriptionTemplateType._id)) return DescriptionTemplateTypeEntity._id;
return DescriptionTemplateType._id; else if (item.match(DescriptionTemplateType._name)) return DescriptionTemplateTypeEntity._name;
else if (item.match(DescriptionTemplateType._name)) else if (item.match(DescriptionTemplateType._createdAt)) return DescriptionTemplateTypeEntity._createdAt;
return DescriptionTemplateType._name; else if (item.match(DescriptionTemplateType._updatedAt)) return DescriptionTemplateTypeEntity._updatedAt;
else if (item.match(DescriptionTemplateType._createdAt)) else if (item.match(DescriptionTemplateType._isActive)) return DescriptionTemplateTypeEntity._isActive;
return DescriptionTemplateType._createdAt; else if (item.match(DescriptionTemplateType._status)) return DescriptionTemplateTypeEntity._status;
else if (item.match(DescriptionTemplateType._updatedAt)) else return null;
return DescriptionTemplateType._updatedAt;
else if (item.match(DescriptionTemplateType._isActive))
return DescriptionTemplateType._isActive;
else if (item.match(DescriptionTemplateType._status))
return DescriptionTemplateType._status;
else
return null;
} }
} }

View File

@ -1,12 +1,13 @@
package eu.eudat.controllers; package eu.eudat.controllers;
import eu.eudat.authorization.Permission;
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException; import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException; import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
import eu.eudat.logic.managers.MergeEmailConfirmationManager; import eu.eudat.logic.managers.MergeEmailConfirmationManager;
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.userinfo.UserMergeRequestModel; import eu.eudat.models.data.userinfo.UserMergeRequestModel;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -22,10 +23,12 @@ import javax.management.InvalidApplicationException;
public class EmailMergeConfirmation { public class EmailMergeConfirmation {
private MergeEmailConfirmationManager emailConfirmationManager; private MergeEmailConfirmationManager emailConfirmationManager;
private final AuthorizationService authorizationService;
@Autowired @Autowired
public EmailMergeConfirmation(MergeEmailConfirmationManager emailConfirmationManager) { public EmailMergeConfirmation(MergeEmailConfirmationManager emailConfirmationManager, AuthorizationService authorizationService) {
this.emailConfirmationManager = emailConfirmationManager; this.emailConfirmationManager = emailConfirmationManager;
this.authorizationService = authorizationService;
} }
@Transactional @Transactional
@ -48,9 +51,10 @@ public class EmailMergeConfirmation {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity sendConfirmatioEmail(@RequestBody UserMergeRequestModel requestModel, Principal principal) { ResponseEntity sendConfirmatioEmail(@RequestBody UserMergeRequestModel requestModel) {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
try { try {
this.emailConfirmationManager.sendConfirmationEmail(requestModel.getEmail(), principal, requestModel.getUserId(), requestModel.getProvider()); this.emailConfirmationManager.sendConfirmationEmail(requestModel.getEmail(), requestModel.getUserId(), requestModel.getProvider());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (Exception ex) { } catch (Exception ex) {
if (ex instanceof HasConfirmedEmailException) { if (ex instanceof HasConfirmedEmailException) {

View File

@ -1,12 +1,13 @@
package eu.eudat.controllers; package eu.eudat.controllers;
import eu.eudat.authorization.Permission;
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException; import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException; import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
import eu.eudat.logic.managers.UnlinkEmailConfirmationManager; import eu.eudat.logic.managers.UnlinkEmailConfirmationManager;
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.userinfo.UserUnlinkRequestModel; import eu.eudat.models.data.userinfo.UserUnlinkRequestModel;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -22,10 +23,12 @@ import javax.management.InvalidApplicationException;
public class EmailUnlinkConfirmation { public class EmailUnlinkConfirmation {
private UnlinkEmailConfirmationManager unlinkEmailConfirmationManager; private UnlinkEmailConfirmationManager unlinkEmailConfirmationManager;
private final AuthorizationService authorizationService;
@Autowired @Autowired
public EmailUnlinkConfirmation(UnlinkEmailConfirmationManager unlinkEmailConfirmationManager){ public EmailUnlinkConfirmation(UnlinkEmailConfirmationManager unlinkEmailConfirmationManager, AuthorizationService authorizationService){
this.unlinkEmailConfirmationManager = unlinkEmailConfirmationManager; this.unlinkEmailConfirmationManager = unlinkEmailConfirmationManager;
this.authorizationService = authorizationService;
} }
@Transactional @Transactional
@ -48,9 +51,10 @@ public class EmailUnlinkConfirmation {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem> sendUnlinkConfirmationEmail(@RequestBody UserUnlinkRequestModel requestModel, Principal principal) { ResponseEntity<ResponseItem> sendUnlinkConfirmationEmail(@RequestBody UserUnlinkRequestModel requestModel) {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
try { try {
this.unlinkEmailConfirmationManager.sendConfirmationEmail(requestModel.getEmail(), principal, requestModel.getUserId(), requestModel.getProvider()); this.unlinkEmailConfirmationManager.sendConfirmationEmail(requestModel.getEmail(), requestModel.getUserId(), requestModel.getProvider());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (Exception ex) { } catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).message("Could not send unlink email.")); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).message("Could not send unlink email."));

View File

@ -1,8 +1,7 @@
package eu.eudat.controllers.v2; package eu.eudat.controllers.v2;
import eu.eudat.authorization.Permission;
import eu.eudat.controllers.BaseController; import eu.eudat.controllers.BaseController;
import eu.eudat.data.old.DataRepository;
import eu.eudat.data.old.Registry;
import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest; import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest;
import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest; import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
@ -13,13 +12,11 @@ import eu.eudat.logic.services.externalreferences.FunderService;
import eu.eudat.logic.services.externalreferences.ProjectService; import eu.eudat.logic.services.externalreferences.ProjectService;
import eu.eudat.models.data.ExternalReference; import eu.eudat.models.data.ExternalReference;
import eu.eudat.models.data.ExternalReference2; import eu.eudat.models.data.ExternalReference2;
import eu.eudat.models.data.datarepository.DataRepositoryModel;
import eu.eudat.models.data.funder.Funder; import eu.eudat.models.data.funder.Funder;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.project.Project; import eu.eudat.models.data.project.Project;
import eu.eudat.models.data.registries.RegistryModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -37,30 +34,36 @@ public class ExternalReferencesController extends BaseController {
private final FunderService funderService; private final FunderService funderService;
private final ExternalReferencesService externalReferencesService; private final ExternalReferencesService externalReferencesService;
private final ProjectService projectService; private final ProjectService projectService;
private final AuthorizationService authorizationService;
@Autowired @Autowired
public ExternalReferencesController( public ExternalReferencesController(
ApiContext apiContext, ApiContext apiContext,
FunderService funderService, FunderService funderService,
ExternalReferencesService externalReferencesService, ExternalReferencesService externalReferencesService,
ProjectService projectService ProjectService projectService,
) { AuthorizationService authorizationService) {
super(apiContext); super(apiContext);
this.funderService = funderService; this.funderService = funderService;
this.externalReferencesService = externalReferencesService; this.externalReferencesService = externalReferencesService;
this.projectService = projectService; this.projectService = projectService;
this.authorizationService = authorizationService;
} }
@PostMapping(path = {"funders"}, consumes = "application/json", produces = "application/json") @PostMapping(path = {"funders"}, consumes = "application/json", produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<Funder>>> getWithExternal(@RequestBody FunderCriteriaRequest funderCriteria, Principal principal) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException { public @ResponseBody ResponseEntity<ResponseItem<List<Funder>>> getWithExternal(@RequestBody FunderCriteriaRequest funderCriteria) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException {
List<Funder> dataTable = this.funderService.getCriteriaWithExternal(funderCriteria, principal); this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
List<Funder> dataTable = this.funderService.getCriteriaWithExternal(funderCriteria);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Funder>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Funder>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} }
@PostMapping(path = {"projects"}, consumes = "application/json", produces = "application/json") @PostMapping(path = {"projects"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<List<Project>>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria, Principal principal) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException { ResponseEntity<ResponseItem<List<Project>>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException {
List<Project> dataTable = this.projectService.getCriteriaWithExternal(projectCriteria, principal); this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
List<Project> dataTable = this.projectService.getCriteriaWithExternal(projectCriteria);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} }
@ -68,17 +71,21 @@ public class ExternalReferencesController extends BaseController {
@GetMapping(path = {"data-repo/{externalType}"}, produces = "application/json") @GetMapping(path = {"data-repo/{externalType}"}, produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference>>> listExternalReferecnes(@RequestParam(value = "externalType") String externalType, @RequestParam(value = "query", required = false) String query, public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference>>> listExternalReferecnes(@RequestParam(value = "externalType") String externalType, @RequestParam(value = "query", required = false) String query,
@RequestParam(value = "type", required = false) String type, Principal principal @RequestParam(value = "type", required = false) String type
) throws HugeResultSet, NoURLFound, InvalidApplicationException { ) throws HugeResultSet, NoURLFound, InvalidApplicationException {
List<ExternalReference> externalReferences = this.externalReferencesService.getExternalReference(externalType, query, type, principal); this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
List<ExternalReference> externalReferences = this.externalReferencesService.getExternalReference(externalType, query, type);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences));
} }
@Transactional @Transactional
@PostMapping(path = {"data-repo/persist"}, consumes = "application/json", produces = "application/json") @PostMapping(path = {"data-repo/persist"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<ExternalReference>> createExternalReferecnes(@RequestBody ExternalReference externalReference, Principal principal) throws Exception { ResponseEntity<ResponseItem<ExternalReference>> createExternalReferecnes(@RequestBody ExternalReference externalReference) throws Exception {
ExternalReference newExternalReference = this.externalReferencesService.createDataRepo(externalReference, principal); this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
ExternalReference newExternalReference = this.externalReferencesService.createDataRepo(externalReference);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
} }
@ -87,17 +94,21 @@ public class ExternalReferencesController extends BaseController {
@GetMapping(path = {"{externalType}"}, produces = "application/json") @GetMapping(path = {"{externalType}"}, produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference2>>> listExternalReferecnes2(@RequestParam(value = "externalType") String externalType, @RequestParam(value = "query", required = false) String query, public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference2>>> listExternalReferecnes2(@RequestParam(value = "externalType") String externalType, @RequestParam(value = "query", required = false) String query,
@RequestParam(value = "type", required = false) String type, Principal principal @RequestParam(value = "type", required = false) String type
) throws HugeResultSet, NoURLFound, InvalidApplicationException { ) throws HugeResultSet, NoURLFound, InvalidApplicationException {
List<ExternalReference2> externalReferences = this.externalReferencesService.getExternalReference2(externalType, query, type, principal); this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
List<ExternalReference2> externalReferences = this.externalReferencesService.getExternalReference2(externalType, query, type);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference2>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference2>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences));
} }
@Transactional @Transactional
@PostMapping(value = {"{externalType}/persist"}, consumes = "application/json", produces = "application/json") @PostMapping(value = {"{externalType}/persist"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<ExternalReference2>> create(@RequestBody ExternalReference2 externalReference, Principal principal) throws Exception { ResponseEntity<ResponseItem<ExternalReference2>> create(@RequestBody ExternalReference2 externalReference) throws Exception {
ExternalReference2 newExternalReference = this.externalReferencesService.create(externalReference, principal); this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
ExternalReference2 newExternalReference = this.externalReferencesService.create(externalReference);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference2>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference2>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
} }

View File

@ -1,13 +1,14 @@
package eu.eudat.controllers.v2; package eu.eudat.controllers.v2;
import eu.eudat.authorization.Permission;
import eu.eudat.controllers.BaseController; import eu.eudat.controllers.BaseController;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.ValidationService; import eu.eudat.logic.services.ValidationService;
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.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -19,19 +20,23 @@ import org.springframework.web.bind.annotation.*;
public class ValidationController extends BaseController { public class ValidationController extends BaseController {
private ValidationService validationService; private ValidationService validationService;
private final AuthorizationService authorizationService;
@Autowired @Autowired
public ValidationController(ApiContext apiContext, ValidationService validationService) { public ValidationController(ApiContext apiContext, ValidationService validationService, AuthorizationService authorizationService) {
super(apiContext); super(apiContext);
this.validationService = validationService; this.validationService = validationService;
this.authorizationService = authorizationService;
} }
@GetMapping(path = {""}, produces = "application/json") @GetMapping(path = {""}, produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<Boolean>> validate( ResponseEntity<ResponseItem<Boolean>> validate(
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type, Principal principal @RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type
) throws HugeResultSet, NoURLFound { ) throws HugeResultSet, NoURLFound {
Boolean isValid = this.validationService.validateIdentifier(query, type, principal); this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
Boolean isValid = this.validationService.validateIdentifier(query, type);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Boolean>().payload(isValid).status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Boolean>().payload(isValid).status(ApiMessageCode.NO_MESSAGE));
} }
} }

View File

@ -5,7 +5,6 @@ import eu.eudat.logic.builders.model.criteria.DataRepositoryCriteriaBuilder;
import eu.eudat.logic.builders.model.criteria.ExternalDatasetCriteriaBuilder; import eu.eudat.logic.builders.model.criteria.ExternalDatasetCriteriaBuilder;
import eu.eudat.logic.builders.model.criteria.RegistryCriteriaBuilder; import eu.eudat.logic.builders.model.criteria.RegistryCriteriaBuilder;
import eu.eudat.logic.builders.model.models.*; import eu.eudat.logic.builders.model.models.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -17,7 +16,6 @@ public class BuilderFactoryImpl implements BuilderFactory {
if (tClass.equals(DataRepositoryCriteriaBuilder.class)) return (T) new DataRepositoryCriteriaBuilder(); if (tClass.equals(DataRepositoryCriteriaBuilder.class)) return (T) new DataRepositoryCriteriaBuilder();
if (tClass.equals(DatasetProfileBuilder.class)) return (T) new DatasetProfileBuilder(); if (tClass.equals(DatasetProfileBuilder.class)) return (T) new DatasetProfileBuilder();
if (tClass.equals(DataTableDataBuilder.class)) return (T) new DataTableDataBuilder<>(); if (tClass.equals(DataTableDataBuilder.class)) return (T) new DataTableDataBuilder<>();
if (tClass.equals(PrincipalBuilder.class)) return (T) new PrincipalBuilder();
if (tClass.equals(GrantBuilder.class)) return (T) new GrantBuilder(); if (tClass.equals(GrantBuilder.class)) return (T) new GrantBuilder();
if (tClass.equals(ProjectBuilder.class)) return (T) new ProjectBuilder(); if (tClass.equals(ProjectBuilder.class)) return (T) new ProjectBuilder();
if (tClass.equals(FunderBuilder.class)) return (T) new FunderBuilder(); if (tClass.equals(FunderBuilder.class)) return (T) new FunderBuilder();

View File

@ -1,94 +0,0 @@
package eu.eudat.logic.builders.model.models;
import eu.eudat.logic.builders.Builder;
import eu.eudat.models.data.security.Principal;
import eu.eudat.types.Authorities;
import java.time.Instant;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class PrincipalBuilder extends Builder<Principal> {
private UUID id;
private UUID token;
private String name;
private String email;
private Date expiresAt;
private String avatarUrl;
private Set<Authorities> authorities;
private String culture;
private String language;
private String timezone;
public PrincipalBuilder id(UUID id) {
this.id = id;
return this;
}
public PrincipalBuilder token(UUID token) {
this.token = token;
return this;
}
public PrincipalBuilder name(String name) {
this.name = name;
return this;
}
public PrincipalBuilder email(String email) {
this.email = email;
return this;
}
public PrincipalBuilder expiresAt(Date expiresAt) {
this.expiresAt = expiresAt;
return this;
}
public PrincipalBuilder authorities(Set<Authorities> authorities) {
this.authorities = authorities;
return this;
}
public PrincipalBuilder avatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
return this;
}
public PrincipalBuilder culture(String culture) {
this.culture = culture;
return this;
}
public PrincipalBuilder language(String language) {
this.language = language;
return this;
}
public PrincipalBuilder timezone(String timezone) {
this.timezone = timezone;
return this;
}
@Override
public Principal build() {
Principal principal = new Principal();
principal.setAuthorities(authorities);
principal.setName(name);
principal.setEmail(email);
principal.setExpiresAt(expiresAt);
principal.setToken(token);
principal.setId(id);
principal.setAvatarUrl(avatarUrl);
principal.setCulture(culture);
principal.setLanguage(language);
principal.setTimezone(timezone);
return principal;
}
}

View File

@ -5,7 +5,6 @@ import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
import eu.eudat.models.data.doi.DepositRequest; import eu.eudat.models.data.doi.DepositRequest;
import eu.eudat.models.data.doi.Doi; import eu.eudat.models.data.doi.Doi;
import eu.eudat.models.data.doi.RepositoryConfig; import eu.eudat.models.data.doi.RepositoryConfig;
import eu.eudat.models.data.security.Principal;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View File

@ -14,7 +14,6 @@ import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.models.data.security.Principal;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -74,8 +73,8 @@ public class MergeEmailConfirmationManager {
return userToBeMergedEmail; return userToBeMergedEmail;
} }
public void sendConfirmationEmail(String email, Principal principal, UUID userId, Integer provider) throws HasConfirmedEmailException, InvalidApplicationException { public void sendConfirmationEmail(String email, UUID userId, Integer provider) throws HasConfirmedEmailException, InvalidApplicationException {
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId());
if (user.getEmail() != null && !user.getEmail().equals(email)) { if (user.getEmail() != null && !user.getEmail().equals(email)) {
apiContext.getUtilitiesService().getConfirmationEmailService().createMergeConfirmationEmail( apiContext.getUtilitiesService().getConfirmationEmailService().createMergeConfirmationEmail(
@ -83,7 +82,6 @@ public class MergeEmailConfirmationManager {
apiContext.getUtilitiesService().getMailService(), apiContext.getUtilitiesService().getMailService(),
email, email,
userId, userId,
principal,
provider provider
); );
} }

View File

@ -2,6 +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.commons.scope.user.UserScope;
import eu.eudat.data.CredentialEntity; import eu.eudat.data.CredentialEntity;
import eu.eudat.data.old.EmailConfirmation; import eu.eudat.data.old.EmailConfirmation;
import eu.eudat.data.old.UserInfo; import eu.eudat.data.old.UserInfo;
@ -9,7 +10,6 @@ import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException; import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.models.data.security.Principal;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -27,11 +27,13 @@ public class UnlinkEmailConfirmationManager {
private ApiContext apiContext; private ApiContext apiContext;
private DatabaseRepository databaseRepository; private DatabaseRepository databaseRepository;
private final UserScope userScope;
@Autowired @Autowired
public UnlinkEmailConfirmationManager(ApiContext apiContext) { public UnlinkEmailConfirmationManager(ApiContext apiContext, UserScope userScope) {
this.apiContext = apiContext; this.apiContext = apiContext;
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
this.userScope = userScope;
} }
@Transactional @Transactional
@ -73,8 +75,8 @@ public class UnlinkEmailConfirmationManager {
} }
} }
public void sendConfirmationEmail(String email, Principal principal, UUID userId, Integer provider) throws InvalidApplicationException { public void sendConfirmationEmail(String email, UUID userId, Integer provider) throws InvalidApplicationException {
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userScope.getUserId());
if (user.getEmail() != null && !user.getEmail().equals(email)) { if (user.getEmail() != null && !user.getEmail().equals(email)) {
apiContext.getUtilitiesService().getConfirmationEmailService().createUnlinkConfirmationEmail( apiContext.getUtilitiesService().getConfirmationEmailService().createUnlinkConfirmationEmail(
@ -82,7 +84,6 @@ public class UnlinkEmailConfirmationManager {
apiContext.getUtilitiesService().getMailService(), apiContext.getUtilitiesService().getMailService(),
email, email,
userId, userId,
principal,
provider provider
); );
} }

View File

@ -1,10 +1,10 @@
package eu.eudat.logic.services; package eu.eudat.logic.services;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria; import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.proxy.fetching.RemoteFetcher; import eu.eudat.logic.proxy.fetching.RemoteFetcher;
import eu.eudat.models.data.security.Principal;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -12,17 +12,19 @@ import org.springframework.stereotype.Service;
public class ValidationService { public class ValidationService {
private RemoteFetcher remoteFetcher; private RemoteFetcher remoteFetcher;
private final UserScope userScope;
@Autowired @Autowired
public ValidationService(RemoteFetcher remoteFetcher) { public ValidationService(RemoteFetcher remoteFetcher, UserScope userScope) {
super(); super();
this.remoteFetcher = remoteFetcher; this.remoteFetcher = remoteFetcher;
this.userScope = userScope;
} }
public Boolean validateIdentifier(String identifier, String type, Principal principal) throws NoURLFound, HugeResultSet { public Boolean validateIdentifier(String identifier, String type) throws NoURLFound, HugeResultSet {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(identifier); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(identifier);
Integer count = this.remoteFetcher.findEntries(externalUrlCriteria, type); Integer count = this.remoteFetcher.findEntries(externalUrlCriteria, type);
return principal != null && count > 0; return userScope.isSet() && count > 0;
} }

View File

@ -2,6 +2,7 @@ package eu.eudat.logic.services.externalreferences;
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 eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.dao.criteria.DataRepositoryCriteria; import eu.eudat.data.dao.criteria.DataRepositoryCriteria;
import eu.eudat.data.dao.criteria.RegistryCriteria; import eu.eudat.data.dao.criteria.RegistryCriteria;
import eu.eudat.data.dao.criteria.ServiceCriteria; import eu.eudat.data.dao.criteria.ServiceCriteria;
@ -15,7 +16,6 @@ import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.ExternalReference; import eu.eudat.models.data.ExternalReference;
import eu.eudat.models.data.ExternalReference2; import eu.eudat.models.data.ExternalReference2;
import eu.eudat.models.data.security.Principal;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import java.util.LinkedList; import java.util.LinkedList;
@ -27,9 +27,11 @@ import java.util.stream.Collectors;
public class ExternalReferencesService {//implements ExternalReferencesService{ public class ExternalReferencesService {//implements ExternalReferencesService{
private final ApiContext apiContext; private final ApiContext apiContext;
private final UserScope userScope;
public ExternalReferencesService(ApiContext apiContext) { public ExternalReferencesService(ApiContext apiContext, UserScope userScope) {
this.apiContext = apiContext; this.apiContext = apiContext;
this.userScope = userScope;
} }
// external references: // external references:
@ -40,16 +42,16 @@ public class ExternalReferencesService {//implements ExternalReferencesService{
// pubRepositories, // pubRepositories,
// dataRepositories // dataRepositories
public ExternalReference createDataRepo(ExternalReference externalReference, Principal principal) throws Exception { public ExternalReference createDataRepo(ExternalReference externalReference) throws Exception {
// only dataRepositories, pubRepositories, journals // only dataRepositories, pubRepositories, journals
DataRepository dataRepository = externalReference.toDataModel(); DataRepository dataRepository = externalReference.toDataModel();
dataRepository.getCreationUser().setId(principal.getId()); dataRepository.getCreationUser().setId(this.userScope.getUserId());
dataRepository = apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().createOrUpdate(dataRepository); dataRepository = apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().createOrUpdate(dataRepository);
return new ExternalReference().fromDataModel(dataRepository); return new ExternalReference().fromDataModel(dataRepository);
} }
public List<ExternalReference> getExternalReference(String externalType, String query, String type, Principal principal) throws HugeResultSet, NoURLFound, InvalidApplicationException { public List<ExternalReference> getExternalReference(String externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type); List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type);
@ -58,7 +60,7 @@ public class ExternalReferencesService {//implements ExternalReferencesService{
List<ExternalReference> list = new LinkedList<>(); List<ExternalReference> list = new LinkedList<>();
if((externalType.equals("dataRepositories") || externalType.equals("pubRepositories") || externalType.equals("journals"))){ if((externalType.equals("dataRepositories") || externalType.equals("pubRepositories") || externalType.equals("journals"))){
criteria.setCreationUserId(principal.getId()); criteria.setCreationUserId(this.userScope.getUserId());
if (type.equals("")) { if (type.equals("")) {
List<DataRepository> dataRepositoryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().getWithCriteria(criteria)).toList(); List<DataRepository> dataRepositoryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().getWithCriteria(criteria)).toList();
list = dataRepositoryList.stream().map(item -> new ExternalReference().fromDataModel(item)).collect(Collectors.toList()); list = dataRepositoryList.stream().map(item -> new ExternalReference().fromDataModel(item)).collect(Collectors.toList());
@ -77,7 +79,7 @@ public class ExternalReferencesService {//implements ExternalReferencesService{
// registries, // registries,
// services // services
public ExternalReference2 create(ExternalReference2 externalReference, Principal principal) throws Exception { public ExternalReference2 create(ExternalReference2 externalReference) throws Exception {
if (externalReference.getLabel() == null || externalReference.getAbbreviation() == null || externalReference.getUri() == null) { if (externalReference.getLabel() == null || externalReference.getAbbreviation() == null || externalReference.getUri() == null) {
throw new Exception("Missing mandatory entity."); throw new Exception("Missing mandatory entity.");
} }
@ -85,12 +87,12 @@ public class ExternalReferencesService {//implements ExternalReferencesService{
ExternalReference2 newExternalReference = null; ExternalReference2 newExternalReference = null;
if(externalReference.getExternalType().equals("registries")){ if(externalReference.getExternalType().equals("registries")){
Registry registry = externalReference.toDataModelRegistry(); Registry registry = externalReference.toDataModelRegistry();
registry.getCreationUser().setId(principal.getId()); registry.getCreationUser().setId(this.userScope.getUserId());
registry = apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().createOrUpdate(registry); registry = apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().createOrUpdate(registry);
newExternalReference = new ExternalReference2().fromDataModel(registry); newExternalReference = new ExternalReference2().fromDataModel(registry);
} else if (externalReference.getExternalType().equals("services")) { } else if (externalReference.getExternalType().equals("services")) {
Service service = externalReference.toDataModelService(); Service service = externalReference.toDataModelService();
service.getCreationUser().setId(principal.getId()); service.getCreationUser().setId(this.userScope.getUserId());
service = apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().createOrUpdate(service); service = apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().createOrUpdate(service);
newExternalReference = new ExternalReference2().fromDataModel(service); newExternalReference = new ExternalReference2().fromDataModel(service);
} }
@ -99,7 +101,7 @@ public class ExternalReferencesService {//implements ExternalReferencesService{
} }
public List<ExternalReference2> getExternalReference2(String externalType, String query, String type, Principal principal) throws HugeResultSet, NoURLFound, InvalidApplicationException { public List<ExternalReference2> getExternalReference2(String externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType,externalUrlCriteria, type); List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType,externalUrlCriteria, type);
@ -109,7 +111,7 @@ public class ExternalReferencesService {//implements ExternalReferencesService{
RegistryCriteria criteria = new RegistryCriteria(); RegistryCriteria criteria = new RegistryCriteria();
if (!query.isEmpty()) criteria.setLike(query); if (!query.isEmpty()) criteria.setLike(query);
criteria.setCreationUserId(principal.getId()); criteria.setCreationUserId(this.userScope.getUserId());
if (type.equals("")) { if (type.equals("")) {
List<Registry> registryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().getWithCriteria(criteria)).toList(); List<Registry> registryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().getWithCriteria(criteria)).toList();
@ -119,7 +121,7 @@ public class ExternalReferencesService {//implements ExternalReferencesService{
ServiceCriteria criteria = new ServiceCriteria(); ServiceCriteria criteria = new ServiceCriteria();
if (!query.isEmpty()) criteria.setLike(query); if (!query.isEmpty()) criteria.setLike(query);
criteria.setCreationUserId(principal.getId()); criteria.setCreationUserId(this.userScope.getUserId());
if (type.equals("")) { if (type.equals("")) {
List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList(); List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList();

View File

@ -1,5 +1,6 @@
package eu.eudat.logic.services.externalreferences; package eu.eudat.logic.services.externalreferences;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.old.UserInfo; import eu.eudat.data.old.UserInfo;
import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest; import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest;
import eu.eudat.logic.builders.model.models.FunderBuilder; import eu.eudat.logic.builders.model.models.FunderBuilder;
@ -12,7 +13,6 @@ import eu.eudat.logic.utilities.helpers.ListHelper;
import eu.eudat.models.data.external.ExternalSourcesItemModel; import eu.eudat.models.data.external.ExternalSourcesItemModel;
import eu.eudat.models.data.external.FundersExternalSourcesModel; import eu.eudat.models.data.external.FundersExternalSourcesModel;
import eu.eudat.models.data.funder.Funder; import eu.eudat.models.data.funder.Funder;
import eu.eudat.models.data.security.Principal;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -28,16 +28,18 @@ public class FunderService {
private ApiContext apiContext; private ApiContext apiContext;
private RemoteFetcher remoteFetcher; private RemoteFetcher remoteFetcher;
private ListHelper listHelper; private ListHelper listHelper;
private final UserScope userScope;
public FunderService(ApiContext apiContext, RemoteFetcher remoteFetcher, ListHelper listHelper) { public FunderService(ApiContext apiContext, RemoteFetcher remoteFetcher, ListHelper listHelper, UserScope userScope) {
this.apiContext = apiContext; this.apiContext = apiContext;
this.remoteFetcher = remoteFetcher; this.remoteFetcher = remoteFetcher;
this.listHelper = listHelper; this.listHelper = listHelper;
this.userScope = userScope;
} }
public List<Funder> getCriteriaWithExternal(FunderCriteriaRequest funderCriteria, Principal principal) throws HugeResultSet, NoURLFound, InvalidApplicationException { public List<Funder> getCriteriaWithExternal(FunderCriteriaRequest funderCriteria) throws HugeResultSet, NoURLFound, InvalidApplicationException {
UserInfo userInfo = new UserInfo(); UserInfo userInfo = new UserInfo();
userInfo.setId(principal.getId()); userInfo.setId(this.userScope.getUserId());
funderCriteria.getCriteria().setReference("dmp:"); funderCriteria.getCriteria().setReference("dmp:");
QueryableList<eu.eudat.data.old.Funder> items = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(funderCriteria.getCriteria()); QueryableList<eu.eudat.data.old.Funder> items = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(funderCriteria.getCriteria());
QueryableList<eu.eudat.data.old.Funder> authItems = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getAuthenticated(items, userInfo); QueryableList<eu.eudat.data.old.Funder> authItems = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getAuthenticated(items, userInfo);

View File

@ -1,5 +1,6 @@
package eu.eudat.logic.services.externalreferences; package eu.eudat.logic.services.externalreferences;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest; import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest;
import eu.eudat.logic.builders.model.models.ProjectBuilder; import eu.eudat.logic.builders.model.models.ProjectBuilder;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria; import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
@ -11,7 +12,6 @@ import eu.eudat.logic.utilities.helpers.ListHelper;
import eu.eudat.models.data.external.ExternalSourcesItemModel; import eu.eudat.models.data.external.ExternalSourcesItemModel;
import eu.eudat.models.data.external.ProjectsExternalSourcesModel; import eu.eudat.models.data.external.ProjectsExternalSourcesModel;
import eu.eudat.models.data.project.Project; import eu.eudat.models.data.project.Project;
import eu.eudat.models.data.security.Principal;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -27,16 +27,18 @@ public class ProjectService {
private ApiContext apiContext; private ApiContext apiContext;
private RemoteFetcher remoteFetcher; private RemoteFetcher remoteFetcher;
private ListHelper listHelper; private ListHelper listHelper;
private final UserScope userScope;
public ProjectService(ApiContext apiContext, ListHelper listHelper) { public ProjectService(ApiContext apiContext, ListHelper listHelper, UserScope userScope) {
this.apiContext = apiContext; this.apiContext = apiContext;
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher(); this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
this.listHelper = listHelper; this.listHelper = listHelper;
this.userScope = userScope;
} }
public List<Project> getCriteriaWithExternal(ProjectCriteriaRequest projectCriteria, Principal principal) throws HugeResultSet, NoURLFound, InvalidApplicationException { public List<Project> getCriteriaWithExternal(ProjectCriteriaRequest projectCriteria) throws HugeResultSet, NoURLFound, InvalidApplicationException {
eu.eudat.data.old.UserInfo userInfo = new eu.eudat.data.old.UserInfo(); eu.eudat.data.old.UserInfo userInfo = new eu.eudat.data.old.UserInfo();
userInfo.setId(principal.getId()); userInfo.setId(this.userScope.getUserId());
projectCriteria.getCriteria().setReference("dmp:"); projectCriteria.getCriteria().setReference("dmp:");
QueryableList<eu.eudat.data.old.Project> items = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getWithCritetia(projectCriteria.getCriteria()); QueryableList<eu.eudat.data.old.Project> items = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getWithCritetia(projectCriteria.getCriteria());
QueryableList<eu.eudat.data.old.Project> authItems = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getAuthenticated(items, userInfo); QueryableList<eu.eudat.data.old.Project> authItems = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getAuthenticated(items, userInfo);

View File

@ -2,17 +2,17 @@ package eu.eudat.logic.services.utilities;
import eu.eudat.data.dao.entities.EmailConfirmationDao; import eu.eudat.data.dao.entities.EmailConfirmationDao;
import eu.eudat.data.old.EmailConfirmation; import eu.eudat.data.old.EmailConfirmation;
import eu.eudat.models.data.security.Principal;
import javax.management.InvalidApplicationException;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
public interface ConfirmationEmailService { public interface ConfirmationEmailService {
public void createConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId); public void createConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId);
public void createMergeConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId, Principal principal, Integer provider); public void createMergeConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId, Integer provider) throws InvalidApplicationException;
public void createUnlinkConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId, Principal principal, Integer provider); public void createUnlinkConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId, Integer provider) throws InvalidApplicationException;
public CompletableFuture sentConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService); public CompletableFuture sentConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService);

View File

@ -3,15 +3,18 @@ package eu.eudat.logic.services.utilities;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
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.commons.scope.user.UserScope;
import eu.eudat.data.dao.entities.EmailConfirmationDao; import eu.eudat.data.dao.entities.EmailConfirmationDao;
import eu.eudat.data.old.EmailConfirmation; import eu.eudat.data.old.EmailConfirmation;
import eu.eudat.data.old.UserInfo;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.mail.SimpleMail; import eu.eudat.models.data.mail.SimpleMail;
import eu.eudat.models.data.security.Principal;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.management.InvalidApplicationException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -23,10 +26,14 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
private static final Logger logger = LoggerFactory.getLogger(ConfirmationEmailServiceImpl.class); private static final Logger logger = LoggerFactory.getLogger(ConfirmationEmailServiceImpl.class);
//private Logger logger; //private Logger logger;
private Environment environment; private Environment environment;
private final UserScope userScope;
private final ApiContext apiContext;
public ConfirmationEmailServiceImpl(/*Logger logger,*/ Environment environment) { public ConfirmationEmailServiceImpl(/*Logger logger,*/ Environment environment, UserScope userScope, ApiContext apiContext) {
// this.logger = logger; // this.logger = logger;
this.environment = environment; this.environment = environment;
this.userScope = userScope;
this.apiContext = apiContext;
} }
@Override @Override
@ -139,7 +146,7 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
@Override @Override
public void createMergeConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, public void createMergeConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService,
String email, UUID userId, Principal principal, Integer provider) { String email, UUID userId, Integer provider) throws InvalidApplicationException {
EmailConfirmation confirmationEmail = new EmailConfirmation(); EmailConfirmation confirmationEmail = new EmailConfirmation();
confirmationEmail.setEmail(email); confirmationEmail.setEmail(email);
confirmationEmail.setExpiresAt(Date confirmationEmail.setExpiresAt(Date
@ -148,27 +155,29 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
.plusSeconds(Long.parseLong(this.environment.getProperty("conf_email.expiration_time_seconds"))) .plusSeconds(Long.parseLong(this.environment.getProperty("conf_email.expiration_time_seconds")))
) )
); );
UserInfo user = this.apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); //TODO: Authz
confirmationEmail.setUserId(userId); confirmationEmail.setUserId(userId);
try { try {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("userId", principal.getId()); map.put("userId", this.userScope.getUserId());
map.put("provider", provider.toString()); map.put("provider", provider.toString());
confirmationEmail.setData(new ObjectMapper().writeValueAsString(map)); confirmationEmail.setData(new ObjectMapper().writeValueAsString(map));
} catch (JsonProcessingException e) { } catch (JsonProcessingException | InvalidApplicationException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
confirmationEmail.setIsConfirmed(false); confirmationEmail.setIsConfirmed(false);
confirmationEmail.setToken(UUID.randomUUID()); confirmationEmail.setToken(UUID.randomUUID());
confirmationEmail = loginConfirmationEmailDao.createOrUpdate(confirmationEmail); confirmationEmail = loginConfirmationEmailDao.createOrUpdate(confirmationEmail);
sentMergeConfirmationEmail(confirmationEmail, mailService, principal.getName()); sentMergeConfirmationEmail(confirmationEmail, mailService, user.getName());
} }
@Override @Override
public void createUnlinkConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, public void createUnlinkConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService,
String email, UUID userId, Principal principal, Integer provider) { String email, UUID userId, Integer provider) throws InvalidApplicationException {
UserInfo user = this.apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); //TODO: Authz
EmailConfirmation confirmationEmail = new EmailConfirmation(); EmailConfirmation confirmationEmail = new EmailConfirmation();
confirmationEmail.setEmail(principal.getEmail()); confirmationEmail.setEmail(user.getEmail());
confirmationEmail.setExpiresAt(Date confirmationEmail.setExpiresAt(Date
.from(new Date() .from(new Date()
.toInstant() .toInstant()

View File

@ -1,121 +0,0 @@
package eu.eudat.models.data.principal;
import eu.eudat.models.data.security.Principal;
import eu.eudat.types.Authorities;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
public class PrincipalModel {
private UUID id;
private UUID token;
private String name;
private String email;
private Date expiresAt;
private String avatarUrl;
private Set<Authorities> authorities;
private String culture;
private String language;
private String timezone;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getToken() {
return token;
}
public void setToken(UUID token) {
this.token = token;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getExpiresAt() {
return expiresAt;
}
public void setExpiresAt(Date expiresAt) {
this.expiresAt = expiresAt;
}
public String getAvatarUrl() {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public Set<Authorities> getAuthz() {
return authorities;
}
public Set<Integer> getAuthorities() {
return authorities.stream().map(authz -> authz.getValue()).collect(Collectors.toSet());
}
public void setAuthorities(Set<Authorities> authorities) {
this.authorities = authorities;
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public static PrincipalModel fromEntity(Principal principal) {
PrincipalModel model = new PrincipalModel();
model.setId(principal.getId());
model.setToken(principal.getToken());
model.setAuthorities(principal.getAuthz());
model.setAvatarUrl(principal.getAvatarUrl());
model.setCulture(principal.getCulture());
model.setEmail(principal.getEmail());
model.setExpiresAt(principal.getExpiresAt());
model.setLanguage(principal.getLanguage());
model.setName(principal.getName());
model.setTimezone(principal.getTimezone());
return model;
}
}

View File

@ -1,113 +0,0 @@
package eu.eudat.models.data.security;
import com.fasterxml.jackson.annotation.JsonIgnore;
import eu.eudat.types.Authorities;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
public class Principal {
private UUID id;
private UUID token;
private String name;
private String email;
private Date expiresAt;
private String avatarUrl;
private Set<Authorities> authorities;
private String culture;
private String language;
private String timezone;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getToken() {
return token;
}
public void setToken(UUID token) {
this.token = token;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getExpiresAt() {
return expiresAt;
}
public void setExpiresAt(Date expiresAt) {
this.expiresAt = expiresAt;
}
public String getAvatarUrl() {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public Set<Integer> getAuthorities() {
return authorities.stream().map(authz -> authz.getValue()).collect(Collectors.toSet());
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
@JsonIgnore
public Set<Authorities> getAuthz() {
return this.authorities;
}
public void setAuthorities(Set<Authorities> authorities) {
this.authorities = authorities;
}
public boolean isAuthorized(List<Authorities> requiredAuthorities) {
if (!Collections.disjoint(this.authorities, requiredAuthorities) || requiredAuthorities.size() == 0)
return true;
else return false;
}
}