use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class PageMyPasswordQuestions method updateQuestions.
private void updateQuestions(String useroid, AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_SAVE_QUESTIONS);
OperationResult result = new OperationResult(OPERATION_SAVE_QUESTIONS);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
SecurityQuestionAnswerType[] answerTypeList = new SecurityQuestionAnswerType[questionNumber];
try {
int listnum = 0;
for (Iterator iterator = pqPanels.iterator(); iterator.hasNext(); ) {
MyPasswordQuestionsPanel type = (MyPasswordQuestionsPanel) iterator.next();
SecurityQuestionAnswerType answerType = new SecurityQuestionAnswerType();
ProtectedStringType answer = new ProtectedStringType();
answer.setClearValue(((TextField<String>) type.get(MyPasswordQuestionsPanel.F_ANSWER)).getModelObject());
answerType.setQuestionAnswer(answer);
//used apache's unescapeHtml method for special chars like \'
String results = StringEscapeUtils.unescapeHtml((type.get(MyPasswordQuestionsPanel.F_QUESTION)).getDefaultModelObjectAsString());
answerType.setQuestionIdentifier(getQuestionIdentifierFromQuestion(results));
answerTypeList[listnum] = answerType;
listnum++;
}
//if(answerTypeList.length !=)
// fill in answerType data here
ItemPath path = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceContainer(UserType.class, useroid, path, getPrismContext(), answerTypeList);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
getModelService().executeChanges(deltas, null, task, result);
/*
System.out.println("getModel");
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
PasswordQuestionsDto dto = new PasswordQuestionsDto();
PrismObjectDefinition objDef =registry.findObjectDefinitionByCompileTimeClass(UserType.class);
Class<? extends ObjectType> type = UserType.class;
final ItemPath valuePath = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
SecurityQuestionAnswerType secQuesAnsType= new SecurityQuestionAnswerType();
ProtectedStringType protStrType= new ProtectedStringType();
protStrType.setClearValue("deneme");
secQuesAnsType.setQuestionAnswer(protStrType);
dto.setSecurityAnswers(new ArrayList<SecurityQuestionAnswerType>());
dto.getSecurityAnswers().add(secQuesAnsType);
PropertyDelta delta = PropertyDelta.createModificationReplaceProperty(valuePath, objDef, dto.getSecurityAnswers().get(0).getQuestionAnswer());
// PropertyDelta delta= PropertyDelta.createModifica
System.out.println("Update Questions3");
deltas.add(ObjectDelta.createModifyDelta(useroid, delta, type, getPrismContext()));
System.out.println("Update Questions4");
getModelService().executeChanges(deltas, null, createSimpleTask(OPERATION_SAVE_QUESTIONS), result);
System.out.println("Update Questions5");
*/
success(getString("message.success"));
target.add(getFeedbackPanel());
} catch (Exception ex) {
error(getString("message.error"));
target.add(getFeedbackPanel());
ex.printStackTrace();
}
}
use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class CryptoUtil method checkEncrypted.
private static <T extends ObjectType> void checkEncrypted(PrismPropertyValue<?> pval) {
Itemable item = pval.getParent();
if (item == null) {
return;
}
ItemDefinition itemDef = item.getDefinition();
if (itemDef == null || itemDef.getTypeName() == null) {
return;
}
if (itemDef.getTypeName().equals(ProtectedStringType.COMPLEX_TYPE)) {
QName propName = item.getElementName();
PrismPropertyValue<ProtectedStringType> psPval = (PrismPropertyValue<ProtectedStringType>) pval;
ProtectedStringType ps = psPval.getValue();
if (ps.getClearValue() != null) {
throw new IllegalStateException("Unencrypted value in field " + propName);
}
} else if (itemDef.getTypeName().equals(NotificationConfigurationType.COMPLEX_TYPE)) {
// this is really ugly hack needed because currently it is not possible to break NotificationConfigurationType into prism item [pm]
NotificationConfigurationType ncfg = ((PrismPropertyValue<NotificationConfigurationType>) pval).getValue();
if (ncfg.getMail() != null) {
for (MailServerConfigurationType mscfg : ncfg.getMail().getServer()) {
if (mscfg.getPassword() != null && mscfg.getPassword().getClearValue() != null) {
throw new IllegalStateException("Unencrypted value in mail server config password entry");
}
}
}
if (ncfg.getSms() != null) {
for (SmsConfigurationType smscfg : ncfg.getSms()) {
for (SmsGatewayConfigurationType gwcfg : smscfg.getGateway()) {
if (gwcfg.getPassword() != null && gwcfg.getPassword().getClearValue() != null) {
throw new IllegalStateException("Unencrypted value in SMS gateway config password entry");
}
}
}
}
}
}
use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class CryptoUtil method encryptValue.
private static <T extends ObjectType> void encryptValue(Protector protector, PrismPropertyValue<?> pval) throws EncryptionException {
Itemable item = pval.getParent();
if (item == null) {
return;
}
ItemDefinition itemDef = item.getDefinition();
if (itemDef == null || itemDef.getTypeName() == null) {
return;
}
if (itemDef.getTypeName().equals(ProtectedStringType.COMPLEX_TYPE)) {
QName propName = item.getElementName();
PrismPropertyValue<ProtectedStringType> psPval = (PrismPropertyValue<ProtectedStringType>) pval;
ProtectedStringType ps = psPval.getValue();
encryptProtectedStringType(protector, ps, propName.getLocalPart());
if (pval.getParent() == null) {
pval.setParent(item);
}
} else if (itemDef.getTypeName().equals(NotificationConfigurationType.COMPLEX_TYPE)) {
// this is really ugly hack needed because currently it is not possible to break NotificationConfigurationType into prism item [pm]
NotificationConfigurationType ncfg = ((PrismPropertyValue<NotificationConfigurationType>) pval).getValue();
if (ncfg.getMail() != null) {
for (MailServerConfigurationType mscfg : ncfg.getMail().getServer()) {
encryptProtectedStringType(protector, mscfg.getPassword(), "mail server password");
}
}
if (ncfg.getSms() != null) {
for (SmsConfigurationType smscfg : ncfg.getSms()) {
for (SmsGatewayConfigurationType gwcfg : smscfg.getGateway()) {
encryptProtectedStringType(protector, gwcfg.getPassword(), "sms gateway password");
}
}
}
}
}
use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class TestJaxbParsing method testParseUserFromJaxb.
@Test
public void testParseUserFromJaxb() throws SchemaException, SAXException, IOException, JAXBException {
PrismContext prismContext = PrismTestUtil.getPrismContext();
// Try to use the schema to validate Jack
UserType userType = PrismTestUtil.parseObjectable(new File(TestConstants.COMMON_DIR, "user-jack.xml"), UserType.class);
// WHEN
PrismObject<UserType> user = userType.asPrismObject();
user.revive(prismContext);
// THEN
System.out.println("Parsed user:");
System.out.println(user.debugDump());
user.checkConsistence();
assertPropertyValue(user, UserType.F_NAME, PrismTestUtil.createPolyString("jack"));
assertPropertyValue(user, new QName(SchemaConstants.NS_C, "fullName"), new PolyString("Jack Sparrow", "jack sparrow"));
assertPropertyValue(user, new QName(SchemaConstants.NS_C, "givenName"), new PolyString("Jack", "jack"));
assertPropertyValue(user, new QName(SchemaConstants.NS_C, "familyName"), new PolyString("Sparrow", "sparrow"));
assertPropertyValue(user, new QName(SchemaConstants.NS_C, "honorificPrefix"), new PolyString("Cpt.", "cpt"));
assertPropertyValue(user.findContainer(UserType.F_EXTENSION), new QName(NS_FOO, "bar"), "BAR");
PrismProperty<ProtectedStringType> password = user.findOrCreateContainer(UserType.F_EXTENSION).findProperty(new QName(NS_FOO, "password"));
assertNotNull(password);
// TODO: check inside
assertPropertyValue(user.findOrCreateContainer(UserType.F_EXTENSION), new QName(NS_FOO, "num"), 42);
PrismProperty<?> multi = user.findOrCreateContainer(UserType.F_EXTENSION).findProperty(new QName(NS_FOO, "multi"));
assertEquals(3, multi.getValues().size());
// WHEN
// Node domNode = user.serializeToDom();
//
// //THEN
// System.out.println("\nSerialized user:");
// System.out.println(DOMUtil.serializeDOMToString(domNode));
//
// Element userEl = DOMUtil.getFirstChildElement(domNode);
// assertEquals(SchemaConstants.I_USER, DOMUtil.getQName(userEl));
// TODO: more asserts
}
use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class TestJaxbParsing method testMarshallObjectDeltaType.
@Test
public void testMarshallObjectDeltaType() throws Exception {
ObjectDeltaType delta = new ObjectDeltaType();
delta.setOid("07b32c14-0c18-460b-bd4a-99b96699f952");
delta.setChangeType(ChangeTypeType.MODIFY);
ItemDeltaType item1 = new ItemDeltaType();
delta.getItemDelta().add(item1);
item1.setModificationType(ModificationTypeType.REPLACE);
Document document = DOMUtil.getDocument();
// Element path = document.createElementNS(SchemaConstantsGenerated.NS_TYPES, "path");
// path.setTextContent("c:credentials/c:password");
ItemPath path = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD);
item1.setPath(new ItemPathType(path));
ProtectedStringType protectedString = new ProtectedStringType();
protectedString.setEncryptedData(new EncryptedDataType());
RawType value = new RawType(((PrismContextImpl) PrismTestUtil.getPrismContext()).getBeanMarshaller().marshall(protectedString), PrismTestUtil.getPrismContext());
item1.getValue().add(value);
String xml = PrismTestUtil.serializeJaxbElementToString(new JAXBElement<Object>(new QName("http://www.example.com", "custom"), Object.class, delta));
assertNotNull(xml);
}
Aggregations