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