protected ProvisioningResult<TO> afterDelete( final TO input, final List<PropagationStatus> statuses, final List<LogicActions> actions) { TO any = input; for (LogicActions action : actions) { any = action.afterDelete(any); } ProvisioningResult<TO> result = new ProvisioningResult<>(); result.setEntity(any); result.getPropagationStatuses().addAll(statuses); return result; }
@Override @SuppressWarnings("unchecked") protected Panel customResultBody(final String panelId, final AnyWrapper<A> item, final Serializable result) { if (!(result instanceof ProvisioningResult)) { throw new IllegalStateException("Unsupported result type"); } return new StatusPanel( panelId, ((ProvisioningResult<A>) result).getEntity(), new ListModel<>(new ArrayList<>()), ((ProvisioningResult<A>) result).getPropagationStatuses().stream().map(status -> { ConnObjectTO before = status.getBeforeObj(); ConnObjectWrapper afterObjWrapper = new ConnObjectWrapper( ((ProvisioningResult<A>) result).getEntity(), status.getResource(), status.getAfterObj()); return Triple.of(before, afterObjWrapper, status.getFailureReason()); }).collect(Collectors.toList()), pageRef); } }
switch (patch.getAction()) { case UNLINK: updated = new ProvisioningResult<>(); updated.setEntity(getAnyLogic().unlink(patch.getKey(), patch.getResources())); break; item.setStatus(updated.getEntity().getResources().contains(resource) ? Response.Status.BAD_REQUEST.getStatusCode() : Response.Status.OK.getStatusCode()); Arrays.asList(Preference.RETURN_NO_CONTENT.toString())); } else { item.setContent(POJOHelper.serialize(updated.getEntity())); }).collect(Collectors.toList()); } else { batchResponseItems = updated.getPropagationStatuses().stream(). map(status -> { BatchResponseItem item = new BatchResponseItem(); Arrays.asList(Preference.RETURN_NO_CONTENT.toString())); } else { item.setContent(POJOHelper.serialize(updated.getEntity()));
@Override protected Serializable onApplyInternal(final AnyWrapper<AnyObjectTO> modelObject) { AnyObjectTO inner = modelObject.getInnerObject(); ProvisioningResult<AnyObjectTO> result; if (remediationTO.getAnyURPayload() == null) { AnyObjectCR req = new AnyObjectCR(); EntityTOUtils.toAnyCR(inner, req); result = restClient.remedy(remediationTO.getKey(), req); } else { AnyObjectUR req = AnyOperations.diff(inner, previousAnyObjectTO, false); // update just if it is changed if (req.isEmpty()) { result = new ProvisioningResult<>(); result.setEntity(inner); } else { result = restClient.remedy(remediationTO.getKey(), req); } } return result; } }
/** * Builds response to successful {@code create} request, taking into account any {@code Prefer} header. * * @param provisioningResult the entity just created * @return response to successful {@code create} request */ protected Response createResponse(final ProvisioningResult<?> provisioningResult) { String entityId = provisioningResult.getEntity().getKey(); Response.ResponseBuilder builder = Response. created(uriInfo.getAbsolutePathBuilder().path(entityId).build()). header(RESTHeaders.RESOURCE_KEY, entityId); return applyPreference(provisioningResult, builder).build(); }
propagations.addAll(((ProvisioningResult) result).getPropagationStatuses());
switch (patch.getAction()) { case LINK: updated = new ProvisioningResult<>(); updated.setEntity(getAnyLogic().link( patch.getKey(), patch.getResources())); item.setStatus(updated.getEntity().getResources().contains(resource) ? Response.Status.OK.getStatusCode() : Response.Status.BAD_REQUEST.getStatusCode()); Arrays.asList(Preference.RETURN_NO_CONTENT.toString())); } else { item.setContent(POJOHelper.serialize(updated.getEntity())); }).collect(Collectors.toList()); } else { batchResponseItems = updated.getPropagationStatuses().stream(). map(status -> { BatchResponseItem item = new BatchResponseItem(); Arrays.asList(Preference.RETURN_NO_CONTENT.toString())); } else { item.setContent(POJOHelper.serialize(updated.getEntity()));
@Override protected Serializable onApplyInternal(final AnyWrapper<GroupTO> modelObject) { GroupTO inner = modelObject.getInnerObject(); ProvisioningResult<GroupTO> result; if (remediationTO.getAnyURPayload() == null) { GroupCR req = new GroupCR(); EntityTOUtils.toAnyCR(inner, req); result = restClient.remedy(remediationTO.getKey(), req); } else { GroupUR req = AnyOperations.diff(inner, previousGroupTO, false); // update just if it is changed if (req.isEmpty()) { result = new ProvisioningResult<>(); result.setEntity(inner); } else { result = restClient.remedy(remediationTO.getKey(), req); } } return result; } }
@Override public Response create(final String parentPath, final RealmTO realmTO) { ProvisioningResult<RealmTO> created = logic.create(StringUtils.prependIfMissing(parentPath, SyncopeConstants.ROOT_REALM), realmTO); URI location = uriInfo.getAbsolutePathBuilder().path(created.getEntity().getName()).build(); Response.ResponseBuilder builder = Response.created(location). header(RESTHeaders.RESOURCE_KEY, created.getEntity().getFullPath()); return applyPreference(created, builder).build(); }
protected ProvisioningResult<TO> afterCreate( final TO input, final List<PropagationStatus> statuses, final List<LogicActions> actions) { TO any = input; for (LogicActions action : actions) { any = action.afterCreate(any); } ProvisioningResult<TO> result = new ProvisioningResult<>(); result.setEntity(any); result.getPropagationStatuses().addAll(statuses); return result; }
result = new ProvisioningResult<>(); result.setEntity(inner); } else { result = groupRestClient.update(getOriginalItem().getInnerObject().getETagValue(), groupUR);
provisioningResult.getPropagationStatuses().forEach(propagationStatus -> { results.put(propagationStatus.getResource(), propagationStatus.getStatus().name()); findFirst(). ifPresent(statusBean -> statusBean.setStatus( "suspended".equalsIgnoreCase(provisioningResult.getEntity().getStatus()) ? Status.SUSPENDED : Status.ACTIVE)); if (statusR.isOnSyncope()) { results.put(Constants.SYNCOPE, ("suspended".equalsIgnoreCase(provisioningResult.getEntity().getStatus()) && type == StatusRType.SUSPEND) || ("active".equalsIgnoreCase(provisioningResult.getEntity().getStatus()) && type == StatusRType.REACTIVATE) ? ExecStatus.SUCCESS.name()
@PreAuthorize("isAuthenticated() " + "and not(hasRole('" + StandardEntitlement.ANONYMOUS + "')) " + "and not(hasRole('" + StandardEntitlement.MUST_CHANGE_PASSWORD + "'))") public ProvisioningResult<UserTO> selfUpdate(final UserPatch userPatch, final boolean nullPriorityAsync) { UserTO userTO = binder.getAuthenticatedUserTO(); userPatch.setKey(userTO.getKey()); ProvisioningResult<UserTO> updated = doUpdate(userPatch, true, nullPriorityAsync); // Ensures that, if the self update above moves the user into a status from which no authentication // is possible, the existing Access Token is clean up to avoid issues with future authentications if (!confDAO.getValuesAsStrings("authentication.statuses").contains(updated.getEntity().getStatus())) { String accessToken = accessTokenDAO.findByOwner(updated.getEntity().getUsername()).getKey(); if (accessToken != null) { accessTokenDAO.delete(accessToken); } } return updated; }
protected ProvisioningResult<TO> afterUpdate( final TO input, final List<PropagationStatus> statuses, final List<LogicActions> actions, final boolean authDynRealms, final Set<String> dynRealmsBefore) { Set<String> dynRealmsAfter = new HashSet<>(input.getDynRealms()); if (authDynRealms && !dynRealmsBefore.equals(dynRealmsAfter)) { throw new DelegatedAdministrationException( this instanceof UserLogic ? AnyTypeKind.USER : this instanceof GroupLogic ? AnyTypeKind.GROUP : AnyTypeKind.ANY_OBJECT, input.getKey()); } TO any = input; for (LogicActions action : actions) { any = action.afterUpdate(any); } ProvisioningResult<TO> result = new ProvisioningResult<>(); result.setEntity(any); result.getPropagationStatuses().addAll(statuses); return result; }
@Override protected Serializable onApplyInternal(final AnyWrapper<AnyObjectTO> modelObject) { final AnyObjectTO inner = modelObject.getInnerObject(); ProvisioningResult<AnyObjectTO> result; if (inner.getKey() == null) { AnyObjectCR req = new AnyObjectCR(); EntityTOUtils.toAnyCR(inner, req); result = anyObjectRestClient.create(req); } else { fixPlainAndVirAttrs(inner, getOriginalItem().getInnerObject()); AnyObjectUR req = AnyOperations.diff(inner, getOriginalItem().getInnerObject(), false); // update just if it is changed if (req.isEmpty()) { result = new ProvisioningResult<>(); result.setEntity(inner); } else { result = anyObjectRestClient.update(getOriginalItem().getInnerObject().getETagValue(), req); } } return result; }
@Override public void filter(final ContainerRequestContext reqCtx, final ContainerResponseContext resCtx) throws IOException { if (resCtx.getEntityTag() == null) { AbstractAnnotatedBean annotated = null; if (resCtx.getEntity() instanceof AbstractAnnotatedBean) { annotated = (AbstractAnnotatedBean) resCtx.getEntity(); } else if (resCtx.getEntity() instanceof ProvisioningResult) { EntityTO entity = ((ProvisioningResult<?>) resCtx.getEntity()).getEntity(); if (entity instanceof AbstractAnnotatedBean) { annotated = (AbstractAnnotatedBean) entity; } } if (annotated != null) { String etagValue = annotated.getETagValue(); if (StringUtils.isNotBlank(etagValue)) { resCtx.getHeaders().add(HttpHeaders.ETAG, new EntityTag(etagValue).toString()); } } } } }
@PreAuthorize("hasRole('" + StandardEntitlement.GROUP_UPDATE + "')") @Override public ProvisioningResult<GroupTO> deprovision( final String key, final Collection<String> resources, final boolean nullPriorityAsync) { // security checks GroupTO group = binder.getGroupTO(key); Set<String> effectiveRealms = RealmUtils.getEffective( AuthContextUtils.getAuthorizations().get(StandardEntitlement.GROUP_UPDATE), group.getRealm()); securityChecks(effectiveRealms, group.getRealm(), group.getKey()); List<PropagationStatus> statuses = provisioningManager.deprovision(key, resources, nullPriorityAsync); ProvisioningResult<GroupTO> result = new ProvisioningResult<>(); result.setEntity(binder.getGroupTO(key)); result.getPropagationStatuses().addAll(statuses); return result; }
@Override protected Serializable onApplyInternal(final AnyWrapper<UserTO> modelObject) { UserTO inner = modelObject.getInnerObject(); ProvisioningResult<UserTO> result; if (remediationTO.getAnyURPayload() == null) { UserCR req = new UserCR(); EntityTOUtils.toAnyCR(inner, req); result = restClient.remedy(remediationTO.getKey(), req); } else { UserUR req = AnyOperations.diff(inner, previousUserTO, false); if (StringUtils.isNotBlank(inner.getPassword())) { PasswordPatch passwordPatch = new PasswordPatch.Builder(). value(inner.getPassword()).onSyncope(true).resources(inner. getResources()). build(); req.setPassword(passwordPatch); } // update just if it is changed if (req.isEmpty()) { result = new ProvisioningResult<>(); result.setEntity(inner); } else { result = restClient.remedy(remediationTO.getKey(), req); } } return result; } }
&& ((ProvisioningResult) output).getEntity() instanceof UserTO) { any = userDAO.find(((ProvisioningResult) output).getEntity().getKey()); } else if (before instanceof AnyObjectTO) { any = anyObjectDAO.find(((AnyObjectTO) before).getKey()); any = anyObjectDAO.find(((AnyObjectTO) output).getKey()); } else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof AnyObjectTO) { any = anyObjectDAO.find(((ProvisioningResult) output).getEntity().getKey()); } else if (before instanceof GroupTO) { any = groupDAO.find(((GroupTO) before).getKey()); any = groupDAO.find(((GroupTO) output).getKey()); } else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof GroupTO) { any = groupDAO.find(((ProvisioningResult) output).getEntity().getKey());
@PreAuthorize("hasRole('" + StandardEntitlement.REALM_UPDATE + "')") public ProvisioningResult<RealmTO> update(final RealmTO realmTO) { Realm realm = realmDAO.findByFullPath(realmTO.getFullPath()); if (realm == null) { LOG.error("Could not find realm '" + realmTO.getFullPath() + "'"); throw new NotFoundException(realmTO.getFullPath()); } PropagationByResource propByRes = binder.update(realm, realmTO); realm = realmDAO.save(realm); List<PropagationTaskInfo> taskInfos = propagationManager.createTasks(realm, propByRes, null); PropagationReporter propagationReporter = taskExecutor.execute(taskInfos, false); ProvisioningResult<RealmTO> result = new ProvisioningResult<>(); result.setEntity(binder.getRealmTO(realm, true)); result.getPropagationStatuses().addAll(propagationReporter.getStatuses()); return result; }