use of com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType in project midpoint by Evolveum.
the class SchemaTransformer method applyObjectTemplateItem.
private <IV extends PrismValue, ID extends ItemDefinition> void applyObjectTemplateItem(ID itemDef, ObjectTemplateItemDefinitionType templateItemDefType, String desc) throws SchemaException {
if (itemDef == null) {
throw new SchemaException("No definition for " + desc);
}
String displayName = templateItemDefType.getDisplayName();
if (displayName != null) {
((ItemDefinitionImpl) itemDef).setDisplayName(displayName);
}
Integer displayOrder = templateItemDefType.getDisplayOrder();
if (displayOrder != null) {
((ItemDefinitionImpl) itemDef).setDisplayOrder(displayOrder);
}
Boolean emphasized = templateItemDefType.isEmphasized();
if (emphasized != null) {
((ItemDefinitionImpl) itemDef).setEmphasized(emphasized);
}
List<PropertyLimitationsType> limitations = templateItemDefType.getLimitations();
if (limitations != null) {
PropertyLimitationsType limitationsType = MiscSchemaUtil.getLimitationsType(limitations, LayerType.PRESENTATION);
if (limitationsType != null) {
if (limitationsType.getMinOccurs() != null) {
((ItemDefinitionImpl) itemDef).setMinOccurs(XsdTypeMapper.multiplicityToInteger(limitationsType.getMinOccurs()));
}
if (limitationsType.getMaxOccurs() != null) {
((ItemDefinitionImpl) itemDef).setMaxOccurs(XsdTypeMapper.multiplicityToInteger(limitationsType.getMaxOccurs()));
}
if (limitationsType.isIgnore() != null) {
((ItemDefinitionImpl) itemDef).setIgnored(limitationsType.isIgnore());
}
PropertyAccessType accessType = limitationsType.getAccess();
if (accessType != null) {
if (accessType.isAdd() != null) {
((ItemDefinitionImpl) itemDef).setCanAdd(accessType.isAdd());
}
if (accessType.isModify() != null) {
((ItemDefinitionImpl) itemDef).setCanModify(accessType.isModify());
}
if (accessType.isRead() != null) {
((ItemDefinitionImpl) itemDef).setCanRead(accessType.isRead());
}
}
}
}
ObjectReferenceType valueEnumerationRef = templateItemDefType.getValueEnumerationRef();
if (valueEnumerationRef != null) {
PrismReferenceValue valueEnumerationRVal = MiscSchemaUtil.objectReferenceTypeToReferenceValue(valueEnumerationRef);
((ItemDefinitionImpl) itemDef).setValueEnumerationRef(valueEnumerationRVal);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType in project midpoint by Evolveum.
the class RefinedAttributeDefinitionImpl method isIgnored.
static boolean isIgnored(ResourceAttributeDefinitionType attrDefType) throws SchemaException {
List<PropertyLimitationsType> limitations = attrDefType.getLimitations();
if (limitations == null) {
return false;
}
PropertyLimitationsType limitationsType = MiscSchemaUtil.getLimitationsType(limitations, DEFAULT_LAYER);
if (limitationsType == null) {
return false;
}
if (limitationsType.isIgnore() == null) {
return false;
}
return limitationsType.isIgnore();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType in project midpoint by Evolveum.
the class ValuePolicyProcessor method testCheckExpression.
private List<StringLimitationResult> testCheckExpression(String newPassword, LimitationsType lims, ExpressionProfile expressionProfile, ObjectBasedValuePolicyOriginResolver<?> originResolver, String shortDesc, Task task, OperationResult result, List<LocalizableMessage> messages) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
List<StringLimitationResult> limitations = new ArrayList<>();
for (CheckExpressionType checkExpression : lims.getCheckExpression()) {
ExpressionType expressionType = checkExpression.getExpression();
if (expressionType == null) {
continue;
}
StringLimitationResult limitation = new StringLimitationResult();
PolyStringType name = null;
if (checkExpression.getDisplay() != null) {
name = checkExpression.getDisplay().getLabel();
limitation.setHelp(checkExpression.getDisplay().getHelp());
}
if (name == null) {
name = new PolyStringType("Check expression");
PolyStringTranslationType translation = new PolyStringTranslationType();
translation.setKey("ValuePolicy.checkExpression");
name.setTranslation(translation);
}
limitation.setName(name);
limitation.setSuccess(true);
if (!checkExpression(newPassword, expressionType, expressionProfile, originResolver, shortDesc, task, result)) {
LocalizableMessage msg;
if (checkExpression.getLocalizableFailureMessage() != null) {
msg = LocalizationUtil.toLocalizableMessage(checkExpression.getLocalizableFailureMessage());
} else if (checkExpression.getFailureMessage() != null) {
msg = LocalizableMessageBuilder.buildFallbackMessage(checkExpression.getFailureMessage());
} else {
msg = LocalizableMessageBuilder.buildKey("ValuePolicy.checkExpressionFailed");
}
result.addSubresult(new OperationResult("Check expression", OperationResultStatus.FATAL_ERROR, msg));
messages.add(msg);
limitation.setSuccess(false);
}
limitations.add(limitation);
}
return limitations;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType in project midpoint by Evolveum.
the class ValuePolicyProcessor method generate.
public String generate(ItemPath path, ValuePolicyType policy, int defaultLength, boolean generateMinimalSize, ObjectBasedValuePolicyOriginResolver<?> originResolver, String shortDesc, Task task, OperationResult parentResult) throws ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
Context ctx = new Context(path != null ? path : SchemaConstants.PATH_PASSWORD_VALUE);
OperationResult result = parentResult.createSubresult(OP_GENERATE);
if (policy == null) {
// lets create some default policy
policy = new ValuePolicyType().stringPolicy(new StringPolicyType().limitations(new LimitationsType().maxLength(defaultLength).minLength(defaultLength)));
}
StringPolicyType stringPolicy = policy.getStringPolicy();
int maxAttempts = DEFAULT_MAX_ATTEMPTS;
if (stringPolicy.getLimitations() != null && stringPolicy.getLimitations().getMaxAttempts() != null) {
maxAttempts = stringPolicy.getLimitations().getMaxAttempts();
}
if (maxAttempts < 1) {
ExpressionEvaluationException e = new ExpressionEvaluationException("Illegal number of maximum value generation attempts: " + maxAttempts);
result.recordFatalError(e);
throw e;
}
String generatedValue;
int attempt = 1;
for (; ; ) {
generatedValue = generateAttempt(policy, defaultLength, generateMinimalSize, ctx, result);
if (result.isError()) {
throw new ExpressionEvaluationException(result.getMessage());
}
// TODO: this needs to be determined from ValuePolicyType archetype
ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
if (checkAttempt(generatedValue, policy, expressionProfile, originResolver, shortDesc, task, result)) {
break;
}
LOGGER.trace("Generator attempt {}: check failed", attempt);
if (attempt == maxAttempts) {
ExpressionEvaluationException e = new ExpressionEvaluationException("Unable to generate value, maximum number of attempts (" + maxAttempts + ") exceeded");
result.recordFatalError(e);
throw e;
}
attempt++;
}
return generatedValue;
}
Aggregations