1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.provisioning.java.propagation;
20
21 import java.util.Collection;
22 import java.util.stream.Collectors;
23 import org.apache.syncope.core.persistence.api.entity.task.PropagationTask;
24 import org.apache.syncope.core.persistence.api.entity.task.TaskExec;
25 import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter;
26 import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskCallable;
27 import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor;
28 import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskInfo;
29 import org.apache.syncope.core.spring.security.AuthContextUtils;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.security.core.GrantedAuthority;
34 import org.springframework.security.core.context.SecurityContext;
35 import org.springframework.security.core.context.SecurityContextHolder;
36
37 public class DefaultPropagationTaskCallable implements PropagationTaskCallable {
38
39 protected static final Logger LOG = LoggerFactory.getLogger(PropagationTaskCallable.class);
40
41 @Autowired
42 protected PropagationTaskExecutor taskExecutor;
43
44 protected final String domain;
45
46 protected final Collection<String> authorities;
47
48 protected PropagationTaskInfo taskInfo;
49
50 protected PropagationReporter reporter;
51
52 protected String executor;
53
54 public DefaultPropagationTaskCallable() {
55 SecurityContext ctx = SecurityContextHolder.getContext();
56 domain = AuthContextUtils.getDomain();
57 authorities = ctx.getAuthentication().getAuthorities().stream().
58 map(GrantedAuthority::getAuthority).collect(Collectors.toSet());
59 }
60
61 @Override
62 public void setTaskInfo(final PropagationTaskInfo taskInfo) {
63 this.taskInfo = taskInfo;
64 }
65
66 @Override
67 public void setReporter(final PropagationReporter reporter) {
68 this.reporter = reporter;
69 }
70
71 @Override
72 public void setExecutor(final String executor) {
73 this.executor = executor;
74 }
75
76 @Override
77 public TaskExec<PropagationTask> call() throws Exception {
78 return AuthContextUtils.callAs(domain, executor, authorities, () -> {
79 LOG.debug("Execution started for {}", taskInfo);
80
81 TaskExec<PropagationTask> execution = taskExecutor.execute(taskInfo, reporter, executor);
82
83 LOG.debug("Execution completed for {}, {}", taskInfo, execution);
84
85 return execution;
86 });
87 }
88 }