/** * Finds a specific attribute in the resource object by definition. * * Returns null if nothing is found. * * @param attributeDefinition * attribute definition to find. * @return found attribute or null */ @Override public <X> ResourceAttribute<X> findAttribute(ResourceAttributeDefinition attributeDefinition) { return (ResourceAttribute<X>) getValue().findProperty(attributeDefinition); }
public static <T> T getPropertyValue(PrismContainerValue container, QName name, Class<T> clazz) { Validate.notNull(container, "Container must not be null."); Validate.notNull(name, "QName must not be null."); Validate.notNull(clazz, "Class type must not be null."); PrismProperty property = container.findProperty(ItemName.fromQName(name)); return getPropertyValue(property, clazz); }
private <T> PrismProperty<T> findAttribute(QName attrName) { return getAttributes().findProperty(ItemName.fromQName(attrName)); }
private <T> PrismProperty<T> findProperty(QName attrName) { return getPrismValue().findProperty(ItemName.fromQName(attrName)); }
public static <T> List<T> getPropertyValues(PrismContainerValue<?> container, QName name, Class<T> clazz) { Validate.notNull(container, "Container must not be null."); Validate.notNull(name, "QName must not be null."); Validate.notNull(clazz, "Class type must not be null."); PrismProperty<?> property; try { property = container.findProperty(ItemName.fromQName(name)); if (property == null) { property = container.createDetachedSubItem(name, PrismPropertyImpl.class, null, container.isImmutable()); } } catch (SchemaException e) { // This should not happen. Code generator and compiler should take care of that. throw new IllegalStateException("Internal schema error: "+e.getMessage(),e); } return new PropertyArrayList<>(property, container); }
public static <T> void assertPropertyValue(PrismContainerValue<?> containerValue, ItemPath propPath, T... realPropValues) { PrismProperty<T> property = containerValue.findProperty(propPath); assertNotNull("Property " + propPath + " not found in " + containerValue.getParent(), property); assertPropertyValueDesc(property, containerValue.getParent().toString(), realPropValues); }
public static Element findXsdElement(PrismContainerValue<XmlSchemaType> xmlSchemaContainerValue) { PrismProperty<SchemaDefinitionType> definitionProperty = xmlSchemaContainerValue.findProperty(XmlSchemaType.F_DEFINITION); if (definitionProperty == null) { return null; } SchemaDefinitionType schemaDefinition = definitionProperty.getValue().getValue(); if (schemaDefinition == null) { return null; } return schemaDefinition.getSchema(); // List<Element> schemaElements = DOMUtil.listChildElements(definitionElement); // for (Element e : schemaElements) { // if (QNameUtil.compareQName(DOMUtil.XSD_SCHEMA_ELEMENT, e)) { // DOMUtil.fixNamespaceDeclarations(e); // return e; // } // } // return null; }
public static String retrieveUsualNamespacePrefix(ConnectorType connectorType) { if (connectorType.getExtension() != null) { PrismContainerValue<ExtensionType> ext = connectorType.getExtension().asPrismContainerValue(); PrismProperty<String> prefixProp = ext.findProperty(SchemaConstants.ICF_CONNECTOR_USUAL_NAMESPACE_PREFIX); if (prefixProp != null) { return prefixProp.getRealValue(); } } return null; }
protected void validateCredentialContainerValues(PrismContainerValue<R> cVal) throws PolicyViolationException, SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException { PrismProperty<ProtectedStringType> credentialValueProperty = cVal.findProperty(getCredentialRelativeValuePath()); if (credentialValueProperty != null) { for (PrismPropertyValue<ProtectedStringType> credentialValuePropertyValue : credentialValueProperty.getValues()) { validateProtectedStringValue(credentialValuePropertyValue.getValue()); } } }
public static void removeTriggersForWorkItem(Task wfTask, String workItemId, OperationResult result) { List<PrismContainerValue<TriggerType>> toDelete = new ArrayList<>(); for (TriggerType triggerType : wfTask.getTaskPrismObject().asObjectable().getTrigger()) { if (WfTimedActionTriggerHandler.HANDLER_URI.equals(triggerType.getHandlerUri())) { PrismProperty workItemIdProperty = triggerType.getExtension().asPrismContainerValue() .findProperty(SchemaConstants.MODEL_EXTENSION_WORK_ITEM_ID); if (workItemIdProperty != null && workItemId.equals(workItemIdProperty.getRealValue())) { toDelete.add(triggerType.clone().asPrismContainerValue()); } } } removeSelectedTriggers(wfTask, toDelete, result); }
public static <T> void assertPropertyValueMatch(PrismContainerValue<?> containerValue, ItemPath propQName, MatchingRule<T> matchingRule, T... realPropValues) throws SchemaException { PrismProperty<T> property = containerValue.findProperty(propQName); assertNotNull("Property " + propQName + " not found in " + containerValue.getParent(), property); assertSame("Wrong parent for property " + property, containerValue, property.getParent()); assertPropertyValueDesc(property, matchingRule, containerValue.getParent().toString(), realPropValues); }
private void fillInAssociationNames(Map<QName, DeltaSetTriple<ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>,PrismContainerDefinition<ShadowAssociationType>>>> squeezedAssociations) throws SchemaException { PrismPropertyDefinition<QName> nameDefinition = prismContext.getSchemaRegistry() .findContainerDefinitionByCompileTimeClass(ShadowAssociationType.class) .findPropertyDefinition(ShadowAssociationType.F_NAME); for (Entry<QName, DeltaSetTriple<ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>,PrismContainerDefinition<ShadowAssociationType>>>> entry : squeezedAssociations.entrySet()) { DeltaSetTriple<ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>,PrismContainerDefinition<ShadowAssociationType>>> deltaSetTriple = entry.getValue(); for (ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>,PrismContainerDefinition<ShadowAssociationType>> ivwo : deltaSetTriple.getAllValues()) { PrismContainerValue<ShadowAssociationType> value = ivwo.getItemValue(); if (value != null && value.findProperty(ShadowAssociationType.F_NAME) == null) { // just for safety PrismProperty<QName> nameProperty = value.createProperty(nameDefinition); nameProperty.setRealValue(entry.getKey()); } } } LOGGER.trace("Names for squeezed associations filled-in."); }
@Test public void testFindAssignment() throws SchemaException, SAXException, IOException { final String TEST_NAME = "testFindAssignment"; System.out.println("===[ "+TEST_NAME+" ]==="); // GIVEN ItemPath path = UserType.F_ASSIGNMENT; // WHEN PrismContainer<AssignmentType> container = findUserContainer(path); // THEN PrismContainerValue<AssignmentType> value2 = container.getValue(USER_ASSIGNMENT_2_ID); assertEquals("Wrong value2 description (path="+path+")", "Assignment 2", value2.findProperty(AssignmentType.F_DESCRIPTION).getRealValue()); }
private void checkOrFixActivationItem(ShadowCheckResult checkResult, PrismObject<ShadowType> shadow, PrismContainerValue<ActivationType> activation, ItemName itemName) { PrismProperty property = activation.findProperty(itemName); if (property == null || property.isEmpty()) { return; } checkResult.recordWarning(ShadowStatistics.EXTRA_ACTIVATION_DATA, "Unexpected activation item: " + property); if (fixExtraData) { PropertyDelta delta = prismContext.deltaFactory().property().createReplaceEmptyDelta(shadow.getDefinition(), ItemPath.create(ShadowType.F_ACTIVATION, itemName)); checkResult.addFixDelta(delta, ShadowStatistics.EXTRA_ACTIVATION_DATA); } }
protected void assertEntitlementGroup(PrismObject<ShadowType> account, String entitlementOid) { ShadowAssociationType associationType = IntegrationTestTools.assertAssociation(account, ASSOCIATION_GROUP_NAME, entitlementOid); PrismContainerValue identifiersCVal = associationType.getIdentifiers().asPrismContainerValue(); PrismProperty<String> dnProp = identifiersCVal.findProperty(getSecondaryIdentifierQName()); assertNotNull("No DN identifier in group association in "+account+", got "+identifiersCVal, dnProp); }
public ShadowAttributesAsserter<R> assertAttributes(QName... expectedAttributes) { for (QName expectedAttribute: expectedAttributes) { PrismProperty<Object> attr = getAttributes().findProperty(ItemName.fromQName(expectedAttribute)); if (attr == null) { fail("Expected attribute "+expectedAttribute+" in "+desc()+" but there was none. Attributes present: "+presentAttributeNames()); } } for (PrismProperty<?> existingAttr : getAttributes().getProperties()) { if (!QNameUtil.contains(expectedAttributes, existingAttr.getElementName())) { fail("Unexpected attribute "+existingAttr.getElementName()+" in "+desc()+". Expected attributes: "+QNameUtil.prettyPrint(expectedAttributes)); } } return this; }
@Override protected void checkAccountWill(PrismObject<ShadowType> shadow, OperationResult result, XMLGregorianCalendar startTs, XMLGregorianCalendar endTs) throws SchemaException, EncryptionException { super.checkAccountWill(shadow, result, startTs, endTs); CredentialsType credentials = shadow.asObjectable().getCredentials(); assertNotNull("No credentials in "+shadow, credentials); PasswordType password = credentials.getPassword(); assertNotNull("No password in "+shadow, password); PrismContainerValue<PasswordType> passwordContainerValue = password.asPrismContainerValue(); PrismProperty<ProtectedStringType> valueProperty = passwordContainerValue.findProperty(PasswordType.F_VALUE); assertTrue("Unexpected password value in "+shadow+": "+valueProperty, valueProperty.getValues().isEmpty()); assertTrue("No incompleteness in password value in "+shadow+": "+valueProperty, valueProperty.isIncomplete()); }
@Override protected void assertShadowPassword(ShadowType provisioningShadow) { CredentialsType credentials = provisioningShadow.getCredentials(); if (credentials == null) { return; } PasswordType passwordType = credentials.getPassword(); if (passwordType == null) { return; } ProtectedStringType passwordValue = passwordType.getValue(); assertNull("Unexpected password value in "+provisioningShadow+": "+passwordValue, passwordValue); PrismContainerValue<PasswordType> passwordContainer = passwordType.asPrismContainerValue(); PrismProperty<ProtectedStringType> valueProp = passwordContainer.findProperty(PasswordType.F_VALUE); assertTrue("Incomplete flag is NOT set for password value in "+provisioningShadow, valueProp.isIncomplete()); } }
@Override protected void assertShadowPassword(ShadowType provisioningShadow) throws Exception { CredentialsType credentials = provisioningShadow.getCredentials(); if (credentials == null) { return; } PasswordType passwordType = credentials.getPassword(); if (passwordType == null) { return; } ProtectedStringType passwordValue = passwordType.getValue(); assertNotNull("Missing password value in "+provisioningShadow, passwordValue); assertFalse("Empty password value in "+provisioningShadow, passwordValue.isEmpty()); String clearPassword = protector.decryptString(passwordValue); display("Clear password of "+provisioningShadow+": "+clearPassword); PrismContainerValue<PasswordType> passwordContainer = passwordType.asPrismContainerValue(); PrismProperty<ProtectedStringType> valueProp = passwordContainer.findProperty(PasswordType.F_VALUE); assertFalse("Incomplete password value in "+provisioningShadow, valueProp.isIncomplete()); } }
@Test public void test021ModifyInducement() throws Exception { //given ObjectDelta<RoleType> delta = deltaFor(RoleType.class) .item(RoleType.F_INDUCEMENT, 5L, AssignmentType.F_TARGET_REF) .replace(new ObjectReferenceType().oid(NEW_INDUCEMENT_5_TARGET_OID).type(RoleType.COMPLEX_TYPE)) .asObjectDeltaCast(ROLE_OID); OperationResult result = new OperationResult("modify inducement"); // WHEN repositoryService.modifyObject(RoleType.class, delta.getOid(), delta.getModifications(), result); // THEN assertSuccess(result); PrismObject<RoleType> repoRole = getObject(RoleType.class, ROLE_OID); PrismContainer<AssignmentType> inducement = repoRole.findContainer(RoleType.F_INDUCEMENT); assertNotNull(inducement); assertEquals(3, inducement.getValues().size()); PrismContainer<AssignmentType> assignment = repoRole.findContainer(AbstractRoleType.F_ASSIGNMENT); assertNotNull(assignment); assertEquals(2, assignment.getValues().size()); PrismContainerValue<AssignmentType> value5 = inducement.getValue(5L); PrismReference targetRef = value5.findReference(AssignmentType.F_TARGET_REF); assertNotNull(targetRef); assertEquals(1, targetRef.getValues().size()); PrismReferenceValue refValue = targetRef.getValue(); assertEquals(NEW_INDUCEMENT_5_TARGET_OID, refValue.getOid()); assertEquals(RoleType.COMPLEX_TYPE, refValue.getTargetType()); PrismProperty accConstruction = value5.findProperty(AssignmentType.F_CONSTRUCTION); AssertJUnit.assertNull(accConstruction); }