Search in sources :

Example 1 with RunAsSystem

use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.

the class AnnotationJobFactory method createJob.

@RunAsSystem
public AnnotationJob createJob(AnnotationJobExecution metaData) {
    dataService.add(ANNOTATION_JOB_EXECUTION, metaData);
    String annotatorNames = metaData.getAnnotators();
    String targetName = metaData.getTargetName();
    String username = metaData.getUser();
    // create an authentication to run as the user that is listed as the owner of the job
    RunAsUserToken runAsAuthentication = new RunAsUserToken("Job Execution", username, null, userDetailsService.loadUserByUsername(username).getAuthorities(), null);
    Repository<Entity> repository = dataService.getRepository(targetName);
    List<RepositoryAnnotator> availableAnnotators = annotationService.getAllAnnotators().stream().filter(RepositoryAnnotator::annotationDataExists).collect(toList());
    List<RepositoryAnnotator> requestedAnnotators = Arrays.stream(annotatorNames.split(",")).map(annotationService::getAnnotatorByName).collect(toList());
    AnnotatorDependencyOrderResolver resolver = new AnnotatorDependencyOrderResolver();
    List<RepositoryAnnotator> annotators = Lists.newArrayList(resolver.getAnnotatorSelectionDependencyList(availableAnnotators, requestedAnnotators, repository, entityTypeFactory));
    return new AnnotationJob(crudRepositoryAnnotator, username, annotators, repository, new ProgressImpl(metaData, jobExecutionUpdater, mailSender), runAsAuthentication, new TransactionTemplate(transactionManager));
}
Also used : Entity(org.molgenis.data.Entity) ProgressImpl(org.molgenis.jobs.ProgressImpl) RunAsUserToken(org.springframework.security.access.intercept.RunAsUserToken) RepositoryAnnotator(org.molgenis.data.annotation.core.RepositoryAnnotator) CrudRepositoryAnnotator(org.molgenis.data.annotation.web.CrudRepositoryAnnotator) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) AnnotatorDependencyOrderResolver(org.molgenis.data.annotation.core.utils.AnnotatorDependencyOrderResolver) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 2 with RunAsSystem

use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.

the class FairController method getDataset.

@GetMapping(produces = TEXT_TURTLE_VALUE, value = "/{catalogID}/{datasetID}")
@ResponseBody
@RunAsSystem
public Model getDataset(@PathVariable("catalogID") String catalogID, @PathVariable("datasetID") String datasetID) {
    String subjectIRI = getBaseUri().pathSegment(catalogID, datasetID).toUriString();
    Entity subjectEntity = dataService.findOneById("fdp_Dataset", datasetID);
    return entityModelWriter.createRdfModel(subjectIRI, subjectEntity);
}
Also used : Entity(org.molgenis.data.Entity) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 3 with RunAsSystem

use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.

the class FairController method getMetadata.

@GetMapping(produces = TEXT_TURTLE_VALUE)
@ResponseBody
@RunAsSystem
public Model getMetadata() {
    String subjectIRI = getBaseUri().toUriString();
    Entity subjectEntity = dataService.findOne("fdp_Metadata", new QueryImpl<>());
    return entityModelWriter.createRdfModel(subjectIRI, subjectEntity);
}
Also used : Entity(org.molgenis.data.Entity) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 4 with RunAsSystem

use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.

the class GavinJobFactory method createJob.

@RunAsSystem
public GavinJob createJob(GavinJobExecution gavinJobExecution) {
    dataService.add(gavinJobExecution.getEntityType().getId(), gavinJobExecution);
    String username = gavinJobExecution.getUser();
    // create an authentication to run as the user that is listed as the owner of the job
    RunAsUserToken runAsAuthentication = new RunAsUserToken("Job Execution", username, null, userDetailsService.loadUserByUsername(username).getAuthorities(), null);
    return new GavinJob(new ProgressImpl(gavinJobExecution, jobExecutionUpdater, mailSender), new TransactionTemplate(transactionManager), runAsAuthentication, gavinJobExecution.getIdentifier(), fileStore, menuReaderService, cadd, exac, snpEff, gavin, parser, annotatorRunner, gavinJobExecution);
}
Also used : ProgressImpl(org.molgenis.jobs.ProgressImpl) RunAsUserToken(org.springframework.security.access.intercept.RunAsUserToken) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 5 with RunAsSystem

use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.

the class UserServiceImpl method getUserGroups.

@Override
@RunAsSystem
public Iterable<Group> getUserGroups(String username) {
    Fetch fetch = new Fetch().field(GroupMemberMetaData.GROUP, new Fetch().field(GroupMetaData.ID).field(GroupMetaData.NAME).field(GroupMetaData.ACTIVE));
    Stream<GroupMember> molgenisGroupMembers = dataService.query(GROUP_MEMBER, GroupMember.class).fetch(fetch).eq(GroupMemberMetaData.USER, getUser(username)).findAll();
    // N.B. Must collect the results in a list before yielding up the RunAsSystem privileges!
    return molgenisGroupMembers.map(GroupMember::getGroup).collect(toList());
}
Also used : Fetch(org.molgenis.data.Fetch) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Aggregations

RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)29 Entity (org.molgenis.data.Entity)12 Transactional (org.springframework.transaction.annotation.Transactional)7 User (org.molgenis.data.security.auth.User)5 QueryImpl (org.molgenis.data.support.QueryImpl)4 UnknownEntityException (org.molgenis.data.UnknownEntityException)3 MolgenisUserException (org.molgenis.security.user.MolgenisUserException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Stream (java.util.stream.Stream)2 DataService (org.molgenis.data.DataService)2 Fetch (org.molgenis.data.Fetch)2 IndexActionGroup (org.molgenis.data.index.meta.IndexActionGroup)2 INDEX_ACTION_GROUP (org.molgenis.data.index.meta.IndexActionGroupMetaData.INDEX_ACTION_GROUP)2 Token (org.molgenis.data.security.auth.Token)2 ProgressImpl (org.molgenis.jobs.ProgressImpl)2 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)2 RunAsUserToken (org.springframework.security.access.intercept.RunAsUserToken)2