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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations