use of org.identityconnectors.framework.common.objects.Name in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method getUid.
/**
* Looks up ConnId Uid identifier in a (potentially multi-valued) set of
* identifiers. Handy method to convert midPoint identifier style to an ICF
* identifier style.
*
* @param identifiers
* midPoint resource object identifiers
* @return ConnId UID or null
*/
private Uid getUid(ObjectClassComplexTypeDefinition objectClass, Collection<? extends ResourceAttribute<?>> identifiers) throws SchemaException {
if (identifiers.size() == 0) {
return null;
}
if (identifiers.size() == 1) {
try {
return new Uid((String) identifiers.iterator().next().getRealValue());
} catch (IllegalArgumentException e) {
throw new SchemaException(e.getMessage(), e);
}
}
String uidValue = null;
String nameValue = null;
for (ResourceAttribute<?> attr : identifiers) {
if (objectClass.isPrimaryIdentifier(attr.getElementName())) {
uidValue = ((ResourceAttribute<String>) attr).getValue().getValue();
}
if (objectClass.isSecondaryIdentifier(attr.getElementName())) {
ResourceAttributeDefinition<?> attrDef = objectClass.findAttributeDefinition(attr.getElementName());
String frameworkAttributeName = attrDef.getFrameworkAttributeName();
if (Name.NAME.equals(frameworkAttributeName)) {
nameValue = ((ResourceAttribute<String>) attr).getValue().getValue();
}
}
}
if (uidValue != null) {
if (nameValue == null) {
return new Uid(uidValue);
} else {
return new Uid(uidValue, new Name(nameValue));
}
}
// fallback, compatibility
for (ResourceAttribute<?> attr : identifiers) {
if (attr.getElementName().equals(SchemaConstants.ICFS_UID)) {
return new Uid(((ResourceAttribute<String>) attr).getValue().getValue());
}
}
return null;
}
use of org.identityconnectors.framework.common.objects.Name in project syncope by apache.
the class GoogleAppsPropagationActions method before.
@Transactional
@Override
public void before(final PropagationTask task, final ConnectorObject beforeObj) {
if (task.getOperation() == ResourceOperation.DELETE || task.getOperation() == ResourceOperation.NONE) {
return;
}
if (AnyTypeKind.USER != task.getAnyTypeKind()) {
return;
}
Set<Attribute> attrs = new HashSet<>(task.getAttributes());
// ensure to set __NAME__ value to user's email (e.g. primary e-mail address)
User user = userDAO.find(task.getEntityKey());
if (user == null) {
LOG.error("Could not find user {}, skipping", task.getEntityKey());
} else {
Name name = AttributeUtil.getNameFromAttributes(attrs);
if (name != null) {
attrs.remove(name);
}
attrs.add(new Name(user.getPlainAttr(getEmailSchema()).get().getValuesAsStrings().get(0)));
}
task.setAttributes(attrs);
}
use of org.identityconnectors.framework.common.objects.Name in project syncope by apache.
the class PullUtils method match.
public Optional<String> match(final AnyType anyType, final String name, final ExternalResource resource, final Connector connector) {
Optional<? extends Provision> provision = resource.getProvision(anyType);
if (!provision.isPresent()) {
return Optional.empty();
}
Optional<String> result = Optional.empty();
AnyUtils anyUtils = anyUtilsFactory.getInstance(anyType.getKind());
final List<ConnectorObject> found = new ArrayList<>();
connector.search(provision.get().getObjectClass(), new EqualsFilter(new Name(name)), obj -> found.add(obj), MappingUtils.buildOperationOptions(MappingUtils.getPullItems(provision.get().getMapping().getItems()).iterator()));
if (found.isEmpty()) {
LOG.debug("No {} found on {} with __NAME__ {}", provision.get().getObjectClass(), resource, name);
} else {
if (found.size() > 1) {
LOG.warn("More than one {} found on {} with __NAME__ {} - taking first only", provision.get().getObjectClass(), resource, name);
}
ConnectorObject connObj = found.iterator().next();
try {
List<String> anyKeys = match(connObj, provision.get(), anyUtils);
if (anyKeys.isEmpty()) {
LOG.debug("No matching {} found for {}, aborting", anyUtils.getAnyTypeKind(), connObj);
} else {
if (anyKeys.size() > 1) {
LOG.warn("More than one {} found {} - taking first only", anyUtils.getAnyTypeKind(), anyKeys);
}
result = Optional.ofNullable(anyKeys.iterator().next());
}
} catch (IllegalArgumentException e) {
LOG.warn(e.getMessage());
}
}
return result;
}
use of org.identityconnectors.framework.common.objects.Name in project syncope by apache.
the class MappingUtils method getName.
private static Name getName(final String evalConnObjectLink, final String connObjectKey) {
// If connObjectLink evaluates to an empty string, just use the provided connObjectKey as Name(),
// otherwise evaluated connObjectLink expression is taken as Name().
Name name;
if (StringUtils.isBlank(evalConnObjectLink)) {
// add connObjectKey as __NAME__ attribute ...
LOG.debug("Add connObjectKey [{}] as __NAME__", connObjectKey);
name = new Name(connObjectKey);
} else {
LOG.debug("Add connObjectLink [{}] as __NAME__", evalConnObjectLink);
name = new Name(evalConnObjectLink);
// connObjectKey not propagated: it will be used to set the value for __UID__ attribute
LOG.debug("connObjectKey will be used just as __UID__ attribute");
}
return name;
}
use of org.identityconnectors.framework.common.objects.Name 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:
}
}
}
Aggregations