You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2013/01/21 15:37:45 UTC
svn commit: r1436375 - in /syncope/trunk:
common/src/main/java/org/apache/syncope/common/types/
core/src/main/java/org/apache/syncope/core/connid/
core/src/main/java/org/apache/syncope/core/persistence/beans/
core/src/main/java/org/apache/syncope/core/...
Author: ilgrosso
Date: Mon Jan 21 14:37:44 2013
New Revision: 1436375
URL: http://svn.apache.org/viewvc?rev=1436375&view=rev
Log:
[SYNCOPE-249] core: extension for propagation implemented
Modified:
syncope/trunk/common/src/main/java/org/apache/syncope/common/types/IntMappingType.java
syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java
syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractDerAttr.java
syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractMappingItem.java
syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RMapping.java
syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RMappingItem.java
syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/PropagationManager.java
syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
syncope/trunk/core/src/test/resources/content.xml
Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/types/IntMappingType.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/types/IntMappingType.java?rev=1436375&r1=1436374&r2=1436375&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/types/IntMappingType.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/types/IntMappingType.java Mon Jan 21 14:37:44 2013
@@ -45,6 +45,7 @@ public enum IntMappingType {
RoleVirtualSchema(AttributableType.ROLE),
RoleId(AttributableType.ROLE),
RoleName(AttributableType.ROLE),
+ RoleOwnerSchema(AttributableType.ROLE),
// -------------------------
// Membership attribute types (the same in MembershipMappingType)
// -------------------------
@@ -92,20 +93,21 @@ public enum IntMappingType {
case ROLE:
enumset = EnumSet.allOf(RoleMappingType.class);
break;
+
case MEMBERSHIP:
enumset = EnumSet.allOf(MembershipMappingType.class);
break;
+
default:
enumset = EnumSet.allOf(UserMappingType.class);
}
- final Set<IntMappingType> res = new HashSet<IntMappingType>();
-
+ final Set<IntMappingType> result = new HashSet<IntMappingType>(enumset.size());
for (Object obj : enumset) {
- res.add(IntMappingType.valueOf(obj.toString()));
+ result.add(IntMappingType.valueOf(obj.toString()));
}
- return res;
+ return result;
}
public static Set<IntMappingType> getEmbedded() {
@@ -175,7 +177,8 @@ public enum IntMappingType {
RoleDerivedSchema,
RoleVirtualSchema,
RoleId,
- RoleName;
+ RoleName,
+ RoleOwnerSchema;
}
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java?rev=1436375&r1=1436374&r2=1436375&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java Mon Jan 21 14:37:44 2013
@@ -446,7 +446,7 @@ public class ConnObjectUtil {
LOG.debug("Retrieve remote object from '{}'", resource.getName());
try {
final String accountId = attrUtil.getAccountIdItem(resource) == null
- ? null : MappingUtil.getAccountIdValue(owner, attrUtil.getAccountIdItem(resource));
+ ? null : MappingUtil.getAccountIdValue(owner, resource, attrUtil.getAccountIdItem(resource));
LOG.debug("Search for object with accountId '{}'", accountId);
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractDerAttr.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractDerAttr.java?rev=1436375&r1=1436374&r2=1436375&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractDerAttr.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractDerAttr.java Mon Jan 21 14:37:44 2013
@@ -19,12 +19,10 @@
package org.apache.syncope.core.persistence.beans;
import java.util.Collection;
-
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
-
import org.apache.commons.jexl2.JexlContext;
import org.apache.commons.jexl2.MapContext;
import org.apache.syncope.core.util.ApplicationContextProvider;
@@ -50,7 +48,6 @@ public abstract class AbstractDerAttr ex
* @return the value of this derived attribute
*/
public String getValue(final Collection<? extends AbstractAttr> attributes) {
-
final ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();
final JexlUtil jexlUtil = context.getBean(JexlUtil.class);
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractMappingItem.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractMappingItem.java?rev=1436375&r1=1436374&r2=1436375&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractMappingItem.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractMappingItem.java Mon Jan 21 14:37:44 2013
@@ -26,7 +26,6 @@ import javax.persistence.Enumerated;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
-
import org.apache.syncope.common.types.IntMappingType;
@MappedSuperclass
@@ -117,12 +116,16 @@ public abstract class AbstractMappingIte
name = "username";
break;
+ case Password:
+ name = "password";
+ break;
+
case RoleName:
name = "roleName";
break;
- case Password:
- name = "password";
+ case RoleOwnerSchema:
+ name = "roleOwnerSchema";
break;
default:
@@ -140,7 +143,7 @@ public abstract class AbstractMappingIte
return intMappingType;
}
- public void setIntMappingType(IntMappingType intMappingType) {
+ public void setIntMappingType(final IntMappingType intMappingType) {
this.intMappingType = intMappingType;
}
@@ -148,7 +151,7 @@ public abstract class AbstractMappingIte
return isBooleanAsInteger(accountid);
}
- public void setAccountid(boolean accountid) {
+ public void setAccountid(final boolean accountid) {
this.accountid = getBooleanAsInteger(accountid);
}
@@ -156,7 +159,7 @@ public abstract class AbstractMappingIte
return isBooleanAsInteger(password);
}
- public void setPassword(boolean password) {
+ public void setPassword(final boolean password) {
this.password = getBooleanAsInteger(password);
}
}
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RMapping.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RMapping.java?rev=1436375&r1=1436374&r2=1436375&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RMapping.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RMapping.java Mon Jan 21 14:37:44 2013
@@ -20,14 +20,12 @@ package org.apache.syncope.core.persiste
import java.util.ArrayList;
import java.util.List;
-
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
-
import org.apache.syncope.core.persistence.beans.AbstractMapping;
import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
import org.apache.syncope.core.persistence.beans.ExternalResource;
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RMappingItem.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RMappingItem.java?rev=1436375&r1=1436374&r2=1436375&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RMappingItem.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RMappingItem.java Mon Jan 21 14:37:44 2013
@@ -21,7 +21,6 @@ package org.apache.syncope.core.persiste
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
-
import org.apache.syncope.core.persistence.beans.AbstractMapping;
import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/PropagationManager.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/PropagationManager.java?rev=1436375&r1=1436374&r2=1436375&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/PropagationManager.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/PropagationManager.java Mon Jan 21 14:37:44 2013
@@ -26,27 +26,18 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
-import org.apache.commons.jexl2.JexlContext;
-import org.apache.commons.jexl2.MapContext;
-import org.apache.commons.lang.StringUtils;
import org.apache.syncope.common.mod.AttributeMod;
import org.apache.syncope.common.to.AttributeTO;
import org.apache.syncope.common.types.AttributableType;
-import org.apache.syncope.common.types.IntMappingType;
import org.apache.syncope.common.types.ResourceOperation;
-import org.apache.syncope.common.types.SchemaType;
import org.apache.syncope.core.connid.ConnObjectUtil;
-import org.apache.syncope.core.persistence.beans.AbstractAttrValue;
import org.apache.syncope.core.persistence.beans.AbstractAttributable;
import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
-import org.apache.syncope.core.persistence.beans.AbstractSchema;
import org.apache.syncope.core.persistence.beans.ExternalResource;
import org.apache.syncope.core.persistence.beans.PropagationTask;
import org.apache.syncope.core.persistence.beans.role.SyncopeRole;
import org.apache.syncope.core.persistence.beans.user.SyncopeUser;
import org.apache.syncope.core.persistence.dao.ResourceDAO;
-import org.apache.syncope.core.persistence.dao.SchemaDAO;
import org.apache.syncope.core.propagation.PropagationByResource;
import org.apache.syncope.core.rest.controller.UnauthorizedRoleException;
import org.apache.syncope.core.rest.data.AbstractAttributableDataBinder;
@@ -57,11 +48,9 @@ import org.apache.syncope.core.util.Jexl
import org.apache.syncope.core.util.MappingUtil;
import org.apache.syncope.core.util.NotFoundException;
import org.apache.syncope.core.workflow.WorkflowResult;
-import org.identityconnectors.framework.common.FrameworkUtil;
import org.identityconnectors.framework.common.objects.Attribute;
import org.identityconnectors.framework.common.objects.AttributeBuilder;
import org.identityconnectors.framework.common.objects.AttributeUtil;
-import org.identityconnectors.framework.common.objects.Name;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -97,12 +86,6 @@ public class PropagationManager {
private ResourceDAO resourceDAO;
/**
- * Schema DAO.
- */
- @Autowired
- private SchemaDAO schemaDAO;
-
- /**
* ConnObjectUtil.
*/
@Autowired
@@ -444,110 +427,6 @@ public class PropagationManager {
}
/**
- * Prepare an attribute to be sent to a connector instance.
- *
- * @param <T> user / role
- * @param mapItem mapping item for the given attribute
- * @param subject given user
- * @param password clear-text password
- * @param vAttrsToBeRemoved virtual attributes to be removed
- * @param vAttrsToBeUpdated virtual attributes to be added
- * @return account link + prepared attribute
- * @throws ClassNotFoundException if schema type for given mapping does not exists in current class loader
- */
- protected <T extends AbstractAttributable> Map.Entry<String, Attribute> prepareAttribute(
- final AbstractMappingItem mapItem, final T subject, final String password,
- final Set<String> vAttrsToBeRemoved, final Map<String, AttributeMod> vAttrsToBeUpdated)
- throws ClassNotFoundException {
-
- final List<AbstractAttributable> attributables = new ArrayList<AbstractAttributable>();
-
- switch (mapItem.getIntMappingType().getAttributableType()) {
- case USER:
- if (subject instanceof SyncopeUser) {
- attributables.add(subject);
- }
- break;
-
- case ROLE:
- if (subject instanceof SyncopeUser) {
- attributables.addAll(((SyncopeUser) subject).getRoles());
- }
- if (subject instanceof SyncopeRole) {
- attributables.add(subject);
- }
- break;
-
- case MEMBERSHIP:
- if (subject instanceof SyncopeUser) {
- attributables.addAll(((SyncopeUser) subject).getMemberships());
- }
- break;
-
- default:
- }
-
- final List<AbstractAttrValue> values =
- MappingUtil.getIntValues(mapItem, attributables, password, vAttrsToBeRemoved, vAttrsToBeUpdated);
-
- AbstractSchema schema = null;
- final SchemaType schemaType;
- switch (mapItem.getIntMappingType()) {
- case UserSchema:
- case RoleSchema:
- case MembershipSchema:
- schema = schemaDAO.find(mapItem.getIntAttrName(),
- MappingUtil.getIntMappingTypeClass(mapItem.getIntMappingType()));
- schemaType = schema == null ? SchemaType.String : schema.getType();
- break;
-
- default:
- schemaType = SchemaType.String;
- }
-
- final String extAttrName = mapItem.getExtAttrName();
-
- LOG.debug("Define mapping for: "
- + "\n* ExtAttrName " + extAttrName
- + "\n* is accountId " + mapItem.isAccountid()
- + "\n* is password " + (mapItem.isPassword() || mapItem.getIntMappingType() == IntMappingType.Password)
- + "\n* mandatory condition " + mapItem.getMandatoryCondition()
- + "\n* Schema " + mapItem.getIntAttrName()
- + "\n* IntMappingType " + mapItem.getIntMappingType().toString()
- + "\n* ClassType " + schemaType.getClassName()
- + "\n* Values " + values);
-
- List<Object> objValues = new ArrayList<Object>();
-
- for (AbstractAttrValue value : values) {
- if (FrameworkUtil.isSupportedAttributeType(Class.forName(schemaType.getClassName()))) {
- objValues.add(value.getValue());
- } else {
- objValues.add(value.getValueAsString());
- }
- }
-
- Map.Entry<String, Attribute> result;
-
- if (mapItem.isAccountid()) {
- result = new SimpleEntry<String, Attribute>(objValues.iterator().next().toString(), null);
- } else if (mapItem.isPassword()) {
- result = new SimpleEntry<String, Attribute>(null,
- AttributeBuilder.buildPassword(objValues.iterator().next().toString().toCharArray()));
- } else {
- if (schema != null && schema.isMultivalue()) {
- result = new SimpleEntry<String, Attribute>(null, AttributeBuilder.build(extAttrName, objValues));
- } else {
- result = new SimpleEntry<String, Attribute>(null, objValues.isEmpty()
- ? AttributeBuilder.build(extAttrName)
- : AttributeBuilder.build(extAttrName, objValues.iterator().next()));
- }
- }
-
- return result;
- }
-
- /**
* Prepare attributes for sending to a connector instance.
*
* @param <T> user / role
@@ -557,13 +436,11 @@ public class PropagationManager {
* @param vAttrsToBeUpdated virtual attributes to be added
* @param enable whether user must be enabled or not
* @param resource target resource
- * @param attrUtil attributable util to get info about subject
* @return account link + prepared attributes
*/
protected <T extends AbstractAttributable> Map.Entry<String, Set<Attribute>> prepareAttributes(final T subject,
final String password, final Set<String> vAttrsToBeRemoved,
- final Map<String, AttributeMod> vAttrsToBeUpdated, final Boolean enable, final ExternalResource resource,
- final AttributableUtil attrUtil) {
+ final Map<String, AttributeMod> vAttrsToBeUpdated, final Boolean enable, final ExternalResource resource) {
LOG.debug("Preparing resource attributes for {} on resource {} with attributes {}",
subject, resource, subject.getAttributes());
@@ -571,12 +448,13 @@ public class PropagationManager {
Set<Attribute> attributes = new HashSet<Attribute>();
String accountId = null;
+ final AttributableUtil attrUtil = AttributableUtil.getInstance(subject);
for (AbstractMappingItem mapping : attrUtil.getMappingItems(resource)) {
LOG.debug("Processing schema {}", mapping.getIntAttrName());
try {
- Map.Entry<String, Attribute> preparedAttribute = prepareAttribute(
- mapping, subject, password, vAttrsToBeRemoved, vAttrsToBeUpdated);
+ Map.Entry<String, Attribute> preparedAttribute = MappingUtil.prepareAttribute(
+ resource, mapping, subject, password, vAttrsToBeRemoved, vAttrsToBeUpdated);
if (preparedAttribute.getKey() != null) {
accountId = preparedAttribute.getKey();
@@ -591,7 +469,7 @@ public class PropagationManager {
} else {
attributes.remove(alreadyAdded);
- Set values = new HashSet(alreadyAdded.getValue());
+ Set<Object> values = new HashSet<Object>(alreadyAdded.getValue());
values.addAll(preparedAttribute.getValue().getValue());
attributes.add(AttributeBuilder.build(preparedAttribute.getValue().getName(), values));
@@ -602,34 +480,7 @@ public class PropagationManager {
}
}
- if (StringUtils.isBlank(accountId)) {
- // LOG error but avoid to throw exception: leave it to the external resource
- LOG.error("Missing accountId for '{}': ", resource.getName());
- }
-
- // Evaluate AccountLink expression
- String evalAccountLink = null;
- if (StringUtils.isNotBlank(attrUtil.getAccountLink(resource))) {
- final JexlContext jexlContext = new MapContext();
- jexlUtil.addFieldsToContext(subject, jexlContext);
- jexlUtil.addAttrsToContext(subject.getAttributes(), jexlContext);
- jexlUtil.addDerAttrsToContext(subject.getDerivedAttributes(), subject.getAttributes(), jexlContext);
- evalAccountLink = jexlUtil.evaluate(attrUtil.getAccountLink(resource), jexlContext);
- }
-
- // If AccountLink evaluates to an empty string, just use the provided AccountId as Name(),
- // otherwise evaluated AccountLink expression is taken as Name().
- if (StringUtils.isBlank(evalAccountLink)) {
- // add AccountId as __NAME__ attribute ...
- LOG.debug("Add AccountId [{}] as __NAME__", accountId);
- attributes.add(new Name(accountId));
- } else {
- LOG.debug("Add AccountLink [{}] as __NAME__", evalAccountLink);
- attributes.add(new Name(evalAccountLink));
-
- // AccountId not propagated: it will be used to set the value for __UID__ attribute
- LOG.debug("AccountId will be used just as __UID__ attribute");
- }
+ attributes.add(MappingUtil.evaluateNAME(subject, resource, accountId));
if (enable != null) {
attributes.add(AttributeBuilder.buildEnabled(enable));
@@ -658,8 +509,6 @@ public class PropagationManager {
LOG.debug("Provisioning subject {}:\n{}", subject, propByRes);
- AttributableUtil attrUtil = AttributableUtil.getInstance(subject);
-
// Avoid duplicates - see javadoc
propByRes.purge();
LOG.debug("After purge: {}", propByRes);
@@ -684,7 +533,7 @@ public class PropagationManager {
task.setOldAccountId(propByRes.getOldAccountId(resource.getName()));
Map.Entry<String, Set<Attribute>> preparedAttrs = prepareAttributes(subject, password,
- vAttrsToBeRemoved, vAttrsToBeUpdated, enable, resource, attrUtil);
+ vAttrsToBeRemoved, vAttrsToBeUpdated, enable, resource);
task.setAccountId(preparedAttrs.getKey());
task.setAttributes(preparedAttrs.getValue());
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java?rev=1436375&r1=1436374&r2=1436375&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java Mon Jan 21 14:37:44 2013
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.core.util;
+import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -25,14 +26,20 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.commons.jexl2.JexlContext;
+import org.apache.commons.jexl2.MapContext;
+import org.apache.commons.lang.StringUtils;
import org.apache.syncope.common.mod.AttributeMod;
import org.apache.syncope.common.types.IntMappingType;
+import org.apache.syncope.common.types.SchemaType;
import org.apache.syncope.core.persistence.beans.AbstractAttr;
import org.apache.syncope.core.persistence.beans.AbstractAttrValue;
import org.apache.syncope.core.persistence.beans.AbstractAttributable;
import org.apache.syncope.core.persistence.beans.AbstractDerAttr;
import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
+import org.apache.syncope.core.persistence.beans.AbstractSchema;
import org.apache.syncope.core.persistence.beans.AbstractVirAttr;
+import org.apache.syncope.core.persistence.beans.ExternalResource;
import org.apache.syncope.core.persistence.beans.membership.MDerSchema;
import org.apache.syncope.core.persistence.beans.membership.MSchema;
import org.apache.syncope.core.persistence.beans.membership.MVirSchema;
@@ -46,8 +53,14 @@ import org.apache.syncope.core.persisten
import org.apache.syncope.core.persistence.beans.user.UDerSchema;
import org.apache.syncope.core.persistence.beans.user.USchema;
import org.apache.syncope.core.persistence.beans.user.UVirSchema;
+import org.apache.syncope.core.persistence.dao.SchemaDAO;
+import org.identityconnectors.framework.common.FrameworkUtil;
+import org.identityconnectors.framework.common.objects.Attribute;
+import org.identityconnectors.framework.common.objects.AttributeBuilder;
+import org.identityconnectors.framework.common.objects.Name;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.context.ConfigurableApplicationContext;
public final class MappingUtil {
@@ -88,15 +101,197 @@ public final class MappingUtil {
}
/**
+ * Prepare an attribute to be sent to a connector instance.
+ *
+ * @param resource target resource
+ * @param <T> user / role
+ * @param mapItem mapping item for the given attribute
+ * @param subject given user
+ * @param password clear-text password
+ * @param vAttrsToBeRemoved virtual attributes to be removed
+ * @param vAttrsToBeUpdated virtual attributes to be added
+ * @return account link + prepared attribute
+ * @throws ClassNotFoundException if schema type for given mapping does not exists in current class loader
+ */
+ public static <T extends AbstractAttributable> Map.Entry<String, Attribute> prepareAttribute(
+ final ExternalResource resource, final AbstractMappingItem mapItem,
+ final T subject, final String password,
+ final Set<String> vAttrsToBeRemoved, final Map<String, AttributeMod> vAttrsToBeUpdated)
+ throws ClassNotFoundException {
+
+ final List<AbstractAttributable> attributables = new ArrayList<AbstractAttributable>();
+
+ switch (mapItem.getIntMappingType().getAttributableType()) {
+ case USER:
+ if (subject instanceof SyncopeUser) {
+ attributables.add(subject);
+ }
+ break;
+
+ case ROLE:
+ if (subject instanceof SyncopeUser) {
+ attributables.addAll(((SyncopeUser) subject).getRoles());
+ }
+ if (subject instanceof SyncopeRole) {
+ attributables.add(subject);
+ }
+ break;
+
+ case MEMBERSHIP:
+ if (subject instanceof SyncopeUser) {
+ attributables.addAll(((SyncopeUser) subject).getMemberships());
+ }
+ break;
+
+ default:
+ }
+
+ final List<AbstractAttrValue> values = MappingUtil.getIntValues(resource, mapItem, attributables, password,
+ vAttrsToBeRemoved, vAttrsToBeUpdated);
+
+ AbstractSchema schema = null;
+ SchemaType schemaType;
+ switch (mapItem.getIntMappingType()) {
+ case UserSchema:
+ case RoleSchema:
+ case MembershipSchema:
+ final ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();
+ final SchemaDAO schemaDAO = context.getBean(SchemaDAO.class);
+ schema = schemaDAO.find(mapItem.getIntAttrName(),
+ MappingUtil.getIntMappingTypeClass(mapItem.getIntMappingType()));
+ schemaType = schema == null ? SchemaType.String : schema.getType();
+ break;
+
+ default:
+ schemaType = SchemaType.String;
+ }
+
+ final String extAttrName = mapItem.getExtAttrName();
+
+ LOG.debug("Define mapping for: "
+ + "\n* ExtAttrName " + extAttrName
+ + "\n* is accountId " + mapItem.isAccountid()
+ + "\n* is password " + (mapItem.isPassword() || mapItem.getIntMappingType() == IntMappingType.Password)
+ + "\n* mandatory condition " + mapItem.getMandatoryCondition()
+ + "\n* Schema " + mapItem.getIntAttrName()
+ + "\n* IntMappingType " + mapItem.getIntMappingType().toString()
+ + "\n* ClassType " + schemaType.getClassName()
+ + "\n* Values " + values);
+
+ List<Object> objValues = new ArrayList<Object>();
+
+ for (AbstractAttrValue value : values) {
+ if (FrameworkUtil.isSupportedAttributeType(Class.forName(schemaType.getClassName()))) {
+ objValues.add(value.getValue());
+ } else {
+ objValues.add(value.getValueAsString());
+ }
+ }
+
+ Map.Entry<String, Attribute> result;
+
+ if (mapItem.isAccountid()) {
+ result = new AbstractMap.SimpleEntry<String, Attribute>(objValues.iterator().next().toString(), null);
+ } else if (mapItem.isPassword()) {
+ result = new AbstractMap.SimpleEntry<String, Attribute>(null,
+ AttributeBuilder.buildPassword(objValues.iterator().next().toString().toCharArray()));
+ } else {
+ if (schema != null && schema.isMultivalue()) {
+ result = new AbstractMap.SimpleEntry<String, Attribute>(null, AttributeBuilder.build(extAttrName,
+ objValues));
+ } else {
+ result = new AbstractMap.SimpleEntry<String, Attribute>(null, objValues.isEmpty()
+ ? AttributeBuilder.build(extAttrName)
+ : AttributeBuilder.build(extAttrName, objValues.iterator().next()));
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Build __NAME__ for propagation. First look if there ia a defined accountLink for the given resource (and in this
+ * case evaluate as JEXL); otherwise, take given accountId.
+ *
+ * @param <T> user / role
+ * @param subject given user / role
+ * @param resource target resource
+ * @param accountId accountId
+ * @return the value to be propagated as __NAME__
+ */
+ public static <T extends AbstractAttributable> Name evaluateNAME(final T subject,
+ final ExternalResource resource, final String accountId) {
+
+ final AttributableUtil attrUtil = AttributableUtil.getInstance(subject);
+
+ if (StringUtils.isBlank(accountId)) {
+ // LOG error but avoid to throw exception: leave it to the external resource
+ LOG.error("Missing accountId for '{}': ", resource.getName());
+ }
+
+ // Evaluate AccountLink expression
+ String evalAccountLink = null;
+ if (StringUtils.isNotBlank(attrUtil.getAccountLink(resource))) {
+ final ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();
+ final JexlUtil jexlUtil = context.getBean(JexlUtil.class);
+
+ final JexlContext jexlContext = new MapContext();
+ jexlUtil.addFieldsToContext(subject, jexlContext);
+ jexlUtil.addAttrsToContext(subject.getAttributes(), jexlContext);
+ jexlUtil.addDerAttrsToContext(subject.getDerivedAttributes(), subject.getAttributes(), jexlContext);
+ evalAccountLink = jexlUtil.evaluate(attrUtil.getAccountLink(resource), jexlContext);
+ }
+
+ // If AccountLink evaluates to an empty string, just use the provided AccountId as Name(),
+ // otherwise evaluated AccountLink expression is taken as Name().
+ Name name;
+ if (StringUtils.isBlank(evalAccountLink)) {
+ // add AccountId as __NAME__ attribute ...
+ LOG.debug("Add AccountId [{}] as __NAME__", accountId);
+ name = new Name(accountId);
+ } else {
+ LOG.debug("Add AccountLink [{}] as __NAME__", evalAccountLink);
+ name = new Name(evalAccountLink);
+
+ // AccountId not propagated: it will be used to set the value for __UID__ attribute
+ LOG.debug("AccountId will be used just as __UID__ attribute");
+ }
+
+ return name;
+ }
+
+ private static <T extends AbstractAttributable> String getRoleOwnerValue(final ExternalResource resource,
+ final T subject) {
+
+ final AttributableUtil attrUtil = AttributableUtil.getInstance(subject);
+
+ String accountId = null;
+ try {
+ Map.Entry<String, Attribute> preparedAttr = prepareAttribute(
+ resource, attrUtil.getAccountIdItem(resource), subject, null,
+ Collections.<String>emptySet(), Collections.<String, AttributeMod>emptyMap());
+ accountId = preparedAttr.getKey();
+ } catch (ClassNotFoundException e) {
+ LOG.error("Could not get accountId for {} on {}", subject, resource, e);
+ }
+
+ final Name roleOwnerName = evaluateNAME(subject, resource, accountId);
+ return roleOwnerName.getNameValue();
+ }
+
+ /**
* Get attribute values.
*
+ * @param resource target resource
* @param mappingItem mapping item
* @param attributables list of attributables
- * @param password password
+ * @param pwd password
+ * @param vAttrsToBeRemoved virtual attributes to be removed
+ * @param vAttrsToBeUpdated virtual attributes to be added
* @return attribute values.
*/
- public static List<AbstractAttrValue> getIntValues(final AbstractMappingItem mappingItem,
- final List<AbstractAttributable> attributables, final String password,
+ public static List<AbstractAttrValue> getIntValues(final ExternalResource resource,
+ final AbstractMappingItem mappingItem, final List<AbstractAttributable> attributables, final String pwd,
final Set<String> vAttrsToBeRemoved, final Map<String, AttributeMod> vAttrsToBeUpdated) {
LOG.debug("Get attributes for '{}' and mapping type '{}'", attributables, mappingItem.getIntMappingType());
@@ -171,8 +366,7 @@ public final class MappingUtil {
values.add(attrValue);
}
- LOG.
- debug("Retrieved attribute {}"
+ LOG.debug("Retrieved attribute {}"
+ "\n* IntAttrName {}"
+ "\n* IntMappingType {}"
+ "\n* Attribute values {}",
@@ -202,8 +396,8 @@ public final class MappingUtil {
case Password:
AbstractAttrValue attrValue = new UAttrValue();
- if (password != null) {
- attrValue.setStringValue(password);
+ if (pwd != null) {
+ attrValue.setStringValue(pwd);
}
values.add(attrValue);
break;
@@ -218,6 +412,27 @@ public final class MappingUtil {
}
break;
+ case RoleOwnerSchema:
+ for (AbstractAttributable attributable : attributables) {
+ if (attributable instanceof SyncopeRole) {
+ SyncopeRole role = (SyncopeRole) attributable;
+ String roleOwnerValue = null;
+ if (role.getUserOwner() != null && resource.getUmapping() != null) {
+ roleOwnerValue = getRoleOwnerValue(resource, role.getUserOwner());
+ }
+ if (role.getRoleOwner() != null && resource.getRmapping() != null) {
+ roleOwnerValue = getRoleOwnerValue(resource, role.getRoleOwner());
+ }
+
+ if (StringUtils.isNotBlank(roleOwnerValue)) {
+ attrValue = new RAttrValue();
+ attrValue.setStringValue(roleOwnerValue);
+ values.add(attrValue);
+ }
+ }
+ }
+ break;
+
default:
}
@@ -233,11 +448,11 @@ public final class MappingUtil {
* @param accountIdItem accountid mapping item
* @return accountId internal value
*/
- public static String getAccountIdValue(final AbstractAttributable attributable,
+ public static String getAccountIdValue(final AbstractAttributable attributable, final ExternalResource resource,
final AbstractMappingItem accountIdItem) {
- List<AbstractAttrValue> values = getIntValues(
- accountIdItem, Collections.<AbstractAttributable>singletonList(attributable), null, null, null);
+ List<AbstractAttrValue> values = getIntValues(resource, accountIdItem,
+ Collections.<AbstractAttributable>singletonList(attributable), null, null, null);
return values == null || values.isEmpty()
? null
: values.get(0).getValueAsString();
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java?rev=1436375&r1=1436374&r2=1436375&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java Mon Jan 21 14:37:44 2013
@@ -19,9 +19,7 @@
package org.apache.syncope.core.rest;
import java.util.UUID;
-
import javax.sql.DataSource;
-
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.syncope.client.http.PreemptiveAuthHttpRequestFactory;
@@ -64,23 +62,9 @@ import org.springframework.test.context.
import org.springframework.web.client.RestTemplate;
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "classpath:restClientContext.xml", "classpath:testJDBCContext.xml" })
+@ContextConfiguration(locations = {"classpath:restClientContext.xml", "classpath:testJDBCContext.xml"})
public abstract class AbstractTest {
- protected static AttributeTO attributeTO(final String schema, final String value) {
- AttributeTO attr = new AttributeTO();
- attr.setSchema(schema);
- attr.addValue(value);
- return attr;
- }
-
- protected static AttributeMod attributeMod(final String schema, final String valueToBeAdded) {
- AttributeMod attr = new AttributeMod();
- attr.setSchema(schema);
- attr.addValueToBeAdded(valueToBeAdded);
- return attr;
- }
-
/**
* Logger.
*/
@@ -88,15 +72,16 @@ public abstract class AbstractTest {
protected static final String BASE_URL = "http://localhost:9080/syncope/rest/";
- public static final String ADMIN_UID = "admin";
+ protected static final String ADMIN_UID = "admin";
- public static final String ADMIN_PWD = "password";
-
- protected PolicyServiceProxy policyService;
+ protected static final String ADMIN_PWD = "password";
@Autowired
private RestTemplate restTemplate;
+ @Autowired
+ protected DataSource testDataSource;
+
protected UserService userService;
protected RoleService roleService;
@@ -123,18 +108,27 @@ public abstract class AbstractTest {
protected UserRequestService userRequestService;
- @Autowired
- protected DataSource testDataSource;
+ protected PolicyServiceProxy policyService;
- public static String getUUIDString() {
- return UUID.randomUUID().toString().substring(0, 8);
+ protected static String getUUIDString() {
+ return UUID.randomUUID().toString().substring(0, 8);
}
- protected RestTemplate anonymousRestTemplate() {
- return new RestTemplate();
+ protected static AttributeTO attributeTO(final String schema, final String value) {
+ AttributeTO attr = new AttributeTO();
+ attr.setSchema(schema);
+ attr.addValue(value);
+ return attr;
}
- public void setupRestTemplate(final String uid, final String pwd) {
+ protected static AttributeMod attributeMod(final String schema, final String valueToBeAdded) {
+ AttributeMod attr = new AttributeMod();
+ attr.setSchema(schema);
+ attr.addValueToBeAdded(valueToBeAdded);
+ return attr;
+ }
+
+ protected void setupRestTemplate(final String uid, final String pwd) {
PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory) restTemplate
.getRequestFactory());
@@ -142,6 +136,10 @@ public abstract class AbstractTest {
requestFactory.getAuthScope(), new UsernamePasswordCredentials(uid, pwd));
}
+ protected RestTemplate anonymousRestTemplate() {
+ return new RestTemplate();
+ }
+
@Before
public void resetRestTemplate() {
setupRestTemplate(ADMIN_UID, ADMIN_PWD);
@@ -160,5 +158,4 @@ public abstract class AbstractTest {
schemaService = new SchemaServiceProxy(BASE_URL, restTemplate);
userRequestService = new UserRequestServiceProxy(BASE_URL, restTemplate);
}
-
}
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java?rev=1436375&r1=1436374&r2=1436375&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java Mon Jan 21 14:37:44 2013
@@ -27,7 +27,6 @@ import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
-
import org.apache.syncope.common.mod.RoleMod;
import org.apache.syncope.common.to.ConnObjectTO;
import org.apache.syncope.common.to.RoleTO;
@@ -45,6 +44,31 @@ import org.springframework.web.client.Ht
@FixMethodOrder(MethodSorters.JVM)
public class RoleTestITCase extends AbstractTest {
+ private RoleTO buildBasicRoleTO(final String name) {
+ RoleTO roleTO = new RoleTO();
+ roleTO.setName(name + getUUIDString());
+ roleTO.setParent(8L);
+ return roleTO;
+ }
+
+ private RoleTO buildRoleTO(final String name) {
+ RoleTO roleTO = buildBasicRoleTO(name);
+
+ // verify inheritance password and account policies
+ roleTO.setInheritAccountPolicy(false);
+ // not inherited so setter execution shouldn't be ignored
+ roleTO.setAccountPolicy(6L);
+
+ roleTO.setInheritPasswordPolicy(true);
+ // inherited so setter execution should be ignored
+ roleTO.setPasswordPolicy(2L);
+
+ roleTO.addAttribute(attributeTO("icon", "anIcon"));
+
+ roleTO.addResource("resource-ldap");
+ return roleTO;
+ }
+
@Test
public void createWithException() {
RoleTO newRoleTO = new RoleTO();
@@ -63,11 +87,9 @@ public class RoleTestITCase extends Abst
@Test
public void create() {
RoleTO roleTO = buildRoleTO("lastRole");
- roleTO.addDerivedAttribute(attributeTO("ownerDN", null));
roleTO.addVirtualAttribute(attributeTO("rvirtualdata", "rvirtualvalue"));
roleTO.setRoleOwner(8L);
-
roleTO = roleService.create(roleTO);
assertNotNull(roleTO);
@@ -85,7 +107,7 @@ public class RoleTestITCase extends Abst
assertTrue(roleTO.getResources().contains("resource-ldap"));
ConnObjectTO connObjectTO = resourceService.getConnector("resource-ldap", AttributableType.ROLE,
- roleTO.getName());
+ roleTO.getName());
assertNotNull(connObjectTO);
assertNotNull(connObjectTO.getAttributeMap().get("owner"));
}
@@ -203,7 +225,7 @@ public class RoleTestITCase extends Abst
RoleMod roleMod = new RoleMod();
roleMod.setId(roleTO.getId());
- String modName = "finalRole" + getUUIDString();
+ String modName = "finalRole" + getUUIDString();
roleMod.setName(modName);
roleMod.addAttributeToBeUpdated(attributeMod("show", "FALSE"));
@@ -302,7 +324,7 @@ public class RoleTestITCase extends Abst
@Test
public void issue178() {
RoleTO roleTO = new RoleTO();
- String roleName = "torename" + getUUIDString();
+ String roleName = "torename" + getUUIDString();
roleTO.setName(roleName);
RoleTO actual = roleService.create(roleTO);
@@ -313,7 +335,7 @@ public class RoleTestITCase extends Abst
RoleMod roleMod = new RoleMod();
roleMod.setId(actual.getId());
- String renamedRole = "renamed" + getUUIDString();
+ String renamedRole = "renamed" + getUUIDString();
roleMod.setName(renamedRole);
actual = roleService.update(roleMod.getId(), roleMod);
@@ -352,30 +374,4 @@ public class RoleTestITCase extends Abst
assertNotNull(roleTO);
assertTrue(roleTO.getEntitlements().isEmpty());
}
-
- private RoleTO buildBasicRoleTO(String name) {
- RoleTO roleTO = new RoleTO();
- roleTO.setName(name + getUUIDString());
- roleTO.setParent(8L);
- return roleTO;
- }
-
- private RoleTO buildRoleTO(String name) {
- RoleTO roleTO = buildBasicRoleTO(name);
-
- // verify inheritance password and account policies
- roleTO.setInheritAccountPolicy(false);
- // not inherited so setter execution shouldn't be ignored
- roleTO.setAccountPolicy(6L);
-
- roleTO.setInheritPasswordPolicy(true);
- // inherited so setter execution should be ignored
- roleTO.setPasswordPolicy(2L);
-
- roleTO.addAttribute(attributeTO("icon", "anIcon"));
-
- roleTO.addResource("resource-ldap");
- return roleTO;
- }
-
}
Modified: syncope/trunk/core/src/test/resources/content.xml
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/resources/content.xml?rev=1436375&r1=1436374&r2=1436375&view=diff
==============================================================================
--- syncope/trunk/core/src/test/resources/content.xml (original)
+++ syncope/trunk/core/src/test/resources/content.xml Mon Jan 21 14:37:44 2013
@@ -209,10 +209,6 @@ under the License.
<!-- rderiveddata is used to verify der schema deletion -->
<RDerSchema name="rderivedschema" expression="rderived_sx + '-' + rderived_dx"/>
- <!-- used for RMapping below -->
- <RDerSchema name="ownerDN"
- expression="!empty(roleOwner) ? 'cn=' + roleOwner.name + ',ou=groups,o=isp': (!empty(userOwner) ? 'uid=' + userOwner.username + ',ou=people,o=isp' : '')"/>
-
<RAttr id="994" owner_id="12" schema_name="title"/>
<RAttrValue attribute_id="994" id="94" stringValue="r12"/>
@@ -576,7 +572,7 @@ under the License.
extAttrName="__UID__" intAttrName="roleName" intMappingType="RoleName"
mandatoryCondition="true"/>
<RMappingItem id="2" accountid="0" password="0" mapping_id="1"
- extAttrName="owner" intAttrName="ownerDN" intMappingType="RoleDerivedSchema"
+ extAttrName="owner" intAttrName="roleOwnerSchema" intMappingType="RoleOwnerSchema"
mandatoryCondition="false"/>
<RMappingItem id="3" accountid="0" password="0" mapping_id="1"
extAttrName="description" intAttrName="title" intMappingType="RoleSchema"