Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into gui-devel
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jun 30, 2014
2 parents 76efe15 + 7c584cb commit 3810320
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 52 deletions.
Expand Up @@ -25,6 +25,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;

import java.io.Serializable;
import java.util.Collection;

public class RefinedAssociationDefinition implements Serializable {

Expand Down Expand Up @@ -56,11 +57,11 @@ public ShadowKindType getKind() {
return resourceObjectAssociationType.getKind();
}

public String getIntent() {
return resourceObjectAssociationType.getIntent();
}
public MappingType getOutboundMappingType() {
public Collection<String> getIntents() {
return resourceObjectAssociationType.getIntent();
}

public MappingType getOutboundMappingType() {
return resourceObjectAssociationType.getOutbound();
}

Expand Down
Expand Up @@ -561,12 +561,11 @@ private static RefinedObjectClassDefinition parseRefinedObjectClass(ResourceObje
return rOcDef;
}

public void parseAssociations(RefinedResourceSchema rSchema) {
public void parseAssociations(RefinedResourceSchema rSchema) throws SchemaException {
for (ResourceObjectAssociationType resourceObjectAssociationType: schemaHandlingObjectTypeDefinitionType.getAssociation()) {
RefinedAssociationDefinition rAssocDef = new RefinedAssociationDefinition(resourceObjectAssociationType);
ShadowKindType assocKind = rAssocDef.getKind();
String assocIntent = rAssocDef.getIntent();
RefinedObjectClassDefinition assocTarget = rSchema.getRefinedDefinition(assocKind, assocIntent);
RefinedObjectClassDefinition assocTarget = rSchema.getRefinedDefinition(assocKind, rAssocDef.getIntents());
rAssocDef.setAssociationTarget(assocTarget);
associations.add(rAssocDef);
}
Expand Down
Expand Up @@ -114,8 +114,38 @@ public RefinedObjectClassDefinition getRefinedDefinition(ShadowKindType kind, St
}
return null;
}

public RefinedObjectClassDefinition getRefinedDefinition(QName objectClassName) {

/**
* If no intents are provided, default account definition is returned.
* We check whether there is only one relevant rOCD.
*/
public RefinedObjectClassDefinition getRefinedDefinition(ShadowKindType kind, Collection<String> intents) throws SchemaException {
RefinedObjectClassDefinition found = null;
for (RefinedObjectClassDefinition acctDef: getRefinedDefinitions(kind)) {
RefinedObjectClassDefinition foundCurrent = null;
if (intents == null || intents.isEmpty()) {
if (acctDef.isDefault()) {
foundCurrent = acctDef;
}
} else {
if (intents.contains(acctDef.getIntent())) {
foundCurrent = acctDef;
}
}
if (foundCurrent != null) {
if (found != null) {
if (!QNameUtil.match(found.getTypeName(), foundCurrent.getTypeName())) {
throw new SchemaException("More than one ObjectClass found for kind " + kind + ", intents: " + intents + ": " + found.getTypeName() + ", " + foundCurrent.getTypeName());
}
} else {
found = foundCurrent;
}
}
}
return found;
}

public RefinedObjectClassDefinition getRefinedDefinition(QName objectClassName) {
for (Definition def: definitions) {
if ((def instanceof RefinedObjectClassDefinition)
&& (QNameUtil.match(def.getTypeName(), objectClassName))) {
Expand Down
Expand Up @@ -3906,7 +3906,14 @@
<xsd:extension base="tns:ResourceItemDefinitionType">
<xsd:sequence>
<xsd:element name="kind" type="tns:ShadowKindType" minOccurs="0"></xsd:element>
<xsd:element name="intent" type="xsd:string" minOccurs="0"></xsd:element>
<xsd:element name="intent" type="xsd:string" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
A set of intents corresponding to this association type.
NOTE: All of them must point to the same resource ObjectClass!
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="direction" type="tns:ResourceObjectAssociationDirectionType" minOccurs="0"></xsd:element>
<xsd:element name="associationAttribute" type="xsd:QName" minOccurs="0"></xsd:element>
<xsd:element name="valueAttribute" type="xsd:QName" minOccurs="0"></xsd:element>
Expand Down
Expand Up @@ -23,11 +23,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.model.impl.ModelConstants;
import com.evolveum.midpoint.model.impl.sync.SynchronizeAccountResultHandler;
import com.evolveum.midpoint.model.impl.util.AbstractSearchIterativeResultHandler;
import com.evolveum.midpoint.model.impl.util.AbstractSearchIterativeTaskHandler;
import com.evolveum.midpoint.model.impl.util.Utils;
import com.evolveum.midpoint.prism.PrismObject;
Expand Down Expand Up @@ -180,11 +178,12 @@ protected SynchronizeAccountResultHandler createHandler(TaskRunResult runResult,
return null;
}

return createHandler(resource, runResult, task, opResult);
return createHandler(resource, null, runResult, task, opResult);
}

private SynchronizeAccountResultHandler createHandler(ResourceType resource, TaskRunResult runResult, Task task,
OperationResult opResult) {

// shadowToImport - it is used to derive objectClass/intent/kind when importing a single shadow
private SynchronizeAccountResultHandler createHandler(ResourceType resource, PrismObject<ShadowType> shadowToImport,
TaskRunResult runResult, Task task, OperationResult opResult) {

RefinedResourceSchema refinedSchema;
try {
Expand All @@ -200,7 +199,12 @@ private SynchronizeAccountResultHandler createHandler(ResourceType resource, Tas
LOGGER.trace("Refined schema:\n{}", refinedSchema.debugDump());
}

ObjectClassComplexTypeDefinition objectClass = Utils.determineObjectClass(refinedSchema, task);
ObjectClassComplexTypeDefinition objectClass;
if (shadowToImport != null) {
objectClass = Utils.determineObjectClass(refinedSchema, shadowToImport);
} else {
objectClass = Utils.determineObjectClass(refinedSchema, task);
}
if (objectClass == null) {
LOGGER.error("Import: No objectclass specified and no default can be determined.");
opResult.recordFatalError("No objectclass specified and no default can be determined");
Expand Down Expand Up @@ -260,7 +264,7 @@ public boolean importSingleShadow(String shadowOid, Task task, OperationResult p

// Create a result handler just for one object. Invoke the handle() method manually.
TaskRunResult runResult = new TaskRunResult();
SynchronizeAccountResultHandler resultHandler = createHandler(resource.asObjectable(), runResult, task, parentResult);
SynchronizeAccountResultHandler resultHandler = createHandler(resource.asObjectable(), shadow, runResult, task, parentResult);
if (resultHandler == null) {
return false;
}
Expand Down
Expand Up @@ -280,27 +280,38 @@ private static void resolveRef(PrismReferenceValue refVal, RepositoryService rep
refVal.setOid(oid);
result.recordSuccessIfUnknown();
}

public static ObjectClassComplexTypeDefinition determineObjectClass(RefinedResourceSchema refinedSchema, Task task) {

public static ObjectClassComplexTypeDefinition determineObjectClass(RefinedResourceSchema refinedSchema, Task task) {

QName objectclass = null;
PrismProperty<QName> objectclassProperty = task.getExtensionProperty(ModelConstants.OBJECTCLASS_PROPERTY_NAME);
if (objectclassProperty != null) {
objectclass = objectclassProperty.getValue().getValue();
}

ShadowKindType kind = null;
PrismProperty<ShadowKindType> kindProperty = task.getExtensionProperty(ModelConstants.KIND_PROPERTY_NAME);
if (kindProperty != null) {
kind = kindProperty.getValue().getValue();
}

String intent = null;
PrismProperty<String> intentProperty = task.getExtensionProperty(ModelConstants.INTENT_PROPERTY_NAME);
if (intentProperty != null) {
intent = intentProperty.getValue().getValue();
}

return determineObjectClassInternal(refinedSchema, objectclass, kind, intent, task);
}

public static ObjectClassComplexTypeDefinition determineObjectClass(RefinedResourceSchema refinedSchema, PrismObject<ShadowType> shadowToImport) {
ShadowType s = shadowToImport.asObjectable();
return determineObjectClassInternal(refinedSchema, s.getObjectClass(), s.getKind(), s.getIntent(), s);
}

private static ObjectClassComplexTypeDefinition determineObjectClassInternal(
RefinedResourceSchema refinedSchema, QName objectclass, ShadowKindType kind, String intent, Object source) {

QName objectclass = null;
PrismProperty<QName> objectclassProperty = task.getExtensionProperty(ModelConstants.OBJECTCLASS_PROPERTY_NAME);
if (objectclassProperty != null) {
objectclass = objectclassProperty.getValue().getValue();
}

ShadowKindType kind = null;
PrismProperty<ShadowKindType> kindProperty = task.getExtensionProperty(ModelConstants.KIND_PROPERTY_NAME);
if (kindProperty != null) {
kind = kindProperty.getValue().getValue();
}

String intent = null;
PrismProperty<String> intentProperty = task.getExtensionProperty(ModelConstants.INTENT_PROPERTY_NAME);
if (intentProperty != null) {
intent = intentProperty.getValue().getValue();
}

if (kind == null && intent == null && objectclass != null) {
// Return generic object class definition from resource schema. No kind/intent means that we want
// to process all kinds and intents in the object class.
Expand All @@ -320,7 +331,7 @@ public static ObjectClassComplexTypeDefinition determineObjectClass(RefinedResou
new Object[]{refinedObjectClassDefinition, objectclass});
} else {
if (LOGGER.isTraceEnabled()) {
LOGGER.debug("No kind or objectclass specified in the task {}, using default values", task);
LOGGER.debug("No kind or objectclass specified in {}, using default values", source);
}
refinedObjectClassDefinition = refinedSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String)null);
LOGGER.trace("Determined refined object class {} by using default ACCOUNT kind",
Expand Down
Expand Up @@ -104,9 +104,9 @@ public void postProcessEntitlementsRead(ConnectorInstance connector, ResourceTyp
PrismContainer<ShadowAssociationType> associationContainer = associationDef.instantiate();

for (RefinedAssociationDefinition assocDefType: entitlementAssociationDefs) {
RefinedObjectClassDefinition entitlementDef = refinedSchema.getRefinedDefinition(ShadowKindType.ENTITLEMENT, assocDefType.getIntent());
RefinedObjectClassDefinition entitlementDef = refinedSchema.getRefinedDefinition(ShadowKindType.ENTITLEMENT, assocDefType.getIntents());
if (entitlementDef == null) {
throw new SchemaException("No definition for entitlement intent '"+assocDefType.getIntent()+"' in "+resourceType);
throw new SchemaException("No definition for entitlement intent(s) '"+assocDefType.getIntents()+"' in "+resourceType);
}
ResourceObjectAssociationDirectionType direction = assocDefType.getResourceObjectAssociationType().getDirection();
if (direction == ResourceObjectAssociationDirectionType.SUBJECT_TO_OBJECT) {
Expand Down Expand Up @@ -361,9 +361,9 @@ public <T> void collectEntitlementsAsObjectOperationDelete(ConnectorInstance con
if (associationName == null) {
throw new SchemaException("No name in entitlement association "+assocDefType+" in "+resourceType);
}
final RefinedObjectClassDefinition entitlementOcDef = refinedSchema.getRefinedDefinition(ShadowKindType.ENTITLEMENT, assocDefType.getIntent());
final RefinedObjectClassDefinition entitlementOcDef = refinedSchema.getRefinedDefinition(ShadowKindType.ENTITLEMENT, assocDefType.getIntents());
if (entitlementOcDef == null) {
throw new SchemaException("No definition for entitlement intent '"+assocDefType.getIntent()+"' defined in entitlement association "+associationName+" in "+resourceType);
throw new SchemaException("No definition for entitlement intent(s) '"+assocDefType.getIntents()+"' defined in entitlement association "+associationName+" in "+resourceType);
}

final QName assocAttrName = assocDefType.getResourceObjectAssociationType().getAssociationAttribute();
Expand Down Expand Up @@ -552,13 +552,13 @@ private <T> void collectEntitlementAsObjectOperation(Map<ResourceObjectDiscrimin
return;
}

String entitlementIntent = assocDefType.getIntent();
if (entitlementIntent == null) {
Collection<String> entitlementIntents = assocDefType.getIntents();
if (entitlementIntents == null || entitlementIntents.isEmpty()) {
throw new SchemaException("No entitlement intent specified in association "+associationCVal+" in "+resource);
}
RefinedObjectClassDefinition entitlementOcDef = rSchema.getRefinedDefinition(ShadowKindType.ENTITLEMENT, entitlementIntent);
RefinedObjectClassDefinition entitlementOcDef = rSchema.getRefinedDefinition(ShadowKindType.ENTITLEMENT, entitlementIntents);
if (entitlementOcDef == null) {
throw new SchemaException("No definition of entitlement intent '"+entitlementIntent+"' specified in association "+associationCVal+" in "+resource);
throw new SchemaException("No definition of entitlement intent(s) '"+entitlementIntents+"' specified in association "+associationCVal+" in "+resource);
}

QName assocAttrName = assocDefType.getResourceObjectAssociationType().getAssociationAttribute();
Expand All @@ -568,7 +568,7 @@ private <T> void collectEntitlementAsObjectOperation(Map<ResourceObjectDiscrimin

RefinedAttributeDefinition assocAttrDef = entitlementOcDef.findAttributeDefinition(assocAttrName);
if (assocAttrDef == null) {
throw new SchemaException("Association attribute '"+assocAttrName+"'defined in entitlement association was not found in entitlement intent '"+entitlementIntent+"' in schema for "+resource);
throw new SchemaException("Association attribute '"+assocAttrName+"'defined in entitlement association was not found in entitlement intent(s) '"+entitlementIntents+"' in schema for "+resource);
}

ResourceAttributeContainer identifiersContainer =
Expand Down
Expand Up @@ -1604,8 +1604,7 @@ private PrismObject<ShadowType> completeShadow(ConnectorInstance connector, Pris
ShadowAssociationType shadowAssociationType = associationCVal.asContainerable();
QName associationName = shadowAssociationType.getName();
RefinedAssociationDefinition rEntitlementAssociation = objectClassDefinition.findEntitlementAssociation(associationName);
String entitlementIntent = rEntitlementAssociation.getIntent();
RefinedObjectClassDefinition entitlementObjectClassDef = refinedSchema.getRefinedDefinition(ShadowKindType.ENTITLEMENT, entitlementIntent);
RefinedObjectClassDefinition entitlementObjectClassDef = refinedSchema.getRefinedDefinition(ShadowKindType.ENTITLEMENT, rEntitlementAssociation.getIntents());

PrismObject<ShadowType> entitlementShadow = (PrismObject<ShadowType>) identifierContainer.getUserData(ResourceObjectConverter.FULL_SHADOW_KEY);
if (entitlementShadow == null) {
Expand Down
Expand Up @@ -19,6 +19,7 @@
import com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException;
import com.evolveum.midpoint.repo.sql.util.MidPointConnectionCustomizer;
import com.evolveum.midpoint.repo.sql.util.MidPointMySQLDialect;
import com.evolveum.midpoint.repo.sql.util.MidPointPostgreSQLDialect;
import com.evolveum.midpoint.repo.sql.util.UnicodeSQLServer2008Dialect;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand Down Expand Up @@ -488,7 +489,8 @@ public boolean isUsingMySQL() {

public boolean isUsingPostgreSQL() {
return isUsingDialect(PostgresPlusDialect.class)
|| isUsingDialect(PostgreSQLDialect.class);
|| isUsingDialect(PostgreSQLDialect.class)
|| isUsingDialect(MidPointPostgreSQLDialect.class);
}

public boolean isUsingSQLServer() {
Expand Down
Expand Up @@ -30,6 +30,7 @@ public class AuthorizationConstants {
public static final String NS_AUTHORIZATION = NS_SECURITY_PREFIX + "authorization-3";
public static final String NS_AUTHORIZATION_UI = NS_SECURITY_PREFIX + "authorization-ui-3";
public static final String NS_AUTHORIZATION_WS = NS_SECURITY_PREFIX + "authorization-ws-3";
public static final String NS_AUTHORIZATION_REST = NS_SECURITY_PREFIX + "authorization-rest-3";
public static final String NS_AUTHORIZATION_MODEL = NS_SECURITY_PREFIX + "authorization-model-3";

public static final QName AUTZ_ALL_QNAME = new QName(NS_AUTHORIZATION, "all");
Expand Down

0 comments on commit 3810320

Please sign in to comment.