1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.fit.core.reference;
20
21 import java.util.Optional;
22 import org.apache.syncope.common.lib.to.Provision;
23 import org.apache.syncope.common.lib.types.MatchType;
24 import org.apache.syncope.core.persistence.api.dao.UserDAO;
25 import org.apache.syncope.core.persistence.api.dao.search.AttrCond;
26 import org.apache.syncope.core.persistence.api.dao.search.SearchCond;
27 import org.apache.syncope.core.persistence.api.entity.Any;
28 import org.apache.syncope.core.provisioning.api.rules.PullCorrelationRule;
29 import org.apache.syncope.core.provisioning.api.rules.PullCorrelationRuleConfClass;
30 import org.apache.syncope.core.provisioning.api.rules.PullMatch;
31 import org.identityconnectors.framework.common.objects.Attribute;
32 import org.identityconnectors.framework.common.objects.SyncDelta;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.transaction.annotation.Transactional;
35 import org.springframework.util.CollectionUtils;
36
37 @PullCorrelationRuleConfClass(LinkedAccountSamplePullCorrelationRuleConf.class)
38 public class LinkedAccountSamplePullCorrelationRule implements PullCorrelationRule {
39
40 public static final String VIVALDI_KEY = "b3cbc78d-32e6-4bd4-92e0-bbe07566a2ee";
41
42 @Autowired
43 private UserDAO userDAO;
44
45 @Override
46 public SearchCond getSearchCond(final SyncDelta syncDelta, final Provision provision) {
47 AttrCond cond = new AttrCond();
48
49 Attribute email = syncDelta.getObject().getAttributeByName("email");
50 if (email != null && !CollectionUtils.isEmpty(email.getValue())) {
51 cond.setSchema("email");
52 cond.setType(AttrCond.Type.EQ);
53 cond.setExpression(email.getValue().get(0).toString());
54 } else {
55 cond.setSchema("");
56 }
57
58 return SearchCond.getLeaf(cond);
59 }
60
61 @Transactional(readOnly = true)
62 @Override
63 public PullMatch matching(final Any<?> any, final SyncDelta syncDelta, final Provision provision) {
64
65
66 Attribute firstName = syncDelta.getObject().getAttributeByName("firstName");
67 if (VIVALDI_KEY.equals(any.getKey())
68 && firstName != null && !CollectionUtils.isEmpty(firstName.getValue())
69 && !"Antonio".equals(firstName.getValue().get(0).toString())) {
70
71 return new PullMatch(MatchType.LINKED_ACCOUNT, any);
72 }
73
74 return PullCorrelationRule.super.matching(any, syncDelta, provision);
75 }
76
77 @Transactional(readOnly = true)
78 @Override
79 public Optional<PullMatch> unmatching(final SyncDelta syncDelta, final Provision provision) {
80
81 return Optional.of(new PullMatch(MatchType.LINKED_ACCOUNT, userDAO.find(VIVALDI_KEY)));
82 }
83 }