use of org.identityconnectors.framework.common.objects.Attribute in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method dumpAttributes.
private String dumpAttributes(Set<Attribute> attributes) {
if (attributes == null) {
return "(null)";
}
if (attributes.isEmpty()) {
return "(empty)";
}
StringBuilder sb = new StringBuilder();
for (Attribute attr : attributes) {
sb.append("\n");
if (attr.getValue() == null || attr.getValue().isEmpty()) {
sb.append(attr.getName());
sb.append(" (empty)");
} else {
for (Object value : attr.getValue()) {
sb.append(attr.getName());
sb.append(" = ");
sb.append(value);
}
}
}
return sb.toString();
}
use of org.identityconnectors.framework.common.objects.Attribute in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method addObject.
@Override
public AsynchronousOperationReturnValue<Collection<ResourceAttribute<?>>> addObject(PrismObject<? extends ShadowType> shadow, Collection<Operation> additionalOperations, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, ObjectAlreadyExistsException, ConfigurationException {
validateShadow(shadow, "add", false);
ShadowType shadowType = shadow.asObjectable();
ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadow);
OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".addObject");
result.addParam("resourceObject", shadow);
// because of serialization issues
result.addParam("additionalOperations", DebugUtil.debugDump(additionalOperations));
ObjectClassComplexTypeDefinition ocDef;
ResourceAttributeContainerDefinition attrContDef = attributesContainer.getDefinition();
if (attrContDef != null) {
ocDef = attrContDef.getComplexTypeDefinition();
} else {
ocDef = resourceSchema.findObjectClassDefinition(shadow.asObjectable().getObjectClass());
if (ocDef == null) {
throw new SchemaException("Unknown object class " + shadow.asObjectable().getObjectClass());
}
}
// getting icf object class from resource object class
ObjectClass icfObjectClass = connIdNameMapper.objectClassToIcf(shadow, getSchemaNamespace(), connectorType, legacySchema);
if (icfObjectClass == null) {
result.recordFatalError("Couldn't get icf object class from " + shadow);
throw new IllegalArgumentException("Couldn't get icf object class from " + shadow);
}
// setting ifc attributes from resource object attributes
Set<Attribute> attributes = null;
try {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("midPoint object before conversion:\n{}", attributesContainer.debugDump());
}
attributes = connIdConvertor.convertFromResourceObject(attributesContainer, ocDef);
if (shadowType.getCredentials() != null && shadowType.getCredentials().getPassword() != null) {
PasswordType password = shadowType.getCredentials().getPassword();
ProtectedStringType protectedString = password.getValue();
GuardedString guardedPassword = ConnIdUtil.toGuardedString(protectedString, "new password", protector);
if (guardedPassword != null) {
attributes.add(AttributeBuilder.build(OperationalAttributes.PASSWORD_NAME, guardedPassword));
}
}
if (ActivationUtil.hasAdministrativeActivation(shadowType)) {
attributes.add(AttributeBuilder.build(OperationalAttributes.ENABLE_NAME, ActivationUtil.isAdministrativeEnabled(shadowType)));
}
if (ActivationUtil.hasValidFrom(shadowType)) {
attributes.add(AttributeBuilder.build(OperationalAttributes.ENABLE_DATE_NAME, XmlTypeConverter.toMillis(shadowType.getActivation().getValidFrom())));
}
if (ActivationUtil.hasValidTo(shadowType)) {
attributes.add(AttributeBuilder.build(OperationalAttributes.DISABLE_DATE_NAME, XmlTypeConverter.toMillis(shadowType.getActivation().getValidTo())));
}
if (ActivationUtil.hasLockoutStatus(shadowType)) {
attributes.add(AttributeBuilder.build(OperationalAttributes.LOCK_OUT_NAME, ActivationUtil.isLockedOut(shadowType)));
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("ICF attributes after conversion:\n{}", ConnIdUtil.dump(attributes));
}
} catch (SchemaException | RuntimeException ex) {
result.recordFatalError("Error while converting resource object attributes. Reason: " + ex.getMessage(), ex);
throw new SchemaException("Error while converting resource object attributes. Reason: " + ex.getMessage(), ex);
}
if (attributes == null) {
result.recordFatalError("Couldn't set attributes for icf.");
throw new IllegalStateException("Couldn't set attributes for icf.");
}
List<String> icfAuxiliaryObjectClasses = new ArrayList<>();
for (QName auxiliaryObjectClass : shadowType.getAuxiliaryObjectClass()) {
icfAuxiliaryObjectClasses.add(connIdNameMapper.objectClassToIcf(auxiliaryObjectClass, resourceSchemaNamespace, connectorType, false).getObjectClassValue());
}
if (!icfAuxiliaryObjectClasses.isEmpty()) {
AttributeBuilder ab = new AttributeBuilder();
ab.setName(PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME);
ab.addValue(icfAuxiliaryObjectClasses);
attributes.add(ab.build());
}
OperationOptionsBuilder operationOptionsBuilder = new OperationOptionsBuilder();
OperationOptions options = operationOptionsBuilder.build();
checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.BEFORE, result);
OperationResult connIdResult = result.createSubresult(ConnectorFacade.class.getName() + ".create");
connIdResult.addArbitraryObjectAsParam("objectClass", icfObjectClass);
connIdResult.addArbitraryCollectionAsParam("auxiliaryObjectClasses", icfAuxiliaryObjectClasses);
connIdResult.addArbitraryCollectionAsParam("attributes", attributes);
connIdResult.addArbitraryObjectAsParam("options", options);
connIdResult.addContext("connector", connIdConnectorFacade.getClass());
Uid uid = null;
try {
// CALL THE ICF FRAMEWORK
InternalMonitor.recordConnectorOperation("create");
// TODO provide object name
recordIcfOperationStart(reporter, ProvisioningOperation.ICF_CREATE, ocDef, null);
uid = connIdConnectorFacade.create(icfObjectClass, attributes, options);
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_CREATE, ocDef, uid);
} catch (Throwable ex) {
// TODO name
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_CREATE, ocDef, ex, null);
Throwable midpointEx = processIcfException(ex, this, connIdResult);
result.computeStatus("Add object failed");
// exception
if (midpointEx instanceof ObjectAlreadyExistsException) {
throw (ObjectAlreadyExistsException) midpointEx;
} else if (midpointEx instanceof CommunicationException) {
// result.muteError();
throw (CommunicationException) midpointEx;
} else if (midpointEx instanceof GenericFrameworkException) {
throw (GenericFrameworkException) midpointEx;
} else if (midpointEx instanceof SchemaException) {
throw (SchemaException) midpointEx;
} else if (midpointEx instanceof ConfigurationException) {
throw (ConfigurationException) midpointEx;
} else if (midpointEx instanceof RuntimeException) {
throw (RuntimeException) midpointEx;
} else if (midpointEx instanceof Error) {
throw (Error) midpointEx;
} else {
throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
}
}
checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.AFTER, result);
if (uid == null || uid.getUidValue() == null || uid.getUidValue().isEmpty()) {
connIdResult.recordFatalError("ICF did not returned UID after create");
result.computeStatus("Add object failed");
throw new GenericFrameworkException("ICF did not returned UID after create");
}
Collection<ResourceAttribute<?>> identifiers = ConnIdUtil.convertToIdentifiers(uid, attributesContainer.getDefinition().getComplexTypeDefinition(), resourceSchema);
for (ResourceAttribute<?> identifier : identifiers) {
attributesContainer.getValue().addReplaceExisting(identifier);
}
connIdResult.recordSuccess();
result.recordSuccess();
return AsynchronousOperationReturnValue.wrap(attributesContainer.getAttributes(), result);
}
use of org.identityconnectors.framework.common.objects.Attribute in project midpoint by Evolveum.
the class ConnIdConvertor method convertToResourceObject.
/**
* Converts ICF ConnectorObject to the midPoint ResourceObject.
* <p/>
* All the attributes are mapped using the same way as they are mapped in
* the schema (which is actually no mapping at all now).
* <p/>
* If an optional ResourceObjectDefinition was provided, the resulting
* ResourceObject is schema-aware (getDefinition() method works). If no
* ResourceObjectDefinition was provided, the object is schema-less. TODO:
* this still needs to be implemented.
*
* @param co
* ICF ConnectorObject to convert
* @param def
* ResourceObjectDefinition (from the schema) or null
* @param full
* if true it describes if the returned resource object should
* contain all of the attributes defined in the schema, if false
* the returned resource object will contain only attributed with
* the non-null values.
* @return new mapped ResourceObject instance.
* @throws SchemaException
*/
<T extends ShadowType> PrismObject<T> convertToResourceObject(ConnectorObject co, PrismObjectDefinition<T> objectDefinition, boolean full, boolean caseIgnoreAttributeNames, boolean legacySchema) throws SchemaException {
PrismObject<T> shadowPrism = null;
if (objectDefinition != null) {
shadowPrism = objectDefinition.instantiate();
} else {
throw new SchemaException("No definition");
}
// LOGGER.trace("Instantiated prism object {} from connector object.",
// shadowPrism.debugDump());
T shadow = shadowPrism.asObjectable();
ResourceAttributeContainer attributesContainer = (ResourceAttributeContainer) shadowPrism.findOrCreateContainer(ShadowType.F_ATTRIBUTES);
ResourceAttributeContainerDefinition attributesContainerDefinition = attributesContainer.getDefinition();
shadow.setObjectClass(attributesContainerDefinition.getTypeName());
List<ObjectClassComplexTypeDefinition> auxiliaryObjectClassDefinitions = new ArrayList<>();
for (Attribute icfAttr : co.getAttributes()) {
if (icfAttr.is(PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME)) {
List<QName> auxiliaryObjectClasses = shadow.getAuxiliaryObjectClass();
for (Object auxiliaryIcfObjectClass : icfAttr.getValue()) {
QName auxiliaryObjectClassQname = icfNameMapper.objectClassToQname(new ObjectClass((String) auxiliaryIcfObjectClass), resourceSchemaNamespace, legacySchema);
auxiliaryObjectClasses.add(auxiliaryObjectClassQname);
ObjectClassComplexTypeDefinition auxiliaryObjectClassDefinition = icfNameMapper.getResourceSchema().findObjectClassDefinition(auxiliaryObjectClassQname);
if (auxiliaryObjectClassDefinition == null) {
throw new SchemaException("Resource object " + co + " refers to auxiliary object class " + auxiliaryObjectClassQname + " which is not in the schema");
}
auxiliaryObjectClassDefinitions.add(auxiliaryObjectClassDefinition);
}
break;
}
}
for (Attribute icfAttr : co.getAttributes()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Reading ICF attribute {}: {}", icfAttr.getName(), icfAttr.getValue());
}
if (icfAttr.getName().equals(Uid.NAME)) {
// UID is handled specially (see above)
continue;
}
if (icfAttr.is(PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME)) {
// Already processed
continue;
}
if (icfAttr.getName().equals(OperationalAttributes.PASSWORD_NAME)) {
// password has to go to the credentials section
ProtectedStringType password = getSingleValue(icfAttr, ProtectedStringType.class);
if (password == null) {
// equals() instead of == is needed. The AttributeValueCompleteness enum may be loaded by different classloader
if (!AttributeValueCompleteness.INCOMPLETE.equals(icfAttr.getAttributeValueCompleteness())) {
continue;
}
// There is no password value in the ConnId attribute. But it was indicated that
// that attribute is incomplete. Therefore we can assume that there in fact is a value.
// We just do not know it.
ShadowUtil.setPasswordIncomplete(shadow);
LOGGER.trace("Converted password: (incomplete)");
} else {
ShadowUtil.setPassword(shadow, password);
LOGGER.trace("Converted password: {}", password);
}
continue;
}
if (icfAttr.getName().equals(OperationalAttributes.ENABLE_NAME)) {
Boolean enabled = getSingleValue(icfAttr, Boolean.class);
if (enabled == null) {
continue;
}
ActivationType activationType = ShadowUtil.getOrCreateActivation(shadow);
ActivationStatusType activationStatusType;
if (enabled) {
activationStatusType = ActivationStatusType.ENABLED;
} else {
activationStatusType = ActivationStatusType.DISABLED;
}
activationType.setAdministrativeStatus(activationStatusType);
activationType.setEffectiveStatus(activationStatusType);
LOGGER.trace("Converted activation administrativeStatus: {}", activationStatusType);
continue;
}
if (icfAttr.getName().equals(OperationalAttributes.ENABLE_DATE_NAME)) {
Long millis = getSingleValue(icfAttr, Long.class);
if (millis == null) {
continue;
}
ActivationType activationType = ShadowUtil.getOrCreateActivation(shadow);
activationType.setValidFrom(XmlTypeConverter.createXMLGregorianCalendar(millis));
continue;
}
if (icfAttr.getName().equals(OperationalAttributes.DISABLE_DATE_NAME)) {
Long millis = getSingleValue(icfAttr, Long.class);
if (millis == null) {
continue;
}
ActivationType activationType = ShadowUtil.getOrCreateActivation(shadow);
activationType.setValidTo(XmlTypeConverter.createXMLGregorianCalendar(millis));
continue;
}
if (icfAttr.getName().equals(OperationalAttributes.LOCK_OUT_NAME)) {
Boolean lockOut = getSingleValue(icfAttr, Boolean.class);
if (lockOut == null) {
continue;
}
ActivationType activationType = ShadowUtil.getOrCreateActivation(shadow);
LockoutStatusType lockoutStatusType;
if (lockOut) {
lockoutStatusType = LockoutStatusType.LOCKED;
} else {
lockoutStatusType = LockoutStatusType.NORMAL;
}
activationType.setLockoutStatus(lockoutStatusType);
LOGGER.trace("Converted activation lockoutStatus: {}", lockoutStatusType);
continue;
}
QName qname = icfNameMapper.convertAttributeNameToQName(icfAttr.getName(), attributesContainerDefinition);
ResourceAttributeDefinition attributeDefinition = attributesContainerDefinition.findAttributeDefinition(qname, caseIgnoreAttributeNames);
if (attributeDefinition == null) {
// Try to locate definition in auxiliary object classes
for (ObjectClassComplexTypeDefinition auxiliaryObjectClassDefinition : auxiliaryObjectClassDefinitions) {
attributeDefinition = auxiliaryObjectClassDefinition.findAttributeDefinition(qname, caseIgnoreAttributeNames);
if (attributeDefinition != null) {
break;
}
}
if (attributeDefinition == null) {
throw new SchemaException("Unknown attribute " + qname + " in definition of object class " + attributesContainerDefinition.getTypeName() + ". Original ICF name: " + icfAttr.getName(), qname);
}
}
if (caseIgnoreAttributeNames) {
// normalized version
qname = attributeDefinition.getName();
}
ResourceAttribute<Object> resourceAttribute = attributeDefinition.instantiate(qname);
// resource object also with the null-values attributes
if (full) {
if (icfAttr.getValue() != null) {
// of them may need it (e.g. GuardedString)
for (Object icfValue : icfAttr.getValue()) {
Object value = convertValueFromIcf(icfValue, qname);
resourceAttribute.add(new PrismPropertyValue<>(value));
}
}
LOGGER.trace("Converted attribute {}", resourceAttribute);
attributesContainer.getValue().add(resourceAttribute);
// in this case when false, we need only the attributes with the
// non-null values.
} else {
if (icfAttr.getValue() != null && !icfAttr.getValue().isEmpty()) {
// Convert the values. While most values do not need
// conversions, some of them may need it (e.g. GuardedString)
boolean empty = true;
for (Object icfValue : icfAttr.getValue()) {
if (icfValue != null) {
Object value = convertValueFromIcf(icfValue, qname);
empty = false;
resourceAttribute.add(new PrismPropertyValue<>(value));
}
}
if (!empty) {
LOGGER.trace("Converted attribute {}", resourceAttribute);
attributesContainer.getValue().add(resourceAttribute);
}
}
}
}
// Add Uid if it is not there already. It can be already present,
// e.g. if Uid and Name represent the same attribute
Uid uid = co.getUid();
ObjectClassComplexTypeDefinition ocDef = attributesContainerDefinition.getComplexTypeDefinition();
ResourceAttributeDefinition<String> uidDefinition = ConnIdUtil.getUidDefinition(ocDef);
if (uidDefinition == null) {
throw new SchemaException("No definition for ConnId UID attribute found in definition " + ocDef);
}
if (attributesContainer.getValue().findItem(uidDefinition.getName()) == null) {
ResourceAttribute<String> uidRoa = uidDefinition.instantiate();
uidRoa.setValue(new PrismPropertyValue<String>(uid.getUidValue()));
attributesContainer.getValue().add(uidRoa);
}
return shadowPrism;
}
use of org.identityconnectors.framework.common.objects.Attribute 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.Attribute in project syncope by apache.
the class LDAPPasswordPropagationActions method before.
@Transactional(readOnly = true)
@Override
public void before(final PropagationTask task, final ConnectorObject beforeObj) {
if (AnyTypeKind.USER == task.getAnyTypeKind()) {
User user = userDAO.find(task.getEntityKey());
if (user != null && user.getPassword() != null) {
Attribute missing = AttributeUtil.find(PropagationTaskExecutor.MANDATORY_MISSING_ATTR_NAME, task.getAttributes());
ConnInstance connInstance = task.getResource().getConnector();
String cipherAlgorithm = getCipherAlgorithm(connInstance);
if (missing != null && missing.getValue() != null && missing.getValue().size() == 1 && missing.getValue().get(0).equals(OperationalAttributes.PASSWORD_NAME) && cipherAlgorithmMatches(getCipherAlgorithm(connInstance), user.getCipherAlgorithm())) {
String password = user.getPassword().toLowerCase();
byte[] decodedPassword = DatatypeConverter.parseHexBinary(password);
String base64EncodedPassword = Base64.getEncoder().encodeToString(decodedPassword);
String cipherPlusPassword = ("{" + cipherAlgorithm.toLowerCase() + "}" + base64EncodedPassword);
Attribute passwordAttribute = AttributeBuilder.buildPassword(new GuardedString(cipherPlusPassword.toCharArray()));
Set<Attribute> attributes = new HashSet<>(task.getAttributes());
attributes.add(passwordAttribute);
attributes.remove(missing);
task.setAttributes(attributes);
}
}
}
}
Aggregations