in client/idm/console/src/main/java/org/apache/syncope/client/console/panels/LinkedAccountModalPanel.java [98:385]
public LinkedAccountModalPanel(
final IModel<UserTO> model,
final PageReference pageRef,
final boolean reconciliationOnly) {
super(BaseModal.CONTENT_ID, model);
final MultilevelPanel mlp = new MultilevelPanel("mlpContainer");
mlp.setOutputMarkupId(true);
setOutputMarkupId(true);
actionTogglePanel = new ActionLinksTogglePanel<>("toggle", pageRef);
add(actionTogglePanel);
AnyLayout anyLayout = AnyLayoutUtils.fetch(
roleRestClient,
anyTypeRestClient.listAnyTypes().stream().map(AnyTypeTO::getKey).collect(Collectors.toList()));
LinkedAccountFormLayoutInfo linkedAccountFormLayoutInfo =
anyLayout.getUser() instanceof IdMUserFormLayoutInfo
? IdMUserFormLayoutInfo.class.cast(anyLayout.getUser()).getLinkedAccountFormLayoutInfo()
: new LinkedAccountFormLayoutInfo();
try {
wizard = linkedAccountFormLayoutInfo.getFormClass().getConstructor(
IModel.class,
LinkedAccountFormLayoutInfo.class,
UserRestClient.class,
AnyTypeRestClient.class,
PageReference.class).
newInstance(model, linkedAccountFormLayoutInfo, userRestClient, anyTypeRestClient, pageRef);
} catch (Exception e) {
LOG.error("Error instantiating form layout", e);
wizard = new LinkedAccountWizardBuilder(
model, linkedAccountFormLayoutInfo, userRestClient, anyTypeRestClient, pageRef);
}
ListViewPanel.Builder<LinkedAccountTO> builder = new ListViewPanel.Builder<>(
LinkedAccountTO.class, pageRef) {
private static final long serialVersionUID = -5322423525438435153L;
@Override
protected LinkedAccountTO getActualItem(final LinkedAccountTO item, final List<LinkedAccountTO> list) {
return item == null
? null
: list.stream().filter(
in -> ((item.getKey() == null && in.getKey() == null)
|| (in.getKey() != null && in.getKey().equals(item.getKey())))).
findAny().orElse(null);
}
@Override
protected void customActionCallback(final AjaxRequestTarget target) {
// change modal footer visibility
send(LinkedAccountModalPanel.this, Broadcast.BUBBLE, new BaseModal.ChangeFooterVisibilityEvent(target));
}
@Override
protected void customActionOnCancelCallback(final AjaxRequestTarget target) {
// change modal footer visibility
send(LinkedAccountModalPanel.this, Broadcast.BUBBLE, new BaseModal.ChangeFooterVisibilityEvent(target));
}
@Override
@SuppressWarnings("unchecked")
protected void customActionOnFinishCallback(final AjaxRequestTarget target) {
checkAddButton(model.getObject().getRealm());
linkedAccountTOs.clear();
linkedAccountTOs.addAll(model.getObject().getLinkedAccounts());
sortLinkedAccounts();
ListViewPanel.class.cast(list).refreshList(linkedAccountTOs);
// change modal footer visibility
send(LinkedAccountModalPanel.this, Broadcast.BUBBLE, new BaseModal.ChangeFooterVisibilityEvent(target));
}
@Override
protected Component getValueComponent(final String key, final LinkedAccountTO bean) {
if ("suspended".equalsIgnoreCase(key)) {
Label label = new Label("field", StringUtils.EMPTY);
if (bean.isSuspended()) {
label.add(new AttributeModifier("class", "fa fa-check"));
label.add(new AttributeModifier("style", "display: table-cell; text-align: center;"));
}
return label;
}
return super.getValueComponent(key, bean);
}
@Override
protected ActionLinksTogglePanel<LinkedAccountTO> getTogglePanel() {
return actionTogglePanel;
}
};
linkedAccountTOs = new ArrayList<>(model.getObject().getLinkedAccounts());
sortLinkedAccounts();
builder.setItems(linkedAccountTOs);
builder.includes("connObjectKeyValue", "resource", "suspended");
builder.setReuseItem(false);
builder.withChecks(ListViewPanel.CheckAvailability.NONE);
builder.addAction(new ActionLink<>() {
private static final long serialVersionUID = 2555747430358755813L;
@Override
public void onClick(final AjaxRequestTarget target, final LinkedAccountTO linkedAccountTO) {
mlp.next(linkedAccountTO.getResource(), new LinkedAccountStatusPanel(
linkedAccountTO.getResource(),
model.getObject().getType(),
linkedAccountTO.getConnObjectKeyValue()),
target);
target.add(mlp);
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
send(LinkedAccountModalPanel.this, Broadcast.BREADTH,
new ActionLinksTogglePanel.ActionLinkToggleCloseEventPayload(target));
}
}, ActionLink.ActionType.VIEW, IdRepoEntitlement.USER_READ);
if (!reconciliationOnly) {
builder.addAction(new ActionLink<>() {
private static final long serialVersionUID = 2555747430358755813L;
@Override
public void onClick(final AjaxRequestTarget target, final LinkedAccountTO linkedAccountTO) {
try {
send(LinkedAccountModalPanel.this, Broadcast.DEPTH,
new AjaxWizard.NewItemActionEvent<>(linkedAccountTO, 1, target).
setTitleModel(new StringResourceModel("inner.edit.linkedAccount",
LinkedAccountModalPanel.this, Model.of(linkedAccountTO))));
} catch (SyncopeClientException e) {
LOG.error("While attempting to create new linked account", e);
SyncopeConsoleSession.get().onException(e);
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
send(LinkedAccountModalPanel.this, Broadcast.BREADTH,
new ActionLinksTogglePanel.ActionLinkToggleCloseEventPayload(target));
}
}, ActionLink.ActionType.EDIT, IdRepoEntitlement.USER_UPDATE);
builder.addAction(new ActionLink<>() {
private static final long serialVersionUID = 2555747430358755813L;
@Override
public void onClick(final AjaxRequestTarget target, final LinkedAccountTO linkedAccountTO) {
try {
linkedAccountTO.setSuspended(!linkedAccountTO.isSuspended());
LinkedAccountUR linkedAccountUR = new LinkedAccountUR.Builder().
operation(PatchOperation.ADD_REPLACE).
linkedAccountTO(linkedAccountTO).build();
UserUR req = new UserUR();
req.setKey(model.getObject().getKey());
req.getLinkedAccounts().add(linkedAccountUR);
model.setObject(userRestClient.update(model.getObject().getETagValue(), req).getEntity());
SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
} catch (SyncopeClientException e) {
LOG.error("While toggling status of linked account", e);
SyncopeConsoleSession.get().onException(e);
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
checkAddButton(model.getObject().getRealm());
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
send(LinkedAccountModalPanel.this, Broadcast.DEPTH, new ListViewPanel.ListViewReload<>(target));
}
}, ActionLink.ActionType.ENABLE, IdRepoEntitlement.USER_UPDATE);
}
builder.addAction(new ActionLink<>() {
private static final long serialVersionUID = 2555747430358755813L;
@Override
public void onClick(final AjaxRequestTarget target, final LinkedAccountTO linkedAccountTO) {
mlp.next("PUSH " + linkedAccountTO.getResource(),
new ReconTaskPanel(
linkedAccountTO.getResource(),
new PushTaskTO(),
model.getObject().getType(),
null,
ConnIdSpecialName.UID + "==" + linkedAccountTO.getConnObjectKeyValue(),
true,
mlp,
pageRef),
target);
target.add(mlp);
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
send(LinkedAccountModalPanel.this, Broadcast.BREADTH,
new ActionLinksTogglePanel.ActionLinkToggleCloseEventPayload(target));
}
}, ActionLink.ActionType.RECONCILIATION_PUSH,
String.format("%s,%s", IdRepoEntitlement.USER_READ, IdRepoEntitlement.TASK_EXECUTE));
builder.addAction(new ActionLink<>() {
private static final long serialVersionUID = 2555747430358755813L;
@Override
public void onClick(final AjaxRequestTarget target, final LinkedAccountTO linkedAccountTO) {
mlp.next("PULL " + linkedAccountTO.getResource(),
new ReconTaskPanel(
linkedAccountTO.getResource(),
new PullTaskTO(),
model.getObject().getType(),
null,
ConnIdSpecialName.UID + "==" + linkedAccountTO.getConnObjectKeyValue(),
true,
mlp,
pageRef),
target);
target.add(mlp);
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
send(LinkedAccountModalPanel.this, Broadcast.BREADTH,
new ActionLinksTogglePanel.ActionLinkToggleCloseEventPayload(target));
}
}, ActionLink.ActionType.RECONCILIATION_PULL,
String.format("%s,%s", IdRepoEntitlement.USER_READ, IdRepoEntitlement.TASK_EXECUTE));
if (!reconciliationOnly) {
builder.addAction(new ActionLink<>() {
private static final long serialVersionUID = 2555747430358755813L;
@Override
public void onClick(final AjaxRequestTarget target, final LinkedAccountTO linkedAccountTO) {
try {
LinkedAccountUR linkedAccountUR = new LinkedAccountUR.Builder().
operation(PatchOperation.DELETE).
linkedAccountTO(linkedAccountTO).build();
UserUR req = new UserUR();
req.setKey(model.getObject().getKey());
req.getLinkedAccounts().add(linkedAccountUR);
model.setObject(userRestClient.update(model.getObject().getETagValue(), req).getEntity());
linkedAccountTOs.remove(linkedAccountTO);
SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
} catch (Exception e) {
LOG.error("While removing linked account {}", linkedAccountTO.getKey(), e);
SyncopeConsoleSession.get().onException(e);
}
checkAddButton(model.getObject().getRealm());
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
send(LinkedAccountModalPanel.this, Broadcast.DEPTH, new ListViewPanel.ListViewReload<>(target));
}
}, ActionLink.ActionType.DELETE, IdRepoEntitlement.USER_UPDATE, true);
}
builder.addNewItemPanelBuilder(wizard);
list = builder.build(MultilevelPanel.FIRST_LEVEL_ID);
list.setOutputMarkupId(true);
list.setReadOnly(!SyncopeConsoleSession.get().
owns(IdRepoEntitlement.USER_UPDATE, model.getObject().getRealm()));
addAjaxLink = new AjaxLink<>("add") {
private static final long serialVersionUID = -7978723352517770644L;
@Override
public void onClick(final AjaxRequestTarget target) {
send(LinkedAccountModalPanel.this, Broadcast.BREADTH,
new ActionLinksTogglePanel.ActionLinkToggleCloseEventPayload(target));
// this opens the wizard (set above) in CREATE mode
send(list, Broadcast.DEPTH, new AjaxWizard.NewItemActionEvent<>(new LinkedAccountTO(), target).
setTitleModel(
new StringResourceModel("inner.create.linkedAccount", LinkedAccountModalPanel.this)));
}
};
list.addOrReplaceInnerObject(addAjaxLink.setEnabled(!reconciliationOnly).setVisible(!reconciliationOnly));
add(mlp.setFirstLevel(list));
}