use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class AbstractAnyLogic method beforeCreate.
protected Pair<TO, List<LogicActions>> beforeCreate(final TO input) {
Realm realm = realmDAO.findByFullPath(input.getRealm());
if (realm == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
sce.getElements().add(input.getRealm());
throw sce;
}
AnyType anyType = input instanceof UserTO ? anyTypeDAO.findUser() : input instanceof GroupTO ? anyTypeDAO.findGroup() : anyTypeDAO.find(input.getType());
if (anyType == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
sce.getElements().add(input.getType());
throw sce;
}
TO any = input;
templateUtils.apply(any, realm.getTemplate(anyType));
List<LogicActions> actions = getActions(realm);
for (LogicActions action : actions) {
any = action.beforeCreate(any);
}
LOG.debug("Input: {}\nOutput: {}\n", input, any);
return ImmutablePair.of(any, actions);
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class NotificationManagerImpl method createTasks.
@Override
public List<NotificationTask> createTasks(final AuditElements.EventCategoryType type, final String category, final String subcategory, final String event, final Result condition, final Object before, final Object output, final Object... input) {
Any<?> any = null;
if (before instanceof UserTO) {
any = userDAO.find(((UserTO) before).getKey());
} else if (output instanceof UserTO) {
any = userDAO.find(((UserTO) output).getKey());
} else if (output instanceof Pair && ((Pair) output).getRight() instanceof UserTO) {
any = userDAO.find(((UserTO) ((Pair) output).getRight()).getKey());
} else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof UserTO) {
any = userDAO.find(((ProvisioningResult) output).getEntity().getKey());
} else if (before instanceof AnyObjectTO) {
any = anyObjectDAO.find(((AnyObjectTO) before).getKey());
} else if (output instanceof AnyObjectTO) {
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());
} else if (output instanceof GroupTO) {
any = groupDAO.find(((GroupTO) output).getKey());
} else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof GroupTO) {
any = groupDAO.find(((ProvisioningResult) output).getEntity().getKey());
}
AnyType anyType = any == null ? null : any.getType();
LOG.debug("Search notification for [{}]{}", anyType, any);
List<NotificationTask> notifications = new ArrayList<>();
for (Notification notification : notificationDAO.findAll()) {
if (LOG.isDebugEnabled()) {
notification.getAbouts().forEach(about -> {
LOG.debug("Notification about {} defined: {}", about.getAnyType(), about.get());
});
}
if (notification.isActive()) {
String currentEvent = AuditLoggerName.buildEvent(type, category, subcategory, event, condition);
if (!notification.getEvents().contains(currentEvent)) {
LOG.debug("No events found about {}", any);
} else if (anyType == null || any == null || !notification.getAbout(anyType).isPresent() || searchDAO.matches(any, SearchCondConverter.convert(notification.getAbout(anyType).get().get()))) {
LOG.debug("Creating notification task for event {} about {}", currentEvent, any);
final Map<String, Object> model = new HashMap<>();
model.put("type", type);
model.put("category", category);
model.put("subcategory", subcategory);
model.put("event", event);
model.put("condition", condition);
model.put("before", before);
model.put("output", output);
model.put("input", input);
if (any instanceof User) {
model.put("user", userDataBinder.getUserTO((User) any, true));
} else if (any instanceof Group) {
model.put("group", groupDataBinder.getGroupTO((Group) any, true));
} else if (any instanceof AnyObject) {
model.put("group", anyObjectDataBinder.getAnyObjectTO((AnyObject) any, true));
}
NotificationTask notificationTask = getNotificationTask(notification, any, model);
notificationTask = taskDAO.save(notificationTask);
notifications.add(notificationTask);
}
} else {
LOG.debug("Notification {} is not active, task will not be created", notification.getKey());
}
}
return notifications;
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class MappingManagerImpl method setIntValues.
@Transactional(readOnly = true)
@Override
public void setIntValues(final Item mapItem, final Attribute attr, final AnyTO anyTO, final AnyUtils anyUtils) {
List<Object> values = null;
if (attr != null) {
values = attr.getValue();
for (ItemTransformer transformer : MappingUtils.getItemTransformers(mapItem)) {
values = transformer.beforePull(mapItem, anyTO, values);
}
}
values = values == null ? Collections.emptyList() : values;
IntAttrName intAttrName;
try {
intAttrName = intAttrNameParser.parse(mapItem.getIntAttrName(), anyUtils.getAnyTypeKind());
} catch (ParseException e) {
LOG.error("Invalid intAttrName '{}' specified, ignoring", mapItem.getIntAttrName(), e);
return;
}
if (intAttrName.getField() != null) {
switch(intAttrName.getField()) {
case "password":
if (anyTO instanceof UserTO && !values.isEmpty()) {
((UserTO) anyTO).setPassword(ConnObjectUtils.getPassword(values.get(0)));
}
break;
case "username":
if (anyTO instanceof UserTO) {
((UserTO) anyTO).setUsername(values.isEmpty() || values.get(0) == null ? null : values.get(0).toString());
}
break;
case "name":
if (anyTO instanceof GroupTO) {
((GroupTO) anyTO).setName(values.isEmpty() || values.get(0) == null ? null : values.get(0).toString());
} else if (anyTO instanceof AnyObjectTO) {
((AnyObjectTO) anyTO).setName(values.isEmpty() || values.get(0) == null ? null : values.get(0).toString());
}
break;
case "mustChangePassword":
if (anyTO instanceof UserTO && !values.isEmpty() && values.get(0) != null) {
((UserTO) anyTO).setMustChangePassword(BooleanUtils.toBoolean(values.get(0).toString()));
}
break;
case "userOwner":
case "groupOwner":
if (anyTO instanceof GroupTO && attr != null) {
// using a special attribute (with schema "", that will be ignored) for carrying the
// GroupOwnerSchema value
AttrTO attrTO = new AttrTO();
attrTO.setSchema(StringUtils.EMPTY);
if (values.isEmpty() || values.get(0) == null) {
attrTO.getValues().add(StringUtils.EMPTY);
} else {
attrTO.getValues().add(values.get(0).toString());
}
((GroupTO) anyTO).getPlainAttrs().add(attrTO);
}
break;
default:
}
} else if (intAttrName.getSchemaType() != null) {
GroupableRelatableTO groupableTO = null;
Group group = null;
if (anyTO instanceof GroupableRelatableTO && intAttrName.getMembershipOfGroup() != null) {
groupableTO = (GroupableRelatableTO) anyTO;
group = groupDAO.findByName(intAttrName.getMembershipOfGroup());
}
switch(intAttrName.getSchemaType()) {
case PLAIN:
AttrTO attrTO = new AttrTO();
attrTO.setSchema(intAttrName.getSchemaName());
PlainSchema schema = plainSchemaDAO.find(intAttrName.getSchemaName());
for (Object value : values) {
AttrSchemaType schemaType = schema == null ? AttrSchemaType.String : schema.getType();
if (value != null) {
PlainAttrValue attrValue = anyUtils.newPlainAttrValue();
switch(schemaType) {
case String:
attrValue.setStringValue(value.toString());
break;
case Binary:
attrValue.setBinaryValue((byte[]) value);
break;
default:
try {
attrValue.parseValue(schema, value.toString());
} catch (ParsingValidationException e) {
LOG.error("While parsing provided value {}", value, e);
attrValue.setStringValue(value.toString());
schemaType = AttrSchemaType.String;
}
break;
}
attrTO.getValues().add(attrValue.getValueAsString(schemaType));
}
}
if (groupableTO == null || group == null) {
anyTO.getPlainAttrs().add(attrTO);
} else {
Optional<MembershipTO> membership = groupableTO.getMembership(group.getKey());
if (!membership.isPresent()) {
membership = Optional.of(new MembershipTO.Builder().group(group.getKey(), group.getName()).build());
groupableTO.getMemberships().add(membership.get());
}
membership.get().getPlainAttrs().add(attrTO);
}
break;
case DERIVED:
attrTO = new AttrTO();
attrTO.setSchema(intAttrName.getSchemaName());
if (groupableTO == null || group == null) {
anyTO.getDerAttrs().add(attrTO);
} else {
Optional<MembershipTO> membership = groupableTO.getMembership(group.getKey());
if (!membership.isPresent()) {
membership = Optional.of(new MembershipTO.Builder().group(group.getKey(), group.getName()).build());
groupableTO.getMemberships().add(membership.get());
}
membership.get().getDerAttrs().add(attrTO);
}
break;
case VIRTUAL:
attrTO = new AttrTO();
attrTO.setSchema(intAttrName.getSchemaName());
// virtual attributes don't get transformed, iterate over original attr.getValue()
if (attr != null && attr.getValue() != null && !attr.getValue().isEmpty()) {
attr.getValue().stream().filter(value -> value != null).forEachOrdered(value -> attrTO.getValues().add(value.toString()));
}
if (groupableTO == null || group == null) {
anyTO.getVirAttrs().add(attrTO);
} else {
Optional<MembershipTO> membership = groupableTO.getMembership(group.getKey());
if (!membership.isPresent()) {
membership = Optional.of(new MembershipTO.Builder().group(group.getKey(), group.getName()).build());
groupableTO.getMemberships().add(membership.get());
}
membership.get().getVirAttrs().add(attrTO);
}
break;
default:
}
}
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class GroupDataBinderImpl method getGroupTO.
@Transactional(readOnly = true)
@Override
public GroupTO getGroupTO(final Group group, final boolean details) {
GroupTO groupTO = new GroupTO();
// set sys info
groupTO.setCreator(group.getCreator());
groupTO.setCreationDate(group.getCreationDate());
groupTO.setLastModifier(group.getLastModifier());
groupTO.setLastChangeDate(group.getLastChangeDate());
groupTO.setKey(group.getKey());
groupTO.setName(group.getName());
if (group.getUserOwner() != null) {
groupTO.setUserOwner(group.getUserOwner().getKey());
}
if (group.getGroupOwner() != null) {
groupTO.setGroupOwner(group.getGroupOwner().getKey());
}
Map<DerSchema, String> derAttrValues = derAttrHandler.getValues(group);
Map<VirSchema, List<String>> virAttrValues = details ? virAttrHandler.getValues(group) : Collections.<VirSchema, List<String>>emptyMap();
fillTO(groupTO, group.getRealm().getFullPath(), group.getAuxClasses(), group.getPlainAttrs(), derAttrValues, virAttrValues, group.getResources(), details);
if (details) {
// dynamic realms
groupTO.getDynRealms().addAll(groupDAO.findDynRealms(group.getKey()));
}
// Static user and AnyType membership counts
groupTO.setStaticUserMembershipCount(groupDAO.countUMembers(group));
groupTO.setStaticAnyObjectMembershipCount(groupDAO.countAMembers(group));
// Dynamic user and AnyType membership counts
groupTO.setDynamicUserMembershipCount(groupDAO.countUDynMembers(group));
groupTO.setDynamicAnyObjectMembershipCount(groupDAO.countADynMembers(group));
if (group.getUDynMembership() != null) {
groupTO.setUDynMembershipCond(group.getUDynMembership().getFIQLCond());
}
group.getADynMemberships().forEach(memb -> {
groupTO.getADynMembershipConds().put(memb.getAnyType().getKey(), memb.getFIQLCond());
});
group.getTypeExtensions().forEach(typeExt -> {
groupTO.getTypeExtensions().add(getTypeExtensionTO(typeExt));
});
return groupTO;
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class SearchClausePanel method settingsDependingComponents.
@Override
public FieldPanel<SearchClause> settingsDependingComponents() {
final SearchClause searchClause = this.clause.getObject();
final WebMarkupContainer operatorContainer = new WebMarkupContainer("operatorContainer");
operatorContainer.setOutputMarkupId(true);
field.add(operatorContainer);
final BootstrapToggleConfig config = new BootstrapToggleConfig().withOnStyle(BootstrapToggleConfig.Style.info).withOffStyle(BootstrapToggleConfig.Style.warning).withSize(BootstrapToggleConfig.Size.mini);
operatorFragment.add(new BootstrapToggle("operator", new Model<Boolean>() {
private static final long serialVersionUID = -7157802546272668001L;
@Override
public Boolean getObject() {
return searchClause.getOperator() == Operator.AND;
}
@Override
public void setObject(final Boolean object) {
searchClause.setOperator(object ? Operator.AND : Operator.OR);
}
}, config) {
private static final long serialVersionUID = 2969634208049189343L;
@Override
protected IModel<String> getOffLabel() {
return Model.of("OR");
}
@Override
protected IModel<String> getOnLabel() {
return Model.of("AND");
}
@Override
protected CheckBox newCheckBox(final String id, final IModel<Boolean> model) {
final CheckBox checkBox = super.newCheckBox(id, model);
checkBox.add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
}
});
return checkBox;
}
}.setOutputMarkupPlaceholderTag(true));
if (getIndex() > 0) {
operatorContainer.add(operatorFragment);
} else {
operatorContainer.add(searchButtonFragment);
}
final AjaxTextFieldPanel property = new AjaxTextFieldPanel("property", "property", new PropertyModel<String>(searchClause, "property"), false);
property.hideLabel().setOutputMarkupId(true).setEnabled(true);
property.setChoices(properties.getObject());
field.add(property);
property.getField().add(AttributeModifier.replace("onkeydown", Model.of("if(event.keyCode == 13) { event.preventDefault(); }")));
property.getField().add(new IndicatorAjaxEventBehavior("onkeyup") {
private static final long serialVersionUID = -7866120562087857309L;
@Override
protected void onEvent(final AjaxRequestTarget target) {
if (field.getModel().getObject() == null || field.getModel().getObject().getType() == null) {
return;
}
if (field.getModel().getObject().getType() == Type.GROUP_MEMBERSHIP) {
String[] inputAsArray = property.getField().getInputAsArray();
if (StringUtils.isBlank(property.getField().getInput()) || inputAsArray.length == 0) {
property.setChoices(properties.getObject());
} else {
String inputValue = (inputAsArray.length > 1 && inputAsArray[1] != null) ? inputAsArray[1] : property.getField().getInput();
inputValue = (inputValue.startsWith("*") && !inputValue.endsWith("*")) ? inputValue + "*" : (!inputValue.startsWith("*") && inputValue.endsWith("*")) ? "*" + inputValue : (inputValue.startsWith("*") && inputValue.endsWith("*") ? inputValue : "*" + inputValue + "*");
if (groupInfo.getRight() > AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY) {
List<GroupTO> filteredGroups = groupRestClient.search("/", SyncopeClient.getGroupSearchConditionBuilder().is("name").equalToIgnoreCase(inputValue).query(), 1, AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY, new SortParam<>("name", true), null);
Collection<String> newList = CollectionUtils.collect(filteredGroups, new Transformer<GroupTO, String>() {
@Override
public String transform(final GroupTO input) {
return input.getName();
}
});
final List<String> names = new ArrayList<>(newList);
Collections.sort(names);
property.setChoices(names);
}
}
}
}
@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getAjaxCallListeners().clear();
}
}, new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
}
});
final AjaxDropDownChoicePanel<SearchClause.Comparator> comparator = new AjaxDropDownChoicePanel<>("comparator", "comparator", new PropertyModel<>(searchClause, "comparator"));
comparator.setChoices(comparators);
comparator.setNullValid(false).hideLabel().setOutputMarkupId(true);
comparator.setRequired(required);
comparator.setChoiceRenderer(getComparatorRender(field.getModel()));
field.add(comparator);
final AjaxTextFieldPanel value = new AjaxTextFieldPanel("value", "value", new PropertyModel<>(searchClause, "value"), false);
value.hideLabel().setOutputMarkupId(true);
field.add(value);
value.getField().add(AttributeModifier.replace("onkeydown", Model.of("if(event.keyCode == 13) {event.preventDefault();}")));
value.getField().add(new IndicatorAjaxEventBehavior("onkeydown") {
private static final long serialVersionUID = -7133385027739964990L;
@Override
protected void onEvent(final AjaxRequestTarget target) {
target.focusComponent(null);
value.getField().inputChanged();
value.getField().validate();
if (value.getField().isValid()) {
value.getField().valid();
value.getField().updateModel();
}
}
@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getAjaxCallListeners().add(new AjaxCallListener() {
private static final long serialVersionUID = 7160235486520935153L;
@Override
public CharSequence getPrecondition(final Component component) {
return "if (Wicket.Event.keyCode(attrs.event) == 13) { return true; } else { return false; }";
}
});
}
});
final AjaxDropDownChoicePanel<SearchClause.Type> type = new AjaxDropDownChoicePanel<>("type", "type", new PropertyModel<>(searchClause, "type"));
type.setChoices(types).hideLabel().setRequired(required).setOutputMarkupId(true);
type.setNullValid(false);
type.getField().add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
final SearchClause searchClause = new SearchClause();
if (StringUtils.isNotEmpty(type.getDefaultModelObjectAsString())) {
searchClause.setType(Type.valueOf(type.getDefaultModelObjectAsString()));
}
SearchClausePanel.this.clause.setObject(searchClause);
setFieldAccess(searchClause.getType(), property, comparator, value);
// reset property value in case and just in case of change of type
property.setModelObject(StringUtils.EMPTY);
target.add(property);
target.add(comparator);
target.add(value);
}
});
field.add(type);
comparator.getField().add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
if (type.getModelObject() == SearchClause.Type.ATTRIBUTE || type.getModelObject() == SearchClause.Type.RELATIONSHIP) {
if (comparator.getModelObject() == SearchClause.Comparator.IS_NULL || comparator.getModelObject() == SearchClause.Comparator.IS_NOT_NULL) {
value.setModelObject(StringUtils.EMPTY);
value.setEnabled(false);
} else {
value.setEnabled(true);
}
target.add(value);
}
if (type.getModelObject() == SearchClause.Type.RELATIONSHIP) {
property.setEnabled(true);
final SearchClause searchClause = new SearchClause();
searchClause.setType(Type.valueOf(type.getDefaultModelObjectAsString()));
searchClause.setComparator(comparator.getModelObject());
SearchClausePanel.this.clause.setObject(searchClause);
target.add(property);
}
}
});
setFieldAccess(searchClause.getType(), property, comparator, value);
return this;
}
Aggregations