use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class QueryInterpreter2Test method test640queryAssignmentExtensionBoolean.
@Test
public void test640queryAssignmentExtensionBoolean() throws Exception {
Session session = open();
try {
SchemaRegistry registry = prismContext.getSchemaRegistry();
PrismObjectDefinition userDef = registry.findObjectDefinitionByCompileTimeClass(UserType.class);
PrismContainerDefinition assignmentDef = userDef.findContainerDefinition(F_ASSIGNMENT);
PrismPropertyDefinition propDef = ((PrismContainerDefinitionImpl) assignmentDef).createPropertyDefinition(SKIP_AUTOGENERATION, DOMUtil.XSD_BOOLEAN);
ObjectQuery objectQuery = QueryBuilder.queryFor(UserType.class, prismContext).itemWithDef(propDef, F_ASSIGNMENT, AssignmentType.F_EXTENSION, SKIP_AUTOGENERATION).eq(true).build();
objectQuery.setUseNewQueryInterpreter(true);
String real = getInterpretedQuery2(session, UserType.class, objectQuery);
String expected = "select\n" + " u.oid, u.fullObject,\n" + " u.stringsCount,\n" + " u.longsCount,\n" + " u.datesCount,\n" + " u.referencesCount,\n" + " u.polysCount,\n" + " u.booleansCount\n" + "from\n" + " RUser u\n" + " left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" + " left join a.extension e\n" + " left join e.booleans b with b.name = :name\n" + "where\n" + " b.value = :value";
assertEqualsIgnoreWhitespace(expected, real);
OperationResult result = new OperationResult("search");
List<PrismObject<UserType>> objects = repositoryService.searchObjects(UserType.class, objectQuery, null, result);
result.computeStatus();
AssertJUnit.assertTrue(result.isSuccess());
AssertJUnit.assertNotNull(objects);
assertEquals(1, objects.size());
PrismObject<UserType> obj = objects.get(0);
AssertJUnit.assertTrue(obj.getCompileTimeClass().equals(UserType.class));
result = new OperationResult("count");
long count = repositoryService.countObjects(UserType.class, objectQuery, result);
result.computeStatus();
AssertJUnit.assertTrue(result.isSuccess());
assertEquals(1, count);
} finally {
close(session);
}
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class RAnyConverterStaticTest method getDefinition.
private <T extends ObjectType> ItemDefinition getDefinition(Class<T> type, ItemPath path) {
SchemaRegistry registry = prismContext.getSchemaRegistry();
PrismObjectDefinition objectDef = registry.findObjectDefinitionByCompileTimeClass(type);
return objectDef.findItemDefinition(path);
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class TestSanity method test000Integrity.
/**
* Test integrity of the test setup.
*
* @throws SchemaException
* @throws ObjectNotFoundException
* @throws CommunicationException
*/
@Test
public void test000Integrity() throws Exception {
final String TEST_NAME = "test000Integrity";
TestUtil.displayTestTile(this, TEST_NAME);
assertNotNull(modelWeb);
assertNotNull(modelService);
assertNotNull(repositoryService);
assertTrue(isSystemInitialized());
assertNotNull(taskManager);
assertNotNull(prismContext);
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
assertNotNull(schemaRegistry);
// This is defined in extra schema. So this effectively checks whether the extra schema was loaded
PrismPropertyDefinition shipStateDefinition = schemaRegistry.findPropertyDefinitionByElementName(MY_SHIP_STATE);
assertNotNull("No my:shipState definition", shipStateDefinition);
assertEquals("Wrong maxOccurs in my:shipState definition", 1, shipStateDefinition.getMaxOccurs());
assertNoRepoCache();
Task task = taskManager.createTaskInstance(TestSanity.class.getName() + ".test000Integrity");
OperationResult result = task.getResult();
// Check if OpenDJ resource was imported correctly
PrismObject<ResourceType> openDjResource = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, result);
display("Imported OpenDJ resource (repository)", openDjResource);
AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, openDjResource.getOid());
assertNoRepoCache();
String ldapConnectorOid = openDjResource.asObjectable().getConnectorRef().getOid();
PrismObject<ConnectorType> ldapConnector = repositoryService.getObject(ConnectorType.class, ldapConnectorOid, null, result);
display("LDAP Connector: ", ldapConnector);
// TODO: test if OpenDJ and Derby are running
repositoryService.getObject(GenericObjectType.class, SAMPLE_CONFIGURATION_OBJECT_OID, null, result);
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class PageAdminFocus method prepareObjectDeltaForModify.
@Override
protected void prepareObjectDeltaForModify(ObjectDelta<F> focusDelta) throws SchemaException {
super.prepareObjectDeltaForModify(focusDelta);
// handle accounts
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismObjectDefinition<F> objectDefinition = registry.findObjectDefinitionByCompileTimeClass(getCompileTimeClass());
PrismReferenceDefinition refDef = objectDefinition.findReferenceDefinition(FocusType.F_LINK_REF);
ReferenceDelta refDelta = prepareUserAccountsDeltaForModify(refDef);
if (!refDelta.isEmpty()) {
focusDelta.addModification(refDelta);
}
refDef = objectDefinition.findReferenceDefinition(FocusType.F_PARENT_ORG_REF);
refDelta = prepareUserOrgsDeltaForModify(refDef);
if (!refDelta.isEmpty()) {
focusDelta.addModification(refDelta);
}
// only slow down the operation - especially if we have many assignments
if (isAssignmentsLoaded()) {
// handle assignments
PrismContainerDefinition def = objectDefinition.findContainerDefinition(UserType.F_ASSIGNMENT);
handleAssignmentDeltas(focusDelta, getFocusAssignments(), def);
}
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class PageSecurityQuestions method resetPassword.
private void resetPassword(UserType user, AjaxRequestTarget target) {
Task task = createAnonymousTask(OPERATION_RESET_PASSWORD);
OperationResult result = task.getResult();
LOGGER.debug("Resetting password for {}", user);
ProtectedStringType password = new ProtectedStringType();
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createResolve(), SystemConfigurationType.F_DEFAULT_USER_TEMPLATE, SystemConfigurationType.F_GLOBAL_PASSWORD_POLICY);
PrismObject<SystemConfigurationType> systemConfig = null;
String newPassword = "";
PageBase page = (PageBase) getPage();
ModelService modelService = page.getModelService();
try {
systemConfig = modelService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), options, task, result);
LOGGER.trace("system config {}", systemConfig);
if (systemConfig.asObjectable().getNotificationConfiguration() != null) {
// Security policy with the minumum number of chars
if (systemConfig.asObjectable().getGlobalPasswordPolicyRef() != null) {
PrismObject<ValuePolicyType> valPolicy = modelService.getObject(ValuePolicyType.class, systemConfig.asObjectable().getGlobalPasswordPolicyRef().getOid(), options, task, result);
LOGGER.trace("password policy {}", valPolicy);
newPassword = getModelInteractionService().generateValue(valPolicy.asObjectable().getStringPolicy(), valPolicy.asObjectable().getStringPolicy().getLimitations().getMinLength(), false, user.asPrismObject(), "security questions password generation", task, result);
} else {
// TODO What if there is no policy? What should be done to
// provide a new automatic password
warn(getString("pageSecurityQuestions.message.noPolicySet"));
target.add(getFeedbackPanel());
return;
}
} else {
// TODO localization
getSession().error(getString("pageSecurityQuestions.message.notificationsNotSet"));
LOGGER.trace("Notificatons not set, returning to login page");
throw new RestartResponseException(PageLogin.class);
}
} catch (ObjectNotFoundException | ExpressionEvaluationException e1) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reset password", e1);
} catch (SchemaException e1) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reset password", e1);
e1.printStackTrace();
} catch (SecurityViolationException e1) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reset password", e1);
} catch (CommunicationException e1) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reset password", e1);
} catch (ConfigurationException e1) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reset password", e1);
}
password.setClearValue(newPassword);
WebComponentUtil.encryptProtectedString(password, true, getMidpointApplication());
final ItemPath valuePath = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
PrismObjectDefinition objDef = registry.findObjectDefinitionByCompileTimeClass(UserType.class);
PropertyDelta delta = PropertyDelta.createModificationReplaceProperty(valuePath, objDef, password);
Class<? extends ObjectType> type = UserType.class;
deltas.add(ObjectDelta.createModifyDelta(user.getOid(), delta, type, getPrismContext()));
try {
modelService.executeChanges(deltas, null, task, result);
OperationResult parentResult = new OperationResult(OPERATION_LOAD_RESET_PASSWORD_POLICY);
try {
if (getModelInteractionService().getCredentialsPolicy(null, null, parentResult).getSecurityQuestions().getResetMethod().getResetType().equals(CredentialsResetTypeType.SECURITY_QUESTIONS)) {
getSession().setAttribute("pwdReset", newPassword);
setResponsePage(PageShowPassword.class);
} else if (getModelInteractionService().getCredentialsPolicy(null, null, parentResult).getSecurityQuestions().getResetMethod().getResetType().equals(CredentialsResetTypeType.SECURITY_QUESTIONS_EMAIL)) {
if (systemConfig.asObjectable().getNotificationConfiguration() != null && systemConfig.asObjectable().getNotificationConfiguration().getMail() != null) {
MailConfigurationType mailConfig = systemConfig.asObjectable().getNotificationConfiguration().getMail();
if (mailConfig.getServer() != null) {
List serverList = mailConfig.getServer();
if (serverList.size() > 0) {
MailServerConfigurationType mailServerType = mailConfig.getServer().get(0);
sendMailToUser(mailServerType.getUsername(), getMidpointApplication().getProtector().decryptString(mailServerType.getPassword()), newPassword, mailServerType.getHost(), mailServerType.getPort().toString(), mailConfig.getDefaultFrom(), user.getEmailAddress());
} else {
getSession().error(getString("pageLogin.message.ForgetPasswordSettingsWrong"));
throw new RestartResponseException(PageLogin.class);
}
} else {
getSession().error(getString("pageLogin.message.ForgetPasswordSettingsWrong"));
throw new RestartResponseException(PageLogin.class);
}
} else {
// System.out.println("ifff4");
getSession().error(getString("pageLogin.message.ForgetPasswordSettingsWrong"));
throw new RestartResponseException(PageLogin.class);
}
}
} catch (ObjectNotFoundException | SchemaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO ASAP a message should be shown as the result of the process
// MailMessage mailMessage=new MailMessage(, port);
// mailTransport.send(mailMessage, transportName, task,
// parentResult);
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException | EncryptionException e) {
LoggingUtils.logUnexpectedException(LOGGER, "reset password exception", e);
}
}
Aggregations