use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class AnyTypeDataBinderImpl method create.
@Override
public AnyType create(final AnyTypeTO anyTypeTO) {
AnyType anyType = entityFactory.newEntity(AnyType.class);
update(anyType, anyTypeTO);
Set<String> added = EntitlementsHolder.getInstance().addFor(anyType.getKey());
if (!adminUser.equals(AuthContextUtils.getUsername())) {
AccessToken accessToken = accessTokenDAO.findByOwner(AuthContextUtils.getUsername());
try {
Set<SyncopeGrantedAuthority> authorities = new HashSet<>(POJOHelper.deserialize(ENCRYPTOR.decode(new String(accessToken.getAuthorities()), CipherAlgorithm.AES), new TypeReference<Set<SyncopeGrantedAuthority>>() {
}));
added.forEach(entitlement -> {
authorities.add(new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM));
});
accessToken.setAuthorities(ENCRYPTOR.encode(POJOHelper.serialize(authorities), CipherAlgorithm.AES).getBytes());
accessTokenDAO.save(accessToken);
} catch (Exception e) {
LOG.error("Could not fetch or store authorities", e);
}
}
return anyType;
}
use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class GroupDataBinderImpl method update.
@Override
public PropagationByResource update(final Group toBeUpdated, final GroupPatch groupPatch) {
// Re-merge any pending change from workflow tasks
Group group = groupDAO.save(toBeUpdated);
PropagationByResource propByRes = new PropagationByResource();
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.GROUP);
// fetch connObjectKeys before update
Map<String, String> oldConnObjectKeys = getConnObjectKeys(group, anyUtils);
// realm
setRealm(group, groupPatch);
// name
if (groupPatch.getName() != null && StringUtils.isNotBlank(groupPatch.getName().getValue())) {
propByRes.addAll(ResourceOperation.UPDATE, groupDAO.findAllResourceKeys(group.getKey()));
group.setName(groupPatch.getName().getValue());
}
// owner
if (groupPatch.getUserOwner() != null) {
group.setUserOwner(groupPatch.getUserOwner().getValue() == null ? null : userDAO.find(groupPatch.getUserOwner().getValue()));
}
if (groupPatch.getGroupOwner() != null) {
group.setGroupOwner(groupPatch.getGroupOwner().getValue() == null ? null : groupDAO.find(groupPatch.getGroupOwner().getValue()));
}
// attributes and resources
propByRes.merge(fill(group, groupPatch, anyUtils, scce));
// check if some connObjectKey was changed by the update above
Map<String, String> newConnObjectKeys = getConnObjectKeys(group, anyUtils);
oldConnObjectKeys.entrySet().stream().filter(entry -> newConnObjectKeys.containsKey(entry.getKey()) && !entry.getValue().equals(newConnObjectKeys.get(entry.getKey()))).forEach(entry -> {
propByRes.addOldConnObjectKey(entry.getKey(), entry.getValue());
propByRes.add(ResourceOperation.UPDATE, entry.getKey());
});
group = groupDAO.save(group);
// dynamic membership
if (groupPatch.getUDynMembershipCond() == null) {
if (group.getUDynMembership() != null) {
group.getUDynMembership().setGroup(null);
group.setUDynMembership(null);
groupDAO.clearUDynMembers(group);
}
} else {
setDynMembership(group, anyTypeDAO.findUser(), groupPatch.getUDynMembershipCond());
}
for (Iterator<? extends ADynGroupMembership> itor = group.getADynMemberships().iterator(); itor.hasNext(); ) {
ADynGroupMembership memb = itor.next();
memb.setGroup(null);
itor.remove();
}
groupDAO.clearADynMembers(group);
for (Map.Entry<String, String> entry : groupPatch.getADynMembershipConds().entrySet()) {
AnyType anyType = anyTypeDAO.find(entry.getKey());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), entry.getKey());
} else {
setDynMembership(group, anyType, entry.getValue());
}
}
// type extensions
for (TypeExtensionTO typeExtTO : groupPatch.getTypeExtensions()) {
AnyType anyType = anyTypeDAO.find(typeExtTO.getAnyType());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), typeExtTO.getAnyType());
} else {
TypeExtension typeExt = group.getTypeExtension(anyType).orElse(null);
if (typeExt == null) {
typeExt = entityFactory.newEntity(TypeExtension.class);
typeExt.setAnyType(anyType);
typeExt.setGroup(group);
group.add(typeExt);
}
// add all classes contained in the TO
for (String name : typeExtTO.getAuxClasses()) {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(name);
if (anyTypeClass == null) {
LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), name);
} else {
typeExt.add(anyTypeClass);
}
}
// remove all classes not contained in the TO
typeExt.getAuxClasses().removeIf(anyTypeClass -> !typeExtTO.getAuxClasses().contains(anyTypeClass.getKey()));
// only consider non-empty type extensions
if (typeExt.getAuxClasses().isEmpty()) {
group.getTypeExtensions().remove(typeExt);
typeExt.setGroup(null);
}
}
}
// remove all type extensions not contained in the TO
group.getTypeExtensions().removeIf(typeExt -> !groupPatch.getTypeExtension(typeExt.getAnyType().getKey()).isPresent());
// Throw composite exception if there is at least one element set in the composing exceptions
if (scce.hasExceptions()) {
throw scce;
}
return propByRes;
}
use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class ReconciliationReportlet method doExtract.
@Override
protected void doExtract(final ReportletConf conf, final ContentHandler handler, final AtomicReference<String> status) throws SAXException {
if (conf instanceof ReconciliationReportletConf) {
this.conf = ReconciliationReportletConf.class.cast(conf);
} else {
throw new ReportException(new IllegalArgumentException("Invalid configuration provided"));
}
AttributesImpl atts = new AttributesImpl();
if (StringUtils.isBlank(this.conf.getUserMatchingCond())) {
int total = userDAO.count();
int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
status.set("Processing " + total + " users in " + pages + " pages");
atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
handler.startElement("", "", getAnyElementName(AnyTypeKind.USER) + "s", atts);
for (int page = 1; page <= pages; page++) {
status.set("Processing " + total + " users: page " + page + " of " + pages);
doExtract(handler, userDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE));
}
} else {
SearchCond cond = SearchCondConverter.convert(this.conf.getUserMatchingCond());
int total = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, cond, AnyTypeKind.USER);
int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
status.set("Processing " + total + " users in " + pages + " pages");
atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
handler.startElement("", "", getAnyElementName(AnyTypeKind.USER) + "s", atts);
for (int page = 1; page <= pages; page++) {
status.set("Processing " + total + " users: page " + page + " of " + pages);
doExtract(handler, searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, cond, page, PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.USER));
}
}
handler.endElement("", "", getAnyElementName(AnyTypeKind.USER) + "s");
atts.clear();
if (StringUtils.isBlank(this.conf.getGroupMatchingCond())) {
int total = groupDAO.count();
int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
status.set("Processing " + total + " groups in " + pages + " pages");
atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
handler.startElement("", "", getAnyElementName(AnyTypeKind.GROUP) + "s", atts);
for (int page = 1; page <= pages; page++) {
status.set("Processing " + total + " groups: page " + page + " of " + pages);
doExtract(handler, groupDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE));
}
} else {
SearchCond cond = SearchCondConverter.convert(this.conf.getUserMatchingCond());
int total = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, cond, AnyTypeKind.GROUP);
int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
status.set("Processing " + total + " groups in " + pages + " pages");
atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
handler.startElement("", "", getAnyElementName(AnyTypeKind.GROUP) + "s", atts);
for (int page = 1; page <= pages; page++) {
status.set("Processing " + total + " groups: page " + page + " of " + pages);
doExtract(handler, searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, cond, page, PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.GROUP));
}
}
handler.endElement("", "", getAnyElementName(AnyTypeKind.GROUP) + "s");
for (AnyType anyType : anyTypeDAO.findAll()) {
if (!anyType.equals(anyTypeDAO.findUser()) && !anyType.equals(anyTypeDAO.findGroup())) {
AnyTypeCond anyTypeCond = new AnyTypeCond();
anyTypeCond.setAnyTypeKey(anyType.getKey());
SearchCond cond = StringUtils.isBlank(this.conf.getAnyObjectMatchingCond()) ? SearchCond.getLeafCond(anyTypeCond) : SearchCond.getAndCond(SearchCond.getLeafCond(anyTypeCond), SearchCondConverter.convert(this.conf.getAnyObjectMatchingCond()));
int total = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, cond, AnyTypeKind.ANY_OBJECT);
int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
status.set("Processing " + total + " any objects " + anyType.getKey() + " in " + pages + " pages");
atts.clear();
atts.addAttribute("", "", "type", ReportXMLConst.XSD_STRING, anyType.getKey());
atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
handler.startElement("", "", getAnyElementName(AnyTypeKind.ANY_OBJECT) + "s", atts);
for (int page = 1; page <= pages; page++) {
status.set("Processing " + total + " any objects " + anyType.getKey() + ": page " + page + " of " + pages);
doExtract(handler, searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, cond, page, PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.ANY_OBJECT));
}
handler.endElement("", "", getAnyElementName(AnyTypeKind.ANY_OBJECT) + "s");
}
}
}
use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class TaskDataBinderImpl method fill.
private void fill(final ProvisioningTask task, final ProvisioningTaskTO taskTO) {
if (task instanceof PushTask && taskTO instanceof PushTaskTO) {
PushTask pushTask = (PushTask) task;
PushTaskTO pushTaskTO = (PushTaskTO) taskTO;
Implementation jobDelegate = pushTaskTO.getJobDelegate() == null ? implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> PushJobDelegate.class.getName().equals(impl.getBody())).findFirst().orElse(null) : implementationDAO.find(pushTaskTO.getJobDelegate());
if (jobDelegate == null) {
jobDelegate = entityFactory.newEntity(Implementation.class);
jobDelegate.setKey(PushJobDelegate.class.getSimpleName());
jobDelegate.setEngine(ImplementationEngine.JAVA);
jobDelegate.setType(ImplementationType.TASKJOB_DELEGATE);
jobDelegate.setBody(PushJobDelegate.class.getName());
jobDelegate = implementationDAO.save(jobDelegate);
}
pushTask.setJobDelegate(jobDelegate);
pushTask.setSourceRealm(realmDAO.findByFullPath(pushTaskTO.getSourceRealm()));
pushTask.setMatchingRule(pushTaskTO.getMatchingRule() == null ? MatchingRule.LINK : pushTaskTO.getMatchingRule());
pushTask.setUnmatchingRule(pushTaskTO.getUnmatchingRule() == null ? UnmatchingRule.ASSIGN : pushTaskTO.getUnmatchingRule());
pushTaskTO.getFilters().forEach((type, fiql) -> {
AnyType anyType = anyTypeDAO.find(type);
if (anyType == null) {
LOG.debug("Invalid AnyType {} specified, ignoring...", type);
} else {
PushTaskAnyFilter filter = pushTask.getFilter(anyType).orElse(null);
if (filter == null) {
filter = entityFactory.newEntity(PushTaskAnyFilter.class);
filter.setAnyType(anyType);
filter.setPushTask(pushTask);
pushTask.add(filter);
}
filter.setFIQLCond(fiql);
}
});
// remove all filters not contained in the TO
pushTask.getFilters().removeIf(anyFilter -> !pushTaskTO.getFilters().containsKey(anyFilter.getAnyType().getKey()));
} else if (task instanceof PullTask && taskTO instanceof PullTaskTO) {
PullTask pullTask = (PullTask) task;
PullTaskTO pullTaskTO = (PullTaskTO) taskTO;
Implementation jobDelegate = pullTaskTO.getJobDelegate() == null ? implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> PullJobDelegate.class.getName().equals(impl.getBody())).findFirst().orElse(null) : implementationDAO.find(pullTaskTO.getJobDelegate());
if (jobDelegate == null) {
jobDelegate = entityFactory.newEntity(Implementation.class);
jobDelegate.setKey(PullJobDelegate.class.getSimpleName());
jobDelegate.setEngine(ImplementationEngine.JAVA);
jobDelegate.setType(ImplementationType.TASKJOB_DELEGATE);
jobDelegate.setBody(PullJobDelegate.class.getName());
jobDelegate = implementationDAO.save(jobDelegate);
}
pullTask.setJobDelegate(jobDelegate);
pullTask.setPullMode(pullTaskTO.getPullMode());
if (pullTaskTO.getReconFilterBuilder() == null) {
pullTask.setReconFilterBuilder(null);
} else {
Implementation reconFilterBuilder = implementationDAO.find(pullTaskTO.getReconFilterBuilder());
if (reconFilterBuilder == null) {
LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", pullTaskTO.getReconFilterBuilder());
} else {
pullTask.setReconFilterBuilder(reconFilterBuilder);
}
}
pullTask.setDestinationRealm(realmDAO.findByFullPath(pullTaskTO.getDestinationRealm()));
pullTask.setMatchingRule(pullTaskTO.getMatchingRule() == null ? MatchingRule.UPDATE : pullTaskTO.getMatchingRule());
pullTask.setUnmatchingRule(pullTaskTO.getUnmatchingRule() == null ? UnmatchingRule.PROVISION : pullTaskTO.getUnmatchingRule());
// validate JEXL expressions from templates and proceed if fine
templateUtils.check(pullTaskTO.getTemplates(), ClientExceptionType.InvalidPullTask);
pullTaskTO.getTemplates().forEach((type, template) -> {
AnyType anyType = anyTypeDAO.find(type);
if (anyType == null) {
LOG.debug("Invalid AnyType {} specified, ignoring...", type);
} else {
AnyTemplatePullTask anyTemplate = pullTask.getTemplate(anyType).orElse(null);
if (anyTemplate == null) {
anyTemplate = entityFactory.newEntity(AnyTemplatePullTask.class);
anyTemplate.setAnyType(anyType);
anyTemplate.setPullTask(pullTask);
pullTask.add(anyTemplate);
}
anyTemplate.set(template);
}
});
// remove all templates not contained in the TO
pullTask.getTemplates().removeIf(anyTemplate -> !pullTaskTO.getTemplates().containsKey(anyTemplate.getAnyType().getKey()));
pullTask.setRemediation(pullTaskTO.isRemediation());
}
// 3. fill the remaining fields
task.setPerformCreate(taskTO.isPerformCreate());
task.setPerformUpdate(taskTO.isPerformUpdate());
task.setPerformDelete(taskTO.isPerformDelete());
task.setSyncStatus(taskTO.isSyncStatus());
taskTO.getActions().forEach(action -> {
Implementation implementation = implementationDAO.find(action);
if (implementation == null) {
LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", action);
} else {
task.add(implementation);
}
});
// remove all implementations not contained in the TO
task.getActions().removeIf(implementation -> !taskTO.getActions().contains(implementation.getKey()));
}
use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class ResourceLogic method connObjectInit.
private Triple<ExternalResource, AnyType, Provision> connObjectInit(final String resourceKey, final String anyTypeKey) {
ExternalResource resource = resourceDAO.authFind(resourceKey);
if (resource == null) {
throw new NotFoundException("Resource '" + resourceKey + "'");
}
AnyType anyType = anyTypeDAO.find(anyTypeKey);
if (anyType == null) {
throw new NotFoundException("AnyType '" + anyTypeKey + "'");
}
Optional<? extends Provision> provision = resource.getProvision(anyType);
if (!provision.isPresent()) {
throw new NotFoundException("Provision on resource '" + resourceKey + "' for type '" + anyTypeKey + "'");
}
return ImmutableTriple.of(resource, anyType, provision.get());
}
Aggregations