});
bundle.addRequiredLabel();
bundle.setEnabled(connectorTO.getId() == 0);
final ListView<ConnConfProperty> view = new ListView<ConnConfProperty>(
"connectorProperties", new PropertyModel(this, "properties")) {
private static final long serialVersionUID = 9101744072914090143L;
@Override
protected void populateItem(final ListItem<ConnConfProperty> item) {
final ConnConfProperty property = item.getModelObject();
final Label label = new Label("connPropAttrSchema", property.getSchema().getDisplayName() == null
|| property.getSchema().getDisplayName().isEmpty()
? property.getSchema().getName()
: property.getSchema().getDisplayName());
item.add(label);
final FieldPanel field;
boolean required = false;
boolean isArray = false;
if (property.getSchema().isConfidential()
|| GUARDED_STRING.equalsIgnoreCase(property.getSchema().getType())
|| GUARDED_BYTE_ARRAY.equalsIgnoreCase(property.getSchema().getType())) {
field = new AjaxPasswordFieldPanel("panel", label.getDefaultModelObjectAsString(), new Model());
((PasswordTextField) field.getField()).setResetPassword(false);
required = property.getSchema().isRequired();
} else {
Class propertySchemaClass;
try {
propertySchemaClass =
ClassUtils.forName(property.getSchema().getType(), ClassUtils.getDefaultClassLoader());
} catch (Exception e) {
LOG.error("Error parsing attribute type", e);
propertySchemaClass = String.class;
}
if (NUMBER.contains(propertySchemaClass)) {
field = new AjaxNumberFieldPanel("panel", label.getDefaultModelObjectAsString(), new Model(),
ClassUtils.resolvePrimitiveIfNecessary(propertySchemaClass));
required = property.getSchema().isRequired();
} else if (Boolean.class.equals(propertySchemaClass) || boolean.class.equals(propertySchemaClass)) {
field = new AjaxCheckBoxPanel("panel", label.getDefaultModelObjectAsString(), new Model());
} else {
field = new AjaxTextFieldPanel("panel", label.getDefaultModelObjectAsString(), new Model());
required = property.getSchema().isRequired();
}
if (String[].class.equals(propertySchemaClass)) {
isArray = true;
}
}
field.setTitle(property.getSchema().getHelpMessage());
if (isArray) {
field.removeRequiredLabel();
if (property.getValues().isEmpty()) {
property.getValues().add(null);
}
item.add(new MultiValueSelectorPanel<String>(
"panel", new PropertyModel<List<String>>(property, "values"), field));
} else {
if (required) {
field.addRequiredLabel();
}
field.setNewModel(property.getValues());
item.add(field);
}
final AjaxCheckBoxPanel overridable = new AjaxCheckBoxPanel("connPropAttrOverridable",
"connPropAttrOverridable", new PropertyModel(property, "overridable"));
item.add(overridable);
connectorTO.addConfiguration(property);
}
};
final Form connectorForm = new Form("form");
connectorForm.setModel(new CompoundPropertyModel(connectorTO));
final Form connectorPropForm = new Form("connectorPropForm");
connectorPropForm.setModel(new CompoundPropertyModel(connectorTO));
connectorPropForm.setOutputMarkupId(true);
propertiesContainer = new WebMarkupContainer("container");
propertiesContainer.setOutputMarkupId(true);
propertiesContainer.add(connectorPropForm);
connectorForm.add(propertiesContainer);
connectorPropForm.add(view);
final AjaxLink check = new IndicatingAjaxLink("check", new ResourceModel("check")) {
private static final long serialVersionUID = -7978723352517770644L;
@Override
public void onClick(final AjaxRequestTarget target) {
connectorTO.setBundleName(bundleTO.getBundleName());
connectorTO.setVersion(bundleTO.getVersion());
if (restClient.check(connectorTO).booleanValue()) {
info(getString("success_connection"));
} else {
error(getString("error_connection"));
}
target.add(feedbackPanel);
}
};
connectorPropForm.add(check);
final AjaxButton submit = new IndicatingAjaxButton("apply", new Model(getString("submit"))) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form form) {
final ConnInstanceTO conn = (ConnInstanceTO) form.getDefaultModelObject();
conn.setBundleName(bundleTO.getBundleName());
// Set the model object's capabilites to capabilitiesPalette's converted Set
conn.setCapabilities(selectedCapabilities.isEmpty()
? EnumSet.noneOf(ConnectorCapability.class)
: EnumSet.copyOf(selectedCapabilities));
try {
if (connectorTO.getId() == 0) {
restClient.create(conn);
} else {
restClient.update(conn);
}
((Resources) callerPageRef.getPage()).setModalResult(true);
window.close(target);
} catch (SyncopeClientCompositeErrorException e) {
error(getString("error") + ":" + e.getMessage());
target.add(feedbackPanel);
((Resources) callerPageRef.getPage()).setModalResult(false);
LOG.error("While creating or updating connector {}", conn, e);
}
}
@Override
protected void onError(final AjaxRequestTarget target, final Form form) {
target.add(feedbackPanel);
}
};
String roles = connectorTO.getId() == 0
? xmlRolesReader.getAllAllowedRoles("Connectors", "create")
: xmlRolesReader.getAllAllowedRoles("Connectors", "update");
MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, roles);
connectorForm.add(connectorName);
connectorForm.add(displayName);
connectorForm.add(bundle);
connectorForm.add(version);
capabilitiesPalette = new CheckBoxMultipleChoice("capabilitiesPalette", new PropertyModel(this,
"selectedCapabilities"), capabilities);
connectorForm.add(capabilitiesPalette);
connectorForm.add(submit);