Skip to content

Instantly share code, notes, and snippets.

@ilgrosso
Created June 15, 2023 14:19
Show Gist options
  • Save ilgrosso/8a3449cdb0c523c56826afccc69aceb0 to your computer and use it in GitHub Desktop.
Save ilgrosso/8a3449cdb0c523c56826afccc69aceb0 to your computer and use it in GitHub Desktop.
Syncope: update single attribute onto External Resource
public class ICLDAPLogic extends AbstractTransactionalLogic<EntityTO> {
private final UserDAO userDAO;
private final ExternalResourceDAO resourceDAO;
private final MappingManager mappingManager;
private final PropagationTaskExecutor taskExecutor;
public ICLDAPLogic(
final UserDAO userDAO,
final ExternalResourceDAO resourceDAO,
final MappingManager mappingManager,
final PropagationTaskExecutor taskExecutor) {
this.userDAO = userDAO;
this.resourceDAO = resourceDAO;
this.mappingManager = mappingManager;
this.taskExecutor = taskExecutor;
}
@PreAuthorize("hasRole('" + IdRepoEntitlement.USER_UPDATE + "')")
public void status(final String userKey, final int value) {
ExternalResource execAuth = Optional.ofNullable(resourceDAO.find(ICConstants.RESOURCE_EXEC_AUTH)).
orElseThrow(() -> new NotFoundException("External Resource " + ICConstants.RESOURCE_EXEC_AUTH));
Provision provision = execAuth.getProvisionByAnyType(AnyTypeKind.USER.name()).
orElseThrow(() -> new NotFoundException("USER provision info for " + ICConstants.RESOURCE_EXEC_AUTH));
User user = Optional.ofNullable(userDAO.find(userKey)).
orElseThrow(() -> new NotFoundException("User " + userKey));
String connObjectKey = mappingManager.getConnObjectKeyValue(user, execAuth, provision).
orElseThrow(() -> new NotFoundException(
"ConnObject key for " + user.getUsername() + " on " + ICConstants.RESOURCE_EXEC_AUTH));
Set<Attribute> attrs = new HashSet<>();
PropagationData propagationData = new PropagationData(attrs);
propagationData.getAttributes().add(AttributeBuilder.build("attr", value));
Set<AttributeDelta> attrDeltas = new HashSet<>();
attrDeltas.add(AttributeDeltaBuilder.build("attr", Set.of(value)));
propagationData.setAttributeDeltas(attrDeltas);
PropagationTaskInfo taskInfo = new PropagationTaskInfo(
execAuth,
ResourceOperation.UPDATE,
new ObjectClass(provision.getObjectClass()),
AnyTypeKind.USER,
AnyTypeKind.USER.name(),
userKey,
connObjectKey,
propagationData);
taskExecutor.execute(taskInfo, new DefaultPropagationReporter(), AuthContextUtils.getUsername());
}
@Override
protected EntityTO resolveReference(final Method method, final Object... args) throws UnresolvedReferenceException {
throw new UnsupportedOperationException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment