You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by fm...@apache.org on 2012/03/02 15:27:35 UTC
svn commit: r1296224 [1/2] - in /incubator/syncope/trunk:
client/src/main/java/org/syncope/types/
console/src/main/java/org/syncope/console/commons/
core/src/main/java/org/syncope/core/persistence/beans/
core/src/main/java/org/syncope/core/persistence/...
Author: fmartelli
Date: Fri Mar 2 14:27:34 2012
New Revision: 1296224
URL: http://svn.apache.org/viewvc?rev=1296224&view=rev
Log:
SYNCOPE-24 #comment provided ConnObjectUtil as well
Modified:
incubator/syncope/trunk/client/src/main/java/org/syncope/types/IntMappingType.java
incubator/syncope/trunk/console/src/main/java/org/syncope/console/commons/StatusUtils.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/AbstractVirAttr.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/ExternalResource.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/validation/entity/SchemaMappingValidator.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/ConnectorFacadeProxy.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/PropagationManager.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/ResourceController.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/UserController.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/AbstractAttributableDataBinder.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ConnInstanceDataBinder.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ResourceDataBinder.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/UserDataBinder.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/SyncJob.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/util/ConnBundleManager.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/util/SchemaMappingUtil.java
incubator/syncope/trunk/core/src/test/java/org/syncope/core/persistence/dao/ResourceTest.java
incubator/syncope/trunk/core/src/test/java/org/syncope/core/persistence/relationships/ResourceTest.java
incubator/syncope/trunk/core/src/test/java/org/syncope/core/persistence/relationships/SchemaTest.java
Modified: incubator/syncope/trunk/client/src/main/java/org/syncope/types/IntMappingType.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/client/src/main/java/org/syncope/types/IntMappingType.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/client/src/main/java/org/syncope/types/IntMappingType.java (original)
+++ incubator/syncope/trunk/client/src/main/java/org/syncope/types/IntMappingType.java Fri Mar 2 14:27:34 2012
@@ -83,7 +83,6 @@ public enum IntMappingType {
* @return true if attribute type belongs to the specified attributable type set.
*/
public static boolean contains(final AttributableType attributableType, final String type) {
-
switch (attributableType) {
case ROLE:
return RoleMappingType.valueOf(type) != null;
@@ -105,7 +104,6 @@ public enum IntMappingType {
SyncopeUserId,
Password,
Username;
-
}
/**
@@ -116,7 +114,6 @@ public enum IntMappingType {
RoleSchema,
RoleDerivedSchema,
RoleVirtualSchema;
-
}
/**
@@ -127,6 +124,5 @@ public enum IntMappingType {
MembershipSchema,
MembershipDerivedSchema,
MembershipVirtualSchema;
-
}
}
Modified: incubator/syncope/trunk/console/src/main/java/org/syncope/console/commons/StatusUtils.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/console/src/main/java/org/syncope/console/commons/StatusUtils.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/console/src/main/java/org/syncope/console/commons/StatusUtils.java (original)
+++ incubator/syncope/trunk/console/src/main/java/org/syncope/console/commons/StatusUtils.java Fri Mar 2 14:27:34 2012
@@ -68,13 +68,11 @@ public class StatusUtils {
final ResourceTO resourceTO = resourceRestClient.read(res);
- final Map.Entry<IntMappingType, String> accountId =
- getAccountId(resourceTO);
+ final Map.Entry<IntMappingType, String> accountId = getAccountId(resourceTO);
String objectId = null;
- switch (accountId != null
- ? accountId.getKey() : IntMappingType.SyncopeUserId) {
+ switch (accountId != null ? accountId.getKey() : IntMappingType.SyncopeUserId) {
case SyncopeUserId:
objectId = String.valueOf(userTO.getId());
@@ -83,8 +81,7 @@ public class StatusUtils {
objectId = userTO.getUsername();
break;
case UserSchema:
- AttributeTO attributeTO =
- userTO.getAttributeMap().get(accountId.getValue());
+ AttributeTO attributeTO = userTO.getAttributeMap().get(accountId.getValue());
objectId =
attributeTO != null
&& attributeTO.getValues() != null
@@ -154,28 +151,24 @@ public class StatusUtils {
public Boolean isEnabled(final ConnObjectTO objectTO) {
final String STATUSATTR = "__ENABLE__";
- final Map<String, AttributeTO> attributeTOs =
- objectTO.getAttributeMap();
+ final Map<String, AttributeTO> attributeTOs = objectTO.getAttributeMap();
final AttributeTO status = attributeTOs.get(STATUSATTR);
return status != null && status.getValues() != null
- && !status.getValues().isEmpty()
- ? Boolean.parseBoolean(status.getValues().get(0)) : null;
+ && !status.getValues().isEmpty() ? Boolean.parseBoolean(status.getValues().get(0)) : null;
}
public String getAccountLink(final ConnObjectTO objectTO) {
final String NAME = "__NAME__";
final Map<String, AttributeTO> attributeTOs = objectTO != null
- ? objectTO.getAttributeMap()
- : Collections.EMPTY_MAP;
+ ? objectTO.getAttributeMap() : Collections.EMPTY_MAP;
final AttributeTO name = attributeTOs.get(NAME);
return name != null && name.getValues() != null
- && !name.getValues().isEmpty()
- ? (String) name.getValues().get(0) : null;
+ && !name.getValues().isEmpty() ? (String) name.getValues().get(0) : null;
}
public Map.Entry<IntMappingType, String> getAccountId(
@@ -185,8 +178,7 @@ public class StatusUtils {
for (SchemaMappingTO mapping : resourceTO.getMappings()) {
if (mapping.isAccountid()) {
accountId = new AbstractMap.SimpleEntry<IntMappingType, String>(
- mapping.getIntMappingType(),
- mapping.getIntAttrName());
+ mapping.getIntMappingType(), mapping.getIntAttrName());
}
}
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/AbstractVirAttr.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/AbstractVirAttr.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/AbstractVirAttr.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/AbstractVirAttr.java Fri Mar 2 14:27:34 2012
@@ -86,11 +86,13 @@ public abstract class AbstractVirAttr ex
String accountId = null;
for (SchemaMapping mapping : resource.getMappings()) {
+ final String extAttrName = SchemaMappingUtil.getExtAttrName(mapping);
+
if (LOG.isDebugEnabled()) {
LOG.debug("Processing mapping."
+ "\n\tID: " + mapping.getId()
+ "\n\tSource: " + mapping.getIntAttrName()
- + "\n\tDestination: " + mapping.getExtAttrName()
+ + "\n\tDestination: " + extAttrName
+ "\n\tType: " + mapping.getIntMappingType()
+ "\n\tMandatory condition: " + mapping.getMandatoryCondition()
+ "\n\tAccountId: " + mapping.isAccountid()
@@ -98,7 +100,7 @@ public abstract class AbstractVirAttr ex
}
if (attributeName.equals(mapping.getIntAttrName()) && mapping.getIntMappingType() == intMappingType) {
- attributeNames.add(mapping.getExtAttrName());
+ attributeNames.add(extAttrName);
}
if (mapping.isAccountid()) {
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/ExternalResource.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/ExternalResource.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/ExternalResource.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/ExternalResource.java Fri Mar 2 14:27:34 2012
@@ -81,8 +81,7 @@ public class ExternalResource extends Ab
/**
* Attribute mappings.
*
- * List type cannot be used. Please, take a look at
- * https://hibernate.onjira.com/browse/HHH-1718
+ * List type cannot be used. Please, take a look at https://hibernate.onjira.com/browse/HHH-1718
*/
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true,
fetch = FetchType.EAGER, mappedBy = "resource")
@@ -90,8 +89,8 @@ public class ExternalResource extends Ab
private Set<SchemaMapping> mappings;
/**
- * A JEXL expression for determining how to link user account id in Syncope
- * DB to user account id in target resource's DB.
+ * A JEXL expression for determining how to link user account id in Syncope DB to user account id in target
+ * resource's DB.
*/
private String accountLink;
@@ -216,14 +215,11 @@ public class ExternalResource extends Ab
return mappings;
}
- public Set<SchemaMapping> getMappings(final String intAttrName,
- final IntMappingType intMappingType) {
+ public Set<SchemaMapping> getMappings(final String intAttrName, final IntMappingType intMappingType) {
Set<SchemaMapping> result = new HashSet<SchemaMapping>();
for (SchemaMapping mapping : mappings) {
- if (intAttrName.equals(mapping.getIntAttrName())
- && mapping.getIntMappingType() == intMappingType) {
-
+ if (intAttrName.equals(mapping.getIntAttrName()) && mapping.getIntMappingType() == intMappingType) {
result.add(mapping);
}
}
@@ -347,8 +343,7 @@ public class ExternalResource extends Ab
Set<ConnConfProperty> deserializedSet;
if (StringUtils.isNotBlank(xmlConfiguration)) {
- deserializedSet = XMLSerializer.<HashSet<ConnConfProperty>>
- deserialize(xmlConfiguration);
+ deserializedSet = XMLSerializer.<HashSet<ConnConfProperty>>deserialize(xmlConfiguration);
if (deserializedSet != null) {
result = deserializedSet;
}
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/validation/entity/SchemaMappingValidator.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/validation/entity/SchemaMappingValidator.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/validation/entity/SchemaMappingValidator.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/validation/entity/SchemaMappingValidator.java Fri Mar 2 14:27:34 2012
@@ -20,9 +20,10 @@ package org.syncope.core.persistence.val
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
+import org.apache.commons.lang.StringUtils;
import org.syncope.core.persistence.beans.SchemaMapping;
+import org.syncope.core.util.SchemaMappingUtil;
import org.syncope.types.EntityViolationType;
-import org.syncope.types.IntMappingType;
public class SchemaMappingValidator extends AbstractValidator
implements ConstraintValidator<SchemaMappingCheck, SchemaMapping> {
@@ -32,34 +33,20 @@ public class SchemaMappingValidator exte
}
@Override
- public boolean isValid(
- final SchemaMapping object,
- final ConstraintValidatorContext context) {
+ public boolean isValid(final SchemaMapping mapping, final ConstraintValidatorContext context) {
context.disableDefaultConstraintViolation();
- if (object.getExtAttrName() == null
- && !object.isAccountid()
- && !object.isPassword()) {
- context.buildConstraintViolationWithTemplate(
- "Missing external attribute name").addNode(
- EntityViolationType.InvalidSchemaMapping.toString()).
- addConstraintViolation();
+ if (StringUtils.isBlank(SchemaMappingUtil.getExtAttrName(mapping))) {
+ context.buildConstraintViolationWithTemplate("Missing external attribute name").
+ addNode(EntityViolationType.InvalidSchemaMapping.toString()).addConstraintViolation();
return false;
}
- if (object.getIntAttrName() == null
- && IntMappingType.SyncopeUserId
- != object.getIntMappingType()
- && IntMappingType.Password
- != object.getIntMappingType()
- && IntMappingType.Username
- != object.getIntMappingType()) {
- context.buildConstraintViolationWithTemplate(
- "Missing internal attribute name").addNode(
- EntityViolationType.InvalidSchemaMapping.toString()).
- addConstraintViolation();
+ if (StringUtils.isBlank(SchemaMappingUtil.getIntAttrName(mapping))) {
+ context.buildConstraintViolationWithTemplate("Missing internal attribute name").
+ addNode(EntityViolationType.InvalidSchemaMapping.toString()).addConstraintViolation();
return false;
}
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/ConnectorFacadeProxy.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/ConnectorFacadeProxy.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/ConnectorFacadeProxy.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/ConnectorFacadeProxy.java Fri Mar 2 14:27:34 2012
@@ -59,15 +59,15 @@ import org.syncope.core.persistence.bean
import org.syncope.core.persistence.beans.SchemaMapping;
import org.syncope.core.persistence.dao.MissingConfKeyException;
import org.syncope.core.util.ConnBundleManager;
+import org.syncope.core.util.SchemaMappingUtil;
import org.syncope.types.ConnConfProperty;
import org.syncope.types.ConnectorCapability;
import org.syncope.types.PropagationMode;
import org.syncope.types.PropagationOperation;
/**
- * Intercept calls to ConnectorFacade's methods and check if the correspondant
- * connector instance has been configured to allow every single operation: if
- * not, simply do nothig.
+ * Intercept calls to ConnectorFacade's methods and check if the correspondant connector instance has been configured to
+ * allow every single operation: if not, simply do nothig.
*/
public class ConnectorFacadeProxy {
@@ -90,8 +90,7 @@ public class ConnectorFacadeProxy {
private final ConnInstance activeConnInstance;
/**
- * Use the passed connector instance to build a ConnectorFacade that will be
- * used to make all wrapped calls.
+ * Use the passed connector instance to build a ConnectorFacade that will be used to make all wrapped calls.
*
* @param connInstance the connector instance configuration
* @param connBundleManager connector bundle loader
@@ -175,8 +174,7 @@ public class ConnectorFacadeProxy {
if (GuardedString.class.equals(propertySchemaClass)) {
propertyValue = new GuardedString(
- ((String) property.getValues().iterator().next()).
- toCharArray());
+ ((String) property.getValues().iterator().next()).toCharArray());
} else if (GuardedByteArray.class.equals(
propertySchemaClass)) {
@@ -264,8 +262,7 @@ public class ConnectorFacadeProxy {
* @param objectClass ConnId's object class
* @param attrs attributes for creation
* @param options ConnId's OperationOptions
- * @param propagationAttempted if creation is actually performed (based on
- * connector instance's capabilities)
+ * @param propagationAttempted if creation is actually performed (based on connector instance's capabilities)
* @return Uid for created user
*/
public Uid create(
@@ -303,8 +300,7 @@ public class ConnectorFacadeProxy {
* @param uid user to be updated
* @param attrs attributes for update
* @param options ConnId's OperationOptions
- * @param propagationAttempted if update is actually performed (based on
- * connector instance's capabilities)
+ * @param propagationAttempted if update is actually performed (based on connector instance's capabilities)
* @return Uid for created user
*/
public Uid update(final PropagationMode propagationMode,
@@ -342,8 +338,7 @@ public class ConnectorFacadeProxy {
* @param objectClass ConnId's object class
* @param uid user to be deleted
* @param options ConnId's OperationOptions
- * @param propagationAttempted if deletion is actually performed (based on
- * connector instance's capabilities)
+ * @param propagationAttempted if deletion is actually performed (based on connector instance's capabilities)
*/
public void delete(final PropagationMode propagationMode,
final ObjectClass objectClass,
@@ -425,8 +420,8 @@ public class ConnectorFacadeProxy {
}
/**
- * Get remote object used by the propagation manager in order to choose for
- * a create (object doesn't exist) or an update (object exists).
+ * Get remote object used by the propagation manager in order to choose for a create (object doesn't exist) or an
+ * update (object exists).
*
* @param propagationMode propagation mode
* @param operationType resource operation type
@@ -488,8 +483,8 @@ public class ConnectorFacadeProxy {
}
/**
- * Get remote object used by the propagation manager in order to choose for
- * a create (object doesn't exist) or an update (object exists).
+ * Get remote object used by the propagation manager in order to choose for a create (object doesn't exist) or an
+ * update (object exists).
*
* @param objectClass ConnId's object class.
* @param handler to be used to handle deltas.
@@ -655,20 +650,16 @@ public class ConnectorFacadeProxy {
final OperationOptionsBuilder oob = new OperationOptionsBuilder();
final Set<String> attributesToGet = new HashSet<String>(
- Arrays.asList(new String[]{
- Name.NAME,
- Uid.NAME,
- OperationalAttributes.ENABLE_NAME
- }));
+ Arrays.asList(new String[]{Name.NAME, Uid.NAME, OperationalAttributes.ENABLE_NAME}));
for (SchemaMapping mapping : resource.getMappings()) {
- if (StringUtils.hasText(mapping.getExtAttrName())) {
- attributesToGet.add(mapping.getExtAttrName());
+ final String extAttrName = SchemaMappingUtil.getExtAttrName(mapping);
+
+ if (StringUtils.hasText(extAttrName)) {
+ attributesToGet.add(extAttrName);
}
}
- attributesToGet.add(OperationalAttributes.ENABLE_NAME);
-
oob.setAttributesToGet(attributesToGet);
// -------------------------------------
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/PropagationManager.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/PropagationManager.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/PropagationManager.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/PropagationManager.java Fri Mar 2 14:27:34 2012
@@ -50,27 +50,14 @@ import org.syncope.client.to.AttributeTO
import org.syncope.core.init.ConnInstanceLoader;
import org.syncope.core.persistence.beans.AbstractAttrValue;
import org.syncope.core.persistence.beans.AbstractAttributable;
-import org.syncope.core.persistence.beans.AbstractDerAttr;
import org.syncope.core.persistence.beans.AbstractSchema;
-import org.syncope.core.persistence.beans.AbstractVirAttr;
import org.syncope.core.persistence.beans.ConnInstance;
import org.syncope.core.persistence.beans.ExternalResource;
import org.syncope.core.persistence.beans.PropagationTask;
import org.syncope.core.persistence.beans.SchemaMapping;
import org.syncope.core.persistence.beans.TaskExec;
-import org.syncope.core.persistence.beans.membership.MDerSchema;
-import org.syncope.core.persistence.beans.membership.MSchema;
-import org.syncope.core.persistence.beans.membership.MVirSchema;
import org.syncope.core.persistence.beans.membership.Membership;
-import org.syncope.core.persistence.beans.role.RDerSchema;
-import org.syncope.core.persistence.beans.role.RSchema;
-import org.syncope.core.persistence.beans.role.RVirSchema;
import org.syncope.core.persistence.beans.user.SyncopeUser;
-import org.syncope.core.persistence.beans.user.UAttr;
-import org.syncope.core.persistence.beans.user.UAttrValue;
-import org.syncope.core.persistence.beans.user.UDerSchema;
-import org.syncope.core.persistence.beans.user.USchema;
-import org.syncope.core.persistence.beans.user.UVirSchema;
import org.syncope.core.persistence.dao.ResourceDAO;
import org.syncope.core.persistence.dao.SchemaDAO;
import org.syncope.core.persistence.dao.TaskDAO;
@@ -79,6 +66,7 @@ import org.syncope.core.persistence.dao.
import org.syncope.core.rest.data.UserDataBinder;
import org.syncope.core.util.AttributableUtil;
import org.syncope.core.util.JexlUtil;
+import org.syncope.core.util.SchemaMappingUtil;
import org.syncope.core.workflow.WorkflowResult;
import org.syncope.types.AttributableType;
import org.syncope.types.IntMappingType;
@@ -389,55 +377,6 @@ public class PropagationManager {
}
/**
- * For given source mapping type, return the corresponding Class object.
- *
- * @param intMappingType source mapping type
- * @return corresponding Class object, if any (can be null)
- */
- private Class getIntMappingTypeClass(
- final IntMappingType intMappingType) {
-
- Class result;
-
- switch (intMappingType) {
- case UserSchema:
- result = USchema.class;
- break;
- case RoleSchema:
- result = RSchema.class;
- break;
- case MembershipSchema:
- result = MSchema.class;
- break;
-
- case UserDerivedSchema:
- result = UDerSchema.class;
- break;
- case RoleDerivedSchema:
- result = RDerSchema.class;
- break;
- case MembershipDerivedSchema:
- result = MDerSchema.class;
- break;
-
- case UserVirtualSchema:
- result = UVirSchema.class;
- break;
- case RoleVirtualSchema:
- result = RVirSchema.class;
- break;
- case MembershipVirtualSchema:
- result = MVirSchema.class;
- break;
-
- default:
- result = null;
- }
-
- return result;
- }
-
- /**
* Prepare an attribute for sending to a connector instance.
*
* @param mapping schema mapping for the given attribute
@@ -471,14 +410,16 @@ public class PropagationManager {
}
final Entry<AbstractSchema, List<AbstractAttrValue>> entry =
- getAttributeValues(mapping, attributables, password);
+ SchemaMappingUtil.getIntValues(mapping, attributables, password, schemaDAO);
final List<AbstractAttrValue> values = entry.getValue();
final AbstractSchema schema = entry.getKey();
final SchemaType schemaType = schema == null ? SchemaType.String : schema.getType();
+ final String extAttrName = SchemaMappingUtil.getExtAttrName(mapping);
+
LOG.debug("Define mapping for: "
- + "\n* ExtAttrName " + mapping.getExtAttrName()
+ + "\n* ExtAttrName " + extAttrName
+ "\n* is accountId " + mapping.isAccountid()
+ "\n* is password "
+ (mapping.isPassword() || mapping.getIntMappingType().equals(IntMappingType.Password))
@@ -511,14 +452,13 @@ public class PropagationManager {
} else {
if (schema != null && schema.isMultivalue()) {
- res = new DefaultMapEntry(null, AttributeBuilder.build(mapping.getExtAttrName(), objValues));
+ res = new DefaultMapEntry(null, AttributeBuilder.build(extAttrName, objValues));
} else {
res = new DefaultMapEntry(null,
objValues.isEmpty()
- ? AttributeBuilder.build(mapping.getExtAttrName())
- : AttributeBuilder.build(mapping.getExtAttrName(),
- objValues.iterator().next()));
+ ? AttributeBuilder.build(extAttrName)
+ : AttributeBuilder.build(extAttrName, objValues.iterator().next()));
}
}
@@ -526,133 +466,6 @@ public class PropagationManager {
}
/**
- * Get attribute values.
- *
- * @param mapping mapping.
- * @param attributables list of attributables.
- * @param password password.
- * @return schema and attribute values.
- */
- private Entry<AbstractSchema, List<AbstractAttrValue>> getAttributeValues(
- final SchemaMapping mapping,
- final List<AbstractAttributable> attributables,
- final String password) {
-
-
- LOG.debug("Get attributes for '{}' and mapping type '{}'",
- attributables, mapping.getIntMappingType());
-
- AbstractSchema schema = null;
-
- List<AbstractAttrValue> values = new ArrayList<AbstractAttrValue>();
- AbstractAttrValue attrValue;
-
- switch (mapping.getIntMappingType()) {
- case UserSchema:
- case RoleSchema:
- case MembershipSchema:
- schema = schemaDAO.find(mapping.getIntAttrName(), getIntMappingTypeClass(mapping.getIntMappingType()));
-
- for (AbstractAttributable attributable : attributables) {
- final UAttr attr = attributable.getAttribute(mapping.getIntAttrName());
-
- if (attr != null && attr.getValues() != null) {
- values.addAll(schema.isUniqueConstraint()
- ? Collections.singletonList(attr.getUniqueValue()) : attr.getValues());
- }
-
- LOG.debug("Retrieved attribute {}"
- + "\n* IntAttrName {}"
- + "\n* IntMappingType {}"
- + "\n* Attribute values {}",
- new Object[]{attr, mapping.getIntAttrName(), mapping.getIntMappingType(), values});
- }
-
- break;
-
- case UserVirtualSchema:
- case RoleVirtualSchema:
- case MembershipVirtualSchema:
-
- for (AbstractAttributable attributable : attributables) {
- AbstractVirAttr virAttr = attributable.getVirtualAttribute(mapping.getIntAttrName());
-
- if (virAttr != null && virAttr.getValues() != null) {
- for (String value : virAttr.getValues()) {
- attrValue = new UAttrValue();
- attrValue.setStringValue(value);
- values.add(attrValue);
- }
- }
-
- LOG.debug("Retrieved virtual attribute {}"
- + "\n* IntAttrName {}"
- + "\n* IntMappingType {}"
- + "\n* Attribute values {}",
- new Object[]{virAttr, mapping.getIntAttrName(), mapping.getIntMappingType(), values});
- }
- break;
-
- case UserDerivedSchema:
- case RoleDerivedSchema:
- case MembershipDerivedSchema:
- for (AbstractAttributable attributable : attributables) {
- AbstractDerAttr derAttr = attributable.getDerivedAttribute(
- mapping.getIntAttrName());
-
- if (derAttr != null) {
- attrValue = new UAttrValue();
- attrValue.setStringValue(
- derAttr.getValue(attributable.getAttributes()));
- values.add(attrValue);
- }
-
- LOG.debug("Retrieved attribute {}"
- + "\n* IntAttrName {}"
- + "\n* IntMappingType {}"
- + "\n* Attribute values {}",
- new Object[]{derAttr, mapping.getIntAttrName(),
- mapping.getIntMappingType(), values});
- }
- break;
-
- case Username:
- for (AbstractAttributable attributable : attributables) {
- attrValue = new UAttrValue();
- attrValue.setStringValue(
- ((SyncopeUser) attributable).getUsername());
-
- values.add(attrValue);
- }
- break;
-
- case SyncopeUserId:
- for (AbstractAttributable attributable : attributables) {
- attrValue = new UAttrValue();
- attrValue.setStringValue(attributable.getId().toString());
- values.add(attrValue);
- }
- break;
-
- case Password:
- attrValue = new UAttrValue();
-
- if (password != null) {
- attrValue.setStringValue(password);
- }
-
- values.add(attrValue);
- break;
-
- default:
- }
-
- LOG.debug("Retrived values '{}'", values);
-
- return new DefaultMapEntry(schema, values);
- }
-
- /**
* Prepare attributes for sending to a connector instance.
*
* @param user given user
@@ -675,7 +488,7 @@ public class PropagationManager {
Map.Entry<String, Attribute> preparedAttribute;
for (SchemaMapping mapping : resource.getMappings()) {
- LOG.debug("Processing schema {}", mapping.getIntAttrName());
+ LOG.debug("Processing schema {}", SchemaMappingUtil.getIntAttrName(mapping));
try {
preparedAttribute = prepareAttribute(mapping, user, password);
@@ -703,8 +516,7 @@ public class PropagationManager {
}
} catch (Throwable t) {
- LOG.debug("Attribute '{}' processing failed",
- mapping.getIntAttrName(), t);
+ LOG.debug("Attribute '{}' processing failed", SchemaMappingUtil.getIntAttrName(mapping), t);
}
}
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/ResourceController.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/ResourceController.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/ResourceController.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/ResourceController.java Fri Mar 2 14:27:34 2012
@@ -52,8 +52,8 @@ import org.syncope.core.persistence.dao.
import org.syncope.core.persistence.dao.ResourceDAO;
import org.syncope.core.persistence.dao.RoleDAO;
import org.syncope.core.propagation.ConnectorFacadeProxy;
-import org.syncope.core.rest.data.ConnInstanceDataBinder;
import org.syncope.core.rest.data.ResourceDataBinder;
+import org.syncope.core.util.ConnObjectUtil;
import org.syncope.types.SyncopeClientExceptionType;
@Controller
@@ -72,8 +72,11 @@ public class ResourceController extends
@Autowired
private ResourceDataBinder binder;
+ /**
+ * ConnectorObject util.
+ */
@Autowired
- private ConnInstanceDataBinder connInstanceDataBinder;
+ private ConnObjectUtil connObjectUtil;
@Autowired
private ConnInstanceLoader connLoader;
@@ -284,8 +287,8 @@ public class ResourceController extends
final ConnectorObject connectorObject =
connector.getObject(
- ObjectClass.ACCOUNT,
- new Uid(objectId),
+ ObjectClass.ACCOUNT,
+ new Uid(objectId),
connector.getOperationOptions(resource));
if (connectorObject == null) {
@@ -304,6 +307,6 @@ public class ResourceController extends
attributes.add(connectorObject.getName());
}
- return connInstanceDataBinder.getConnObjectTO(connectorObject);
+ return connObjectUtil.getConnObjectTO(connectorObject);
}
}
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/UserController.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/UserController.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/UserController.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/UserController.java Fri Mar 2 14:27:34 2012
@@ -55,6 +55,7 @@ import org.syncope.core.persistence.dao.
import org.syncope.core.propagation.PropagationHandler;
import org.syncope.core.propagation.PropagationManager;
import org.syncope.core.rest.data.ConnInstanceDataBinder;
+import org.syncope.core.util.ConnObjectUtil;
import org.syncope.core.util.EntitlementUtil;
import org.syncope.core.workflow.UserWorkflowAdapter;
import org.syncope.core.workflow.WorkflowException;
@@ -98,6 +99,12 @@ public class UserController {
@Autowired
private NotificationManager notificationManager;
+ /**
+ * ConnectorObject util.
+ */
+ @Autowired
+ private ConnObjectUtil connObjectUtil;
+
@PreAuthorize("hasRole('USER_READ')")
@RequestMapping(method = RequestMethod.GET,
value = "/verifyPassword/{userId}")
@@ -289,13 +296,11 @@ public class UserController {
propagation.setStatus(executionStatus);
if (before != null) {
- propagation.setBefore(
- connInstanceDataBinder.getConnObjectTO(before));
+ propagation.setBefore(connObjectUtil.getConnObjectTO(before));
}
if (after != null) {
- propagation.setAfter(
- connInstanceDataBinder.getConnObjectTO(after));
+ propagation.setAfter(connObjectUtil.getConnObjectTO(after));
}
propagations.add(propagation);
@@ -329,7 +334,7 @@ public class UserController {
List<PropagationTask> tasks = propagationManager.getUpdateTaskIds(
updated, userMod.getPassword(),
userMod.getVirtualAttributesToBeRemoved(),
- userMod.getVirtualAttributesToBeUpdated(),
+ userMod.getVirtualAttributesToBeUpdated(),
null);
final List<PropagationTO> propagations = new ArrayList<PropagationTO>();
@@ -348,13 +353,11 @@ public class UserController {
propagation.setStatus(executionStatus);
if (before != null) {
- propagation.setBefore(
- connInstanceDataBinder.getConnObjectTO(before));
+ propagation.setBefore(connObjectUtil.getConnObjectTO(before));
}
if (after != null) {
- propagation.setAfter(
- connInstanceDataBinder.getConnObjectTO(after));
+ propagation.setAfter(connObjectUtil.getConnObjectTO(after));
}
propagations.add(propagation);
@@ -501,13 +504,11 @@ public class UserController {
propagation.setStatus(executionStatus);
if (before != null) {
- propagation.setBefore(
- connInstanceDataBinder.getConnObjectTO(before));
+ propagation.setBefore(connObjectUtil.getConnObjectTO(before));
}
if (after != null) {
- propagation.setAfter(
- connInstanceDataBinder.getConnObjectTO(after));
+ propagation.setAfter(connObjectUtil.getConnObjectTO(after));
}
userTO.addPropagationTO(propagation);
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/AbstractAttributableDataBinder.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/AbstractAttributableDataBinder.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/AbstractAttributableDataBinder.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/AbstractAttributableDataBinder.java Fri Mar 2 14:27:34 2012
@@ -601,8 +601,7 @@ public abstract class AbstractAttributab
if (derivedSchema != null) {
for (SchemaMapping mapping : resourceDAO.findAllMappings()) {
- if (derivedSchema.getName().equals(
- mapping.getIntAttrName())
+ if (derivedSchema.getName().equals(mapping.getIntAttrName())
&& mapping.getIntMappingType() == attributableUtil.derivedIntMappingType()
&& mapping.getResource() != null
&& attributable.getResources().contains(mapping.getResource())) {
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ConnInstanceDataBinder.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ConnInstanceDataBinder.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ConnInstanceDataBinder.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ConnInstanceDataBinder.java Fri Mar 2 14:27:34 2012
@@ -22,15 +22,11 @@ import java.util.Map;
import javassist.NotFoundException;
import org.identityconnectors.framework.api.ConfigurationProperties;
import org.identityconnectors.framework.api.ConfigurationProperty;
-import org.identityconnectors.framework.common.objects.Attribute;
-import org.identityconnectors.framework.common.objects.ConnectorObject;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
-import org.syncope.client.to.AttributeTO;
import org.syncope.client.to.ConnInstanceTO;
-import org.syncope.client.to.ConnObjectTO;
import org.syncope.client.validation.SyncopeClientCompositeErrorException;
import org.syncope.client.validation.SyncopeClientException;
import org.syncope.core.persistence.beans.ConnInstance;
@@ -205,31 +201,4 @@ public class ConnInstanceDataBinder {
}
return connInstanceTO;
}
-
- /**
- * Get connector object TO from a connector object.
- *
- * @param connObject connector object.
- * @return connector object TO.
- */
- public ConnObjectTO getConnObjectTO(final ConnectorObject connObject) {
- final ConnObjectTO connObjectTO = new ConnObjectTO();
-
- for (Attribute attr : connObject.getAttributes()) {
- AttributeTO attrTO = new AttributeTO();
- attrTO.setSchema(attr.getName());
-
- if (attr.getValue() != null) {
- for (Object value : attr.getValue()) {
- if (value != null) {
- attrTO.addValue(value.toString());
- }
- }
- }
-
- connObjectTO.addAttribute(attrTO);
- }
-
- return connObjectTO;
- }
}
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ResourceDataBinder.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ResourceDataBinder.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ResourceDataBinder.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ResourceDataBinder.java Fri Mar 2 14:27:34 2012
@@ -224,8 +224,7 @@ public class ResourceDataBinder {
return schemaMappings;
}
- private SchemaMapping getSchemaMapping(ExternalResource resource,
- SchemaMappingTO mappingTO)
+ private SchemaMapping getSchemaMapping(ExternalResource resource, SchemaMappingTO mappingTO)
throws SyncopeClientCompositeErrorException {
SyncopeClientCompositeErrorException compositeErrorException =
@@ -246,18 +245,15 @@ public class ResourceDataBinder {
if (mappingTO.getIntAttrName() == null) {
switch (mappingTO.getIntMappingType()) {
case SyncopeUserId:
- mappingTO.setIntAttrName(
- IntMappingType.SyncopeUserId.toString());
+ mappingTO.setIntAttrName(IntMappingType.SyncopeUserId.toString());
break;
case Password:
- mappingTO.setIntAttrName(
- IntMappingType.Password.toString());
+ mappingTO.setIntAttrName(IntMappingType.Password.toString());
break;
case Username:
- mappingTO.setIntAttrName(
- IntMappingType.Username.toString());
+ mappingTO.setIntAttrName(IntMappingType.Username.toString());
break;
default:
@@ -273,14 +269,12 @@ public class ResourceDataBinder {
// no mandatory condition implies mandatory condition false
if (!jexlUtil.isExpressionValid(
- mappingTO.getMandatoryCondition() != null
- ? mappingTO.getMandatoryCondition() : "false")) {
+ mappingTO.getMandatoryCondition() != null ? mappingTO.getMandatoryCondition() : "false")) {
SyncopeClientException invalidMandatoryCondition =
- new SyncopeClientException(
- SyncopeClientExceptionType.InvalidValues);
- invalidMandatoryCondition.addElement(
- mappingTO.getMandatoryCondition());
+ new SyncopeClientException(SyncopeClientExceptionType.InvalidValues);
+
+ invalidMandatoryCondition.addElement(mappingTO.getMandatoryCondition());
compositeErrorException.addException(invalidMandatoryCondition);
}
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/UserDataBinder.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/UserDataBinder.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/UserDataBinder.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/UserDataBinder.java Fri Mar 2 14:27:34 2012
@@ -131,7 +131,7 @@ public class UserDataBinder extends Abst
Set<Long> roleIds = user.getRoleIds();
Set<Long> adminRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames());
roleIds.removeAll(adminRoleIds);
-
+
if (!roleIds.isEmpty()) {
throw new UnauthorizedRoleException(roleIds);
}
@@ -257,11 +257,8 @@ public class UserDataBinder extends Abst
for (ExternalResource resource : user.getResources()) {
for (SchemaMapping mapping : resource.getMappings()) {
- if (mapping.isAccountid() && mapping.getIntMappingType()
- == IntMappingType.Username) {
-
- propByRes.addOldAccountId(
- resource.getName(), oldUsername);
+ if (mapping.isAccountid() && mapping.getIntMappingType() == IntMappingType.Username) {
+ propByRes.addOldAccountId(resource.getName(), oldUsername);
}
}
}
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/SyncJob.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/SyncJob.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/SyncJob.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/SyncJob.java Fri Mar 2 14:27:34 2012
@@ -24,10 +24,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javassist.NotFoundException;
-import org.apache.commons.lang.RandomStringUtils;
-import org.apache.commons.lang.StringUtils;
-import org.identityconnectors.common.security.GuardedByteArray;
-import org.identityconnectors.common.security.GuardedString;
import org.identityconnectors.framework.common.objects.Attribute;
import org.identityconnectors.framework.common.objects.AttributeUtil;
import org.identityconnectors.framework.common.objects.ConnectorObject;
@@ -35,7 +31,6 @@ import org.identityconnectors.framework.
import org.identityconnectors.framework.common.objects.OperationalAttributes;
import org.identityconnectors.framework.common.objects.SyncDelta;
import org.identityconnectors.framework.common.objects.SyncResultsHandler;
-import org.identityconnectors.framework.common.objects.Uid;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -44,14 +39,10 @@ import org.springframework.security.core
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
-import org.syncope.client.mod.AttributeMod;
import org.syncope.client.mod.UserMod;
import org.syncope.client.search.AttributeCond;
import org.syncope.client.search.NodeCond;
import org.syncope.client.search.SyncopeUserCond;
-import org.syncope.client.to.AbstractAttributableTO;
-import org.syncope.client.to.AttributeTO;
-import org.syncope.client.to.MembershipTO;
import org.syncope.client.to.UserTO;
import org.syncope.core.init.ConnInstanceLoader;
import org.syncope.core.persistence.beans.Entitlement;
@@ -74,8 +65,9 @@ import org.syncope.core.rest.controller.
import org.syncope.core.rest.controller.UnauthorizedRoleException;
import org.syncope.core.rest.data.UserDataBinder;
import org.syncope.core.scheduling.SyncResult.Operation;
+import org.syncope.core.util.ConnObjectUtil;
import org.syncope.core.util.EntitlementUtil;
-import org.syncope.core.util.JexlUtil;
+import org.syncope.core.util.SchemaMappingUtil;
import org.syncope.core.workflow.UserWorkflowAdapter;
import org.syncope.core.workflow.WorkflowResult;
import org.syncope.types.ConflictResolutionAction;
@@ -144,313 +136,16 @@ public class SyncJob extends AbstractTas
private SyncJobActions actions;
/**
- * JEXL engine for evaluating connector's account link.
+ * ConnectorObject util.
*/
@Autowired
- private JexlUtil jexlUtil;
+ private ConnObjectUtil connObjectUtil;
public void setActions(final SyncJobActions actions) {
this.actions = actions;
}
/**
- * Extract password value from passed value (if instance of GuardedString or
- * GuardedByteArray).
- *
- * @param pwd received from the underlying connector
- * @return password value
- */
- private String getPassword(final Object pwd) {
- final StringBuilder result = new StringBuilder();
-
- if (pwd instanceof GuardedString) {
- ((GuardedString) pwd).access(new GuardedString.Accessor() {
-
- @Override
- public void access(final char[] clearChars) {
- result.append(clearChars);
- }
- });
- } else if (pwd instanceof GuardedByteArray) {
- ((GuardedByteArray) pwd).access(new GuardedByteArray.Accessor() {
-
- @Override
- public void access(final byte[] clearBytes) {
- result.append(new String(clearBytes));
- }
- });
- } else if (pwd instanceof String) {
- result.append((String) pwd);
- } else {
- result.append(pwd.toString());
- }
-
- return result.toString();
- }
-
- private AttributeTO evaluateAttrTemplate(
- final AbstractAttributableTO attributableTO,
- final AttributeTO template) {
-
- AttributeTO result = new AttributeTO();
- result.setSchema(template.getSchema());
-
- if (template.getValues() != null && !template.getValues().isEmpty()) {
- for (String value : template.getValues()) {
- String evaluated = jexlUtil.evaluate(value, attributableTO);
- if (StringUtils.isNotBlank(evaluated)) {
- result.addValue(evaluated);
- }
- }
- }
-
- return result;
- }
-
- private void fillFromTemplate(final AbstractAttributableTO attributableTO,
- final AbstractAttributableTO template) {
-
- Map<String, AttributeTO> currentAttrMap =
- attributableTO.getAttributeMap();
- for (AttributeTO attrTO : template.getAttributes()) {
- if (!currentAttrMap.containsKey(attrTO.getSchema())) {
- attributableTO.addAttribute(
- evaluateAttrTemplate(attributableTO, attrTO));
- }
- }
-
- currentAttrMap = attributableTO.getDerivedAttributeMap();
- for (AttributeTO attrTO : template.getDerivedAttributes()) {
- if (!currentAttrMap.containsKey(attrTO.getSchema())) {
- attributableTO.addDerivedAttribute(attrTO);
- }
- }
-
- currentAttrMap = attributableTO.getVirtualAttributeMap();
- for (AttributeTO attrTO : template.getDerivedAttributes()) {
- if (!currentAttrMap.containsKey(attrTO.getSchema())) {
- attributableTO.addVirtualAttribute(
- evaluateAttrTemplate(attributableTO, attrTO));
- }
- }
- }
-
- /**
- * Build an UserTO out of connector object attributes and schema mapping.
- *
- * @param obj connector object
- * @return UserTO for the user to be created
- */
- private UserTO getUserTO(final ConnectorObject obj) {
- final SyncTask syncTask = (SyncTask) this.task;
-
- final UserTO userTO = new UserTO();
-
- // 1. fill with data from connector object
- for (SchemaMapping mapping : syncTask.getResource().getMappings()) {
- Attribute attribute = obj.getAttributeByName(
- mapping.isAccountid()
- ? Uid.NAME
- : mapping.isPassword()
- ? OperationalAttributes.PASSWORD_NAME
- : mapping.getExtAttrName());
-
- AttributeTO attributeTO;
- switch (mapping.getIntMappingType()) {
- case SyncopeUserId:
- break;
-
- case Password:
- if (attribute != null && attribute.getValue() != null
- && !attribute.getValue().isEmpty()) {
-
- userTO.setPassword(
- getPassword(attribute.getValue().get(0)));
- }
- break;
-
- case Username:
- userTO.setUsername(
- attribute == null || attribute.getValue().isEmpty()
- ? null : attribute.getValue().get(0).toString());
- break;
-
- case UserSchema:
- attributeTO = new AttributeTO();
- attributeTO.setSchema(mapping.getIntAttrName());
- for (Object value : attribute == null
- ? Collections.EMPTY_LIST : attribute.getValue()) {
-
- attributeTO.addValue(value.toString());
- }
- userTO.addAttribute(attributeTO);
- break;
-
- case UserDerivedSchema:
- attributeTO = new AttributeTO();
- attributeTO.setSchema(mapping.getIntAttrName());
- userTO.addDerivedAttribute(attributeTO);
- break;
-
- case UserVirtualSchema:
- attributeTO = new AttributeTO();
- attributeTO.setSchema(mapping.getIntAttrName());
- userTO.addVirtualAttribute(attributeTO);
- break;
-
- default:
- }
- }
-
- // 2. add data from defined template (if any)
- UserTO template = syncTask.getUserTemplate();
- if (template != null) {
- if (StringUtils.isBlank(userTO.getUsername())
- && StringUtils.isNotBlank(template.getUsername())) {
-
- String evaluated =
- jexlUtil.evaluate(template.getUsername(), userTO);
- if (StringUtils.isNotBlank(evaluated)) {
- userTO.setUsername(template.getUsername());
- }
- }
-
- if (StringUtils.isBlank(userTO.getPassword())
- && StringUtils.isNotBlank(template.getPassword())) {
-
- String evaluated =
- jexlUtil.evaluate(template.getPassword(), userTO);
- if (StringUtils.isNotBlank(evaluated)) {
- userTO.setPassword(template.getPassword());
- }
- }
-
- fillFromTemplate(userTO, template);
-
- for (String resource : template.getResources()) {
- userTO.addResource(resource);
- }
-
- Map<Long, MembershipTO> currentMembs = userTO.getMembershipMap();
- for (MembershipTO membTO : template.getMemberships()) {
- MembershipTO membTBU;
- if (currentMembs.containsKey(membTO.getRoleId())) {
- membTBU = currentMembs.get(membTO.getRoleId());
- } else {
- membTBU = new MembershipTO();
- membTBU.setRoleId(membTO.getRoleId());
- userTO.addMembership(membTBU);
- }
- fillFromTemplate(membTBU, membTO);
- }
- }
-
- // 3. if password was not set above, generate a random string
- if (StringUtils.isBlank(userTO.getPassword())) {
- userTO.setPassword(RandomStringUtils.randomAlphanumeric(16));
- }
-
- return userTO;
- }
-
- /**
- * Build an UserMod out of connector object attributes and schema mapping.
- *
- * @param userId user to be updated
- * @param obj connector object
- * @return UserMod for the user to be updated
- */
- private UserMod getUserMod(final Long userId, final ConnectorObject obj) {
-
- final SyncTask syncTask = (SyncTask) this.task;
-
- final UserMod userMod = new UserMod();
- userMod.setId(userId);
-
- for (SchemaMapping mapping : syncTask.getResource().getMappings()) {
- Attribute attribute = obj.getAttributeByName(
- mapping.isAccountid()
- ? Uid.NAME
- : mapping.isPassword()
- ? OperationalAttributes.PASSWORD_NAME
- : mapping.getExtAttrName());
-
- List<Object> values = attribute == null
- ? Collections.EMPTY_LIST : attribute.getValue();
-
- AttributeMod attributeMod;
- switch (mapping.getIntMappingType()) {
- case SyncopeUserId:
- break;
-
- case Password:
- attribute = obj.getAttributeByName(
- OperationalAttributes.PASSWORD_NAME);
-
- if (attribute != null && attribute.getValue() != null
- && !attribute.getValue().isEmpty()) {
-
- String password =
- getPassword(attribute.getValue().get(0));
- // update password if and only if password has really
- // changed
- try {
- if (!userDataBinder.verifyPassword(userId,
- password)) {
-
- userMod.setPassword(password);
- }
- } catch (NotFoundException e) {
- LOG.error("Could not find user {}", userId, e);
- } catch (UnauthorizedRoleException e) {
- LOG.error("Not allowed to read user {}", userId, e);
- }
- }
- break;
-
- case Username:
- if (values != null && !values.isEmpty()) {
- userMod.setUsername(values.get(0).toString());
- }
- break;
-
- case UserSchema:
- userMod.addAttributeToBeRemoved(
- mapping.getIntAttrName());
-
- attributeMod = new AttributeMod();
- attributeMod.setSchema(mapping.getIntAttrName());
- for (Object value : values) {
- attributeMod.addValueToBeAdded(value.toString());
- }
- userMod.addAttributeToBeUpdated(attributeMod);
- break;
-
- case UserDerivedSchema:
- userMod.addDerivedAttributeToBeAdded(
- mapping.getIntAttrName());
- break;
-
- case UserVirtualSchema:
- userMod.addVirtualAttributeToBeRemoved(
- mapping.getIntAttrName());
-
- attributeMod = new AttributeMod();
- attributeMod.setSchema(mapping.getIntAttrName());
- for (Object value : values) {
- attributeMod.addValueToBeAdded(value.toString());
- }
- userMod.addVirtualAttributeToBeUpdated(attributeMod);
- break;
-
- default:
- }
- }
-
- return userMod;
- }
-
- /**
* Find users based on mapped uid value (or previous uid value, if updated).
*
* @param delta sync delta
@@ -485,30 +180,9 @@ public class SyncJob extends AbstractTas
new HashMap<String, Attribute>();
for (SchemaMapping mapping : syncTask.getResource().getMappings()) {
- String key;
- switch (mapping.getIntMappingType()) {
- case SyncopeUserId:
- key = "id";
- break;
-
- case Username:
- key = "username";
- break;
-
- case Password:
- key = "password";
- break;
-
- default:
- key = mapping.getIntAttrName();
- }
-
- extValues.put(key, object.getAttributeByName(
- mapping.isAccountid()
- ? Uid.NAME
- : mapping.isPassword()
- ? OperationalAttributes.PASSWORD_NAME
- : mapping.getExtAttrName()));
+ extValues.put(
+ SchemaMappingUtil.getIntAttrName(mapping),
+ object.getAttributeByName(SchemaMappingUtil.getExtAttrName(mapping)));
}
// search user by attributes specified into the policy
@@ -520,23 +194,18 @@ public class SyncJob extends AbstractTas
AttributeCond.Type type;
String expression = null;
- if (value == null
- || value.getValue() == null
- || value.getValue().isEmpty()) {
-
+ if (value == null || value.getValue() == null || value.getValue().isEmpty()) {
type = AttributeCond.Type.ISNULL;
} else {
type = AttributeCond.Type.EQ;
expression = value.getValue().size() > 1
- ? value.getValue().toString()
- : value.getValue().get(0).toString();
+ ? value.getValue().toString() : value.getValue().get(0).toString();
}
NodeCond nodeCond;
// just Username or SyncopeUserId can be selected to be used
- if ("id".equalsIgnoreCase(schema)
- || "username".equalsIgnoreCase(schema)) {
+ if ("id".equalsIgnoreCase(schema) || "username".equalsIgnoreCase(schema)) {
final SyncopeUserCond cond = new SyncopeUserCond();
cond.setSchema(schema);
@@ -554,14 +223,11 @@ public class SyncJob extends AbstractTas
nodeCond = NodeCond.getLeafCond(cond);
}
- searchCondition = searchCondition != null
- ? NodeCond.getAndCond(searchCondition, nodeCond)
- : nodeCond;
+ searchCondition = searchCondition != null ? NodeCond.getAndCond(searchCondition, nodeCond) : nodeCond;
}
- List<SyncopeUser> users = userSearchDAO.search(
- EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
- searchCondition);
+ List<SyncopeUser> users =
+ userSearchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), searchCondition);
for (SyncopeUser user : users) {
result.add(user.getId());
}
@@ -569,8 +235,8 @@ public class SyncJob extends AbstractTas
final SyncopeUser found;
List<SyncopeUser> users;
- final SchemaMapping accountIdMap =
- syncTask.getResource().getAccountIdMapping();
+ final SchemaMapping accountIdMap = syncTask.getResource().getAccountIdMapping();
+
switch (accountIdMap.getIntMappingType()) {
case Username:
found = userDAO.find(uid);
@@ -589,8 +255,7 @@ public class SyncJob extends AbstractTas
case UserSchema:
final UAttrValue value = new UAttrValue();
value.setStringValue(uid);
- users = userDAO.findByAttrValue(
- accountIdMap.getIntAttrName(), value);
+ users = userDAO.findByAttrValue(accountIdMap.getIntAttrName(), value);
for (SyncopeUser user : users) {
result.add(user.getId());
}
@@ -598,8 +263,7 @@ public class SyncJob extends AbstractTas
case UserDerivedSchema:
try {
- users = userDAO.findByDerAttrValue(
- accountIdMap.getIntAttrName(), uid);
+ users = userDAO.findByDerAttrValue(accountIdMap.getIntAttrName(), uid);
for (SyncopeUser user : users) {
result.add(user.getId());
}
@@ -609,8 +273,7 @@ public class SyncJob extends AbstractTas
break;
default:
- LOG.error("Invalid accountId type '{}'",
- accountIdMap.getIntMappingType());
+ LOG.error("Invalid accountId type '{}'", accountIdMap.getIntMappingType());
}
}
@@ -623,7 +286,7 @@ public class SyncJob extends AbstractTas
final SyncResult result = new SyncResult();
result.setOperation(Operation.CREATE);
- UserTO userTO = getUserTO(delta.getObject());
+ UserTO userTO = connObjectUtil.getUserTO(delta.getObject(), (SyncTask) task);
actions.beforeCreate(delta, userTO);
@@ -639,27 +302,21 @@ public class SyncJob extends AbstractTas
// Check for status synchronization ...
// --------------------------
if (((SyncTask) this.task).isSyncStatus()) {
- Attribute status = AttributeUtil.find(
- OperationalAttributes.ENABLE_NAME,
- delta.getObject().getAttributes());
+ Attribute status =
+ AttributeUtil.find(OperationalAttributes.ENABLE_NAME, delta.getObject().getAttributes());
if (status != null) {
enabled = status != null
&& status.getValue() != null
- && !status.getValue().isEmpty()
- ? (Boolean) status.getValue().get(0) : null;
+ && !status.getValue().isEmpty() ? (Boolean) status.getValue().get(0) : null;
}
}
// --------------------------
- WorkflowResult<Map.Entry<Long, Boolean>> created =
- wfAdapter.create(userTO, true, enabled);
+ WorkflowResult<Map.Entry<Long, Boolean>> created = wfAdapter.create(userTO, true, enabled);
- List<PropagationTask> tasks =
- propagationManager.getCreateTaskIds(
- created, userTO.getPassword(), null,
- Collections.singleton(
- ((SyncTask) this.task).getResource().getName()));
+ List<PropagationTask> tasks = propagationManager.getCreateTaskIds(created, userTO.getPassword(), null,
+ Collections.singleton(((SyncTask) this.task).getResource().getName()));
propagationManager.execute(tasks);
userTO = userDataBinder.getUserTO(created.getResult().getKey());
@@ -668,13 +325,11 @@ public class SyncJob extends AbstractTas
result.setUsername(userTO.getUsername());
result.setStatus(Status.SUCCESS);
} catch (PropagationException e) {
- LOG.error("Could not propagate user "
- + delta.getUid().getUidValue(), e);
+ LOG.error("Could not propagate user " + delta.getUid().getUidValue(), e);
} catch (Throwable t) {
result.setStatus(Status.FAILURE);
result.setMessage(t.getMessage());
- LOG.error("Could not create user "
- + delta.getUid().getUidValue(), t);
+ LOG.error("Could not create user " + delta.getUid().getUidValue(), t);
}
}
@@ -703,9 +358,7 @@ public class SyncJob extends AbstractTas
UserTO userTO = userDataBinder.getUserTO(userId);
try {
- final UserMod userMod =
- getUserMod(userId, delta.getObject());
-
+ final UserMod userMod = connObjectUtil.getUserMod(userId, delta.getObject(), (SyncTask) task);
actions.beforeUpdate(delta, userTO, userMod);
result.setStatus(Status.SUCCESS);
@@ -716,26 +369,19 @@ public class SyncJob extends AbstractTas
WorkflowResult<Long> updated =
wfAdapter.update(userMod);
- List<PropagationTask> tasks =
- propagationManager.getUpdateTaskIds(
- updated,
- userMod.getPassword(),
- null, null, null,
- Collections.singleton(
- ((SyncTask) this.task).getResource().getName()));
+ List<PropagationTask> tasks = propagationManager.getUpdateTaskIds(
+ updated, userMod.getPassword(), null, null, null,
+ Collections.singleton(((SyncTask) this.task).getResource().getName()));
propagationManager.execute(tasks);
-
userTO = userDataBinder.getUserTO(updated.getResult());
}
} catch (PropagationException e) {
- LOG.error("Could not propagate user "
- + delta.getUid().getUidValue(), e);
+ LOG.error("Could not propagate user " + delta.getUid().getUidValue(), e);
} catch (Throwable t) {
result.setStatus(Status.FAILURE);
result.setMessage(t.getMessage());
- LOG.error("Could not update user "
- + delta.getUid().getUidValue(), t);
+ LOG.error("Could not update user " + delta.getUid().getUidValue(), t);
}
actions.after(delta, userTO, result);
@@ -773,9 +419,8 @@ public class SyncJob extends AbstractTas
if (!dryRun) {
try {
- List<PropagationTask> tasks =
- propagationManager.getDeleteTaskIds(userId,
- ((SyncTask) this.task).getResource().getName());
+ List<PropagationTask> tasks = propagationManager.getDeleteTaskIds(
+ userId, ((SyncTask) this.task).getResource().getName());
propagationManager.execute(tasks);
} catch (Exception e) {
LOG.error("Could not propagate user " + userId, e);
@@ -882,46 +527,35 @@ public class SyncJob extends AbstractTas
append(deleted.size()).append('/').append(deletedFailed.size());
// Failures
- if (syncTraceLevel == TraceLevel.FAILURES
- || syncTraceLevel == TraceLevel.ALL) {
+ if (syncTraceLevel == TraceLevel.FAILURES || syncTraceLevel == TraceLevel.ALL) {
if (!createdFailed.isEmpty()) {
report.append("\n\nFailed to create: ");
- report.append(SyncResult.reportSetOfSynchronizationResult(
- createdFailed,
- syncTraceLevel));
+ report.append(SyncResult.reportSetOfSynchronizationResult(createdFailed, syncTraceLevel));
}
if (!updatedFailed.isEmpty()) {
report.append("\nFailed to update: ");
- report.append(SyncResult.reportSetOfSynchronizationResult(
- updatedFailed,
- syncTraceLevel));
+ report.append(SyncResult.reportSetOfSynchronizationResult(updatedFailed, syncTraceLevel));
}
if (!deletedFailed.isEmpty()) {
report.append("\nFailed to delete: ");
- report.append(SyncResult.reportSetOfSynchronizationResult(
- deletedFailed,
- syncTraceLevel));
+ report.append(SyncResult.reportSetOfSynchronizationResult(deletedFailed, syncTraceLevel));
}
}
// Succeeded, only if on 'ALL' level
if (syncTraceLevel == TraceLevel.ALL) {
report.append("\n\nCreated:\n").
- append(SyncResult.reportSetOfSynchronizationResult(created,
- syncTraceLevel)).
- append("\nUpdated:\n").append(SyncResult.
- reportSetOfSynchronizationResult(updated, syncTraceLevel)).
- append("\nDeleted:\n").append(SyncResult.
- reportSetOfSynchronizationResult(deleted, syncTraceLevel));
+ append(SyncResult.reportSetOfSynchronizationResult(created, syncTraceLevel)).
+ append("\nUpdated:\n").append(SyncResult.reportSetOfSynchronizationResult(updated, syncTraceLevel)).
+ append("\nDeleted:\n").append(SyncResult.reportSetOfSynchronizationResult(deleted, syncTraceLevel));
}
return report.toString();
}
/**
- * Used to simulate authentication in order to perform updates through
- * AbstractUserWorkflowAdapter.
+ * Used to simulate authentication in order to perform updates through AbstractUserWorkflowAdapter.
*/
private void setupSecurity() {
final List<GrantedAuthority> authorities =
@@ -931,12 +565,10 @@ public class SyncJob extends AbstractTas
authorities.add(new SimpleGrantedAuthority(entitlement.getName()));
}
- final UserDetails userDetails = new User(
- "admin", "FAKE_PASSWORD", true, true, true, true, authorities);
+ final UserDetails userDetails = new User("admin", "FAKE_PASSWORD", true, true, true, true, authorities);
SecurityContextHolder.getContext().setAuthentication(
- new UsernamePasswordAuthenticationToken(
- userDetails, "FAKE_PASSWORD", authorities));
+ new UsernamePasswordAuthenticationToken(userDetails, "FAKE_PASSWORD", authorities));
}
@Override
@@ -949,8 +581,7 @@ public class SyncJob extends AbstractTas
}
if (!(task instanceof SyncTask)) {
- throw new JobExecutionException(
- "Task " + taskId + " isn't a SyncTask");
+ throw new JobExecutionException("Task " + taskId + " isn't a SyncTask");
}
final SyncTask syncTask = (SyncTask) this.task;
@@ -960,21 +591,16 @@ public class SyncJob extends AbstractTas
connector = connInstanceLoader.getConnector(syncTask.getResource());
} catch (Exception e) {
final String msg = String.format(
- "Connector instance bean for resource %s "
- + "and connInstance %s not found",
- syncTask.getResource(),
- syncTask.getResource().getConnector());
+ "Connector instance bean for resource %s and connInstance %s not found",
+ syncTask.getResource(), syncTask.getResource().getConnector());
throw new JobExecutionException(msg, e);
}
- final SchemaMapping accountIdMap =
- syncTask.getResource().getAccountIdMapping();
+ final SchemaMapping accountIdMap = syncTask.getResource().getAccountIdMapping();
if (accountIdMap == null) {
- throw new JobExecutionException(
- "Invalid account id mapping for resource "
- + syncTask.getResource());
+ throw new JobExecutionException("Invalid account id mapping for resource " + syncTask.getResource());
}
LOG.debug("Execute synchronization with token {}",
@@ -986,13 +612,11 @@ public class SyncJob extends AbstractTas
actions.beforeAll(syncTask);
try {
- final SyncPolicy syncPolicy =
- syncTask.getResource().getSyncPolicy();
+ final SyncPolicy syncPolicy = syncTask.getResource().getSyncPolicy();
final ConflictResolutionAction conflictResolutionAction =
syncPolicy != null && syncPolicy.getSpecification() != null
- ? ((SyncPolicySpec) syncPolicy.getSpecification()).
- getConflictResolutionAction()
+ ? ((SyncPolicySpec) syncPolicy.getSpecification()).getConflictResolutionAction()
: ConflictResolutionAction.IGNORE;
if (syncTask.isFullReconciliation()) {
@@ -1004,11 +628,8 @@ public class SyncJob extends AbstractTas
public boolean handle(final SyncDelta delta) {
try {
- return results.addAll(handleDelta(
- syncTask,
- delta,
- conflictResolutionAction,
- dryRun));
+ return results.addAll(
+ handleDelta(syncTask, delta, conflictResolutionAction, dryRun));
} catch (JobExecutionException e) {
LOG.error("Reconciliation failed", e);
@@ -1026,11 +647,8 @@ public class SyncJob extends AbstractTas
public boolean handle(final SyncDelta delta) {
try {
- return results.addAll(handleDelta(
- syncTask,
- delta,
- conflictResolutionAction,
- dryRun));
+ return results.addAll(
+ handleDelta(syncTask, delta, conflictResolutionAction, dryRun));
} catch (JobExecutionException e) {
LOG.error("Synchronization failed", e);
@@ -1043,15 +661,12 @@ public class SyncJob extends AbstractTas
if (!dryRun && !syncTask.isFullReconciliation()) {
try {
- ExternalResource resource =
- resourceDAO.find(syncTask.getResource().getName());
-
+ ExternalResource resource = resourceDAO.find(syncTask.getResource().getName());
resource.setSyncToken(connector.getLatestSyncToken());
resourceDAO.save(resource);
} catch (Throwable t) {
- throw new JobExecutionException("While updating SyncToken",
- t);
+ throw new JobExecutionException("While updating SyncToken", t);
}
}
} catch (Throwable t) {
@@ -1060,8 +675,7 @@ public class SyncJob extends AbstractTas
actions.afterAll(syncTask, results);
- final String result = createReport(
- results, syncTask.getResource().getSyncTraceLevel(), dryRun);
+ final String result = createReport(results, syncTask.getResource().getSyncTraceLevel(), dryRun);
LOG.debug("Sync result: {}", result);
@@ -1087,8 +701,7 @@ public class SyncJob extends AbstractTas
final List<SyncResult> results = new ArrayList<SyncResult>();
- LOG.debug("Process '{}' for '{}'",
- delta.getDeltaType(), delta.getUid().getUidValue());
+ LOG.debug("Process '{}' for '{}'", delta.getDeltaType(), delta.getUid().getUidValue());
final List<Long> users = findExistingUsers(delta);
@@ -1101,8 +714,7 @@ public class SyncJob extends AbstractTas
LOG.debug("SyncTask not configured for create");
}
} else if (users.size() == 1) {
- updateUsers(delta, users.subList(0, 1),
- dryRun, results);
+ updateUsers(delta, users.subList(0, 1), dryRun, results);
} else {
switch (conflictResolutionAction) {
case IGNORE:
@@ -1110,13 +722,11 @@ public class SyncJob extends AbstractTas
break;
case FIRSTMATCH:
- updateUsers(delta, users.subList(0, 1),
- dryRun, results);
+ updateUsers(delta, users.subList(0, 1), dryRun, results);
break;
case LASTMATCH:
- updateUsers(delta, users.subList(users.size()
- - 1, users.size()), dryRun, results);
+ updateUsers(delta, users.subList(users.size() - 1, users.size()), dryRun, results);
break;
case ALL:
@@ -1140,14 +750,11 @@ public class SyncJob extends AbstractTas
break;
case FIRSTMATCH:
- deleteUsers(delta, users.subList(0, 1),
- dryRun, results);
+ deleteUsers(delta, users.subList(0, 1), dryRun, results);
break;
case LASTMATCH:
- deleteUsers(delta, users.subList(
- users.size() - 1, users.size()),
- dryRun, results);
+ deleteUsers(delta, users.subList(users.size() - 1, users.size()), dryRun, results);
break;
case ALL:
@@ -1176,8 +783,7 @@ public class SyncJob extends AbstractTas
// True if either failed and failures have to be registered, or if ALL
// has to be registered.
return (Status.valueOf(execution.getStatus()) == Status.FAILURE
- && syncTask.getResource().getSyncTraceLevel().ordinal()
- >= TraceLevel.FAILURES.ordinal())
+ && syncTask.getResource().getSyncTraceLevel().ordinal() >= TraceLevel.FAILURES.ordinal())
|| syncTask.getResource().getSyncTraceLevel() == TraceLevel.ALL;
}
}
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/util/ConnBundleManager.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/util/ConnBundleManager.java?rev=1296224&r1=1296223&r2=1296224&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/util/ConnBundleManager.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/util/ConnBundleManager.java Fri Mar 2 14:27:34 2012
@@ -22,9 +22,7 @@ import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
-
import javassist.NotFoundException;
-
import org.identityconnectors.common.IOUtil;
import org.identityconnectors.framework.api.APIConfiguration;
import org.identityconnectors.framework.api.ConfigurationProperties;