Search in sources :

Example 11 with ProtectedStringType

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

the class PageSelfRegistration method createPassword.

private PasswordType createPassword() {
    PasswordType password = new PasswordType();
    ProtectedStringType protectedString = new ProtectedStringType();
    protectedString.setClearValue(getPassword());
    password.setValue(protectedString);
    return password;
}
Also used : PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 12 with ProtectedStringType

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

the class TestProtector method testProtectorEncryptionRoundTrip.

@Test
public void testProtectorEncryptionRoundTrip() throws Exception {
    String value = "someValue";
    Protector protector256 = PrismInternalTestUtil.createProtector(XMLCipher.AES_256);
    Protector protector128 = PrismInternalTestUtil.createProtector(XMLCipher.AES_128);
    ProtectedStringType pdt = new ProtectedStringType();
    pdt.setClearValue(value);
    assertFalse(pdt.isEmpty());
    assertFalse(pdt.isHashed());
    assertFalse(pdt.isEncrypted());
    // WHEN
    protector256.encrypt(pdt);
    // THEN
    assertFalse(pdt.isEmpty());
    assertTrue(pdt.isEncrypted());
    assertFalse(pdt.isHashed());
    assertNull(pdt.getClearValue());
    // WHEN
    protector128.decrypt(pdt);
    // THEN
    assertFalse(pdt.isEmpty());
    assertFalse(pdt.isEncrypted());
    assertFalse(pdt.isHashed());
    AssertJUnit.assertEquals(value, pdt.getClearValue());
    // WHEN
    ProtectedStringType pstEnc = protector256.encryptString(value);
    // THEN
    assertFalse(pstEnc.isEmpty());
    assertTrue(pstEnc.isEncrypted());
    assertFalse(pstEnc.isHashed());
    // WHEN
    String clear = protector256.decryptString(pstEnc);
    assertNotNull(clear);
    // THEN
    AssertJUnit.assertEquals(value, clear);
    // WHEN
    boolean compare1 = protector256.compare(pdt, pstEnc);
    // THEN
    assertTrue("compare1 failed", compare1);
    // WHEN
    boolean compare2 = protector256.compare(pstEnc, pdt);
    // THEN
    assertTrue("compare2 failed", compare2);
    ProtectedStringType wrongPst = new ProtectedStringType();
    wrongPst.setClearValue("nonono This is not it");
    // WHEN
    boolean compare5 = protector256.compare(pdt, wrongPst);
    // THEN
    assertFalse("compare5 unexpected success", compare5);
    // WHEN
    boolean compare6 = protector256.compare(wrongPst, pdt);
    // THEN
    assertFalse("compare6 unexpected success", compare6);
}
Also used : ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) Test(org.testng.annotations.Test)

Example 13 with ProtectedStringType

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

the class TestProtectedString method testParseProtectedStringEncrypted.

@Test
public void testParseProtectedStringEncrypted() throws Exception {
    final String TEST_NAME = "testParseProtectedStringEncrypted";
    displayTestTitle(TEST_NAME);
    // GIVEN
    Protector protector = PrismInternalTestUtil.createProtector(XMLCipher.AES_128);
    ProtectedStringType protectedStringType = protector.encryptString("salalala");
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN
    MapXNode protectedStringTypeXNode = ((PrismContextImpl) prismContext).getBeanMarshaller().marshalProtectedDataType(protectedStringType, null);
    System.out.println("Protected string type XNode: " + protectedStringTypeXNode.debugDump());
    // THEN
    ProtectedStringType unmarshalled = new ProtectedStringType();
    XNodeProcessorUtil.parseProtectedType(unmarshalled, protectedStringTypeXNode, prismContext, ParsingContext.createDefault());
    System.out.println("Unmarshalled value: " + unmarshalled);
    assertEquals("Unmarshalled value differs from the original", protectedStringType, unmarshalled);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) TestProtector(com.evolveum.midpoint.prism.crypto.TestProtector) Protector(com.evolveum.midpoint.prism.crypto.Protector) Test(org.testng.annotations.Test)

Example 14 with ProtectedStringType

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

the class TestProtectedString method testParseProtectedStringHashed.

@Test
public void testParseProtectedStringHashed() throws Exception {
    final String TEST_NAME = "testParseProtectedStringHashed";
    displayTestTitle(TEST_NAME);
    // GIVEN
    ProtectedStringType protectedStringType = new ProtectedStringType();
    protectedStringType.setClearValue("blabla");
    Protector protector = PrismInternalTestUtil.createProtector(XMLCipher.AES_128);
    protector.hash(protectedStringType);
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN
    MapXNode protectedStringTypeXNode = ((PrismContextImpl) prismContext).getBeanMarshaller().marshalProtectedDataType(protectedStringType, null);
    System.out.println("Protected string type XNode: " + protectedStringTypeXNode.debugDump());
    // THEN
    ProtectedStringType unmarshalled = new ProtectedStringType();
    XNodeProcessorUtil.parseProtectedType(unmarshalled, protectedStringTypeXNode, prismContext, ParsingContext.createDefault());
    System.out.println("Unmarshalled value: " + unmarshalled);
    assertEquals("Unmarshalled value differs from the original", protectedStringType, unmarshalled);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) TestProtector(com.evolveum.midpoint.prism.crypto.TestProtector) Protector(com.evolveum.midpoint.prism.crypto.Protector) Test(org.testng.annotations.Test)

Example 15 with ProtectedStringType

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

the class MappingTestEvaluator method getUserOld.

protected PrismObject<UserType> getUserOld() throws SchemaException, EncryptionException, IOException {
    PrismObject<UserType> user = PrismTestUtil.parseObject(USER_OLD_FILE);
    ProtectedStringType passwordPs = user.asObjectable().getCredentials().getPassword().getValue();
    protector.encrypt(passwordPs);
    return user;
}
Also used : UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

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