Search in sources :

Example 16 with ProtectedStringType

use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.

the class MappingTestEvaluator method assertProtectedString.

public void assertProtectedString(String desc, Collection<PrismPropertyValue<ProtectedStringType>> set, String expected) throws EncryptionException {
    assertEquals("Unexpected size of " + desc + ": " + set, 1, set.size());
    PrismPropertyValue<ProtectedStringType> pval = set.iterator().next();
    ProtectedStringType ps = pval.getValue();
    String zeroString = protector.decryptString(ps);
    assertEquals("Unexpected value in " + desc + ": " + set, expected, zeroString);
}
Also used : ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 17 with ProtectedStringType

use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.

the class XsdTypeConverterTest method testAccountMarshall.

// ... as it uses JAXB that is no more supported
@Deprecated
@Test(enabled = false)
public void testAccountMarshall() throws JAXBException, SchemaException, IOException {
    System.out.println("===[ testAccountMarshall ]===");
    ShadowType shadow = PrismTestUtil.parseObjectable(new File("src/test/resources/converter/account-jack.xml"), ShadowType.class);
    System.out.println("Object: " + shadow);
    ProtectedStringType ps = new ProtectedStringType();
    ps.setClearValue("foo");
    JAXBElement<ProtectedStringType> pse = new JAXBElement<ProtectedStringType>(FOO_QNAME, ProtectedStringType.class, ps);
    shadow.getAttributes().getAny().add(pse);
    shadow.getAttributes().getAny().add(XmlTypeConverter.toXsdElement(42, BAR_QNAME, null, true));
    Document doc = DOMUtil.getDocument();
    JAXBElement<ShadowType> accountElement = new JAXBElement<ShadowType>(ObjectTypes.SHADOW.getQName(), ShadowType.class, shadow);
    JaxbTestUtil.getInstance().marshalElementToDom(accountElement, doc);
    System.out.println("marshalled shadow: " + DOMUtil.serializeDOMToString(doc));
    Element rootElement = DOMUtil.getFirstChildElement(doc);
    System.out.println("root element: " + rootElement);
    Element attrElement = (Element) rootElement.getElementsByTagNameNS(SchemaConstants.NS_C, "attributes").item(0);
    System.out.println("attrElement element: " + attrElement);
    Element fooElement = (Element) attrElement.getElementsByTagNameNS(FOO_QNAME.getNamespaceURI(), FOO_QNAME.getLocalPart()).item(0);
    System.out.println("fooElement element: " + fooElement);
    Element clearValue = DOMUtil.getFirstChildElement(fooElement);
    assertEquals("foo", clearValue.getTextContent());
    Element barElement = (Element) attrElement.getElementsByTagNameNS(BAR_QNAME.getNamespaceURI(), BAR_QNAME.getLocalPart()).item(0);
    System.out.println("barElement element: " + barElement);
    assertEquals(DOMUtil.XSD_INT, DOMUtil.resolveXsiType(barElement));
    assertEquals("42", barElement.getTextContent());
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) JAXBElement(javax.xml.bind.JAXBElement) Document(org.w3c.dom.Document) File(java.io.File) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) Test(org.testng.annotations.Test)

Example 18 with ProtectedStringType

use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.

the class TestResourceSchema method assertResourceSchema.

private void assertResourceSchema(ResourceSchema unSchema) {
    ObjectClassComplexTypeDefinition objectClassDef = unSchema.findObjectClassDefinition(new QName(SCHEMA_NAMESPACE, "AccountObjectClass"));
    assertEquals(new QName(SCHEMA_NAMESPACE, "AccountObjectClass"), objectClassDef.getTypeName());
    assertEquals("AccountObjectClass class not an account", ShadowKindType.ACCOUNT, objectClassDef.getKind());
    assertTrue("AccountObjectClass class not a DEFAULT account", objectClassDef.isDefaultInAKind());
    PrismPropertyDefinition<String> loginDef = objectClassDef.findPropertyDefinition(new QName(SCHEMA_NAMESPACE, "login"));
    assertEquals(new QName(SCHEMA_NAMESPACE, "login"), loginDef.getName());
    assertEquals(DOMUtil.XSD_STRING, loginDef.getTypeName());
    PrismPropertyDefinition<ProtectedStringType> passwdDef = objectClassDef.findPropertyDefinition(new QName(SCHEMA_NAMESPACE, "password"));
    assertEquals(new QName(SCHEMA_NAMESPACE, "password"), passwdDef.getName());
    assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());
//		PrismContainerDefinition<CredentialsType> credDef = objectClassDef.findContainerDefinition(new QName(SchemaConstants.NS_C,"credentials"));
//		assertEquals(new QName(SchemaConstants.NS_C,"credentials"), credDef.getName());
//		assertEquals(new QName(SchemaConstants.NS_C,"CredentialsType"), credDef.getTypeName());
}
Also used : QName(javax.xml.namespace.QName) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 19 with ProtectedStringType

use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.

the class XsdTypeConverterTest method testConvertFromProtectedString.

@Test(enabled = false)
public void testConvertFromProtectedString() throws SchemaException {
    Document document = DOMUtil.parseDocument("<password xmlns=\"" + FOO_NAMESPACE + "\" " + "xmlns:c=\"http://midpoint.evolveum.com/xml/ns/public/common/common-3\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xsi:type=\"c:ProtectedStringType\">" + "<c:clearValue>3lizab3th</c:clearValue></password>");
    Element element = DOMUtil.getFirstChildElement(document);
    Object value = XmlTypeConverter.toJavaValue(element);
    System.out.println("XML -> ProtectedStringType: " + value);
    assertNotNull(value);
    assertTrue(value instanceof ProtectedStringType);
    assertEquals("3lizab3th", ((ProtectedStringType) value).getClearValue());
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) Test(org.testng.annotations.Test)

Example 20 with ProtectedStringType

use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.

the class WebComponentUtil method encryptCredentials.

public static void encryptCredentials(PrismObject object, boolean encrypt, MidPointApplication app) {
    PrismContainer password = object.findContainer(new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD));
    if (password == null) {
        return;
    }
    PrismProperty protectedStringProperty = password.findProperty(PasswordType.F_VALUE);
    if (protectedStringProperty == null || protectedStringProperty.getRealValue(ProtectedStringType.class) == null) {
        return;
    }
    ProtectedStringType string = (ProtectedStringType) protectedStringProperty.getRealValue(ProtectedStringType.class);
    encryptProtectedString(string, encrypt, app);
}
Also used : PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)120 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)48 Test (org.testng.annotations.Test)48 Task (com.evolveum.midpoint.task.api.Task)39 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)24 QName (javax.xml.namespace.QName)20 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)18 PasswordType (com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType)18 CredentialsType (com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)11 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)10 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)9 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)9 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)9 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)9 Document (org.w3c.dom.Document)8 ArrayList (java.util.ArrayList)7 Entry (org.apache.directory.api.ldap.model.entry.Entry)7