use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.
the class TestIntegrationObjectWrapperFactory method test800EditSchemaJackPropReadAllModifySomeUser.
/**
* MID-3126
*/
@Test
public void test800EditSchemaJackPropReadAllModifySomeUser() throws Exception {
final String TEST_NAME = "test800EditSchemaJackPropReadAllModifySomeUser";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_PROP_READ_ALL_MODIFY_SOME_USER_OID);
login(USER_JACK_USERNAME);
ObjectWrapperFactory factory = new ObjectWrapperFactory(getServiceLocator());
PrismObject<UserType> user = getUser(USER_JACK_OID);
display("user before", user);
// WHEN
TestUtil.displayWhen(TEST_NAME);
Task task = taskManager.createTaskInstance(TEST_NAME);
ObjectWrapper<UserType> objectWrapper = factory.createObjectWrapper("user display name", "user description", user, ContainerStatus.MODIFYING, task);
// THEN
TestUtil.displayThen(TEST_NAME);
IntegrationTestTools.display("Wrapper after", objectWrapper);
assertEquals("Wrong object wrapper readOnly", Boolean.FALSE, (Boolean) objectWrapper.isReadonly());
ContainerWrapper<UserType> mainContainerWrapper = objectWrapper.findMainContainerWrapper();
assertEquals("Wrong main container wrapper readOnly", Boolean.FALSE, (Boolean) mainContainerWrapper.isReadonly());
ItemWrapper nameWrapper = mainContainerWrapper.findPropertyWrapper(UserType.F_NAME);
// Is this OK?
assertEquals("Wrong name readOnly", Boolean.TRUE, (Boolean) nameWrapper.isReadonly());
assertEquals("Wrong name visible", Boolean.TRUE, (Boolean) nameWrapper.isVisible());
assertEquals("Wrong name definition.canRead", Boolean.TRUE, (Boolean) nameWrapper.getItemDefinition().canRead());
assertEquals("Wrong name definition.canAdd", Boolean.FALSE, (Boolean) nameWrapper.getItemDefinition().canAdd());
assertEquals("Wrong name definition.canModify", Boolean.FALSE, (Boolean) nameWrapper.getItemDefinition().canModify());
ItemWrapper givenNameWrapper = mainContainerWrapper.findPropertyWrapper(UserType.F_GIVEN_NAME);
// Is this OK?
assertEquals("Wrong givenName readOnly", Boolean.TRUE, (Boolean) givenNameWrapper.isReadonly());
assertEquals("Wrong givenName visible", Boolean.TRUE, (Boolean) givenNameWrapper.isVisible());
assertEquals("Wrong givenName definition.canRead", Boolean.TRUE, (Boolean) givenNameWrapper.getItemDefinition().canRead());
assertEquals("Wrong givenName definition.canAdd", Boolean.FALSE, (Boolean) givenNameWrapper.getItemDefinition().canAdd());
assertEquals("Wrong givenName definition.canModify", Boolean.FALSE, (Boolean) givenNameWrapper.getItemDefinition().canModify());
ItemWrapper fullNameWrapper = mainContainerWrapper.findPropertyWrapper(UserType.F_FULL_NAME);
assertEquals("Wrong fullName readOnly", Boolean.FALSE, (Boolean) fullNameWrapper.isReadonly());
assertEquals("Wrong fullName visible", Boolean.TRUE, (Boolean) fullNameWrapper.isVisible());
assertEquals("Wrong fullName definition.canRead", Boolean.TRUE, (Boolean) fullNameWrapper.getItemDefinition().canRead());
assertEquals("Wrong fullName definition.canAdd", Boolean.FALSE, (Boolean) fullNameWrapper.getItemDefinition().canAdd());
assertEquals("Wrong fullName definition.canModify", Boolean.TRUE, (Boolean) fullNameWrapper.getItemDefinition().canModify());
ItemWrapper additionalNameWrapper = mainContainerWrapper.findPropertyWrapper(UserType.F_ADDITIONAL_NAME);
// Is this OK?
assertEquals("Wrong additionalName readOnly", Boolean.TRUE, (Boolean) additionalNameWrapper.isReadonly());
// not visible, because it is empty
assertEquals("Wrong additionalName visible", Boolean.FALSE, (Boolean) additionalNameWrapper.isVisible());
assertEquals("Wrong additionalName definition.canRead", Boolean.TRUE, (Boolean) additionalNameWrapper.getItemDefinition().canRead());
assertEquals("Wrong additionalName definition.canAdd", Boolean.FALSE, (Boolean) additionalNameWrapper.getItemDefinition().canAdd());
assertEquals("Wrong additionalName definition.canModify", Boolean.FALSE, (Boolean) additionalNameWrapper.getItemDefinition().canModify());
ItemWrapper localityNameWrapper = mainContainerWrapper.findPropertyWrapper(UserType.F_LOCALITY);
assertEquals("Wrong locality readOnly", Boolean.TRUE, (Boolean) localityNameWrapper.isReadonly());
assertEquals("Wrong locality visible", Boolean.TRUE, (Boolean) localityNameWrapper.isVisible());
assertEquals("Wrong locality definition.canRead", Boolean.TRUE, (Boolean) localityNameWrapper.getItemDefinition().canRead());
assertEquals("Wrong locality definition.canAdd", Boolean.FALSE, (Boolean) localityNameWrapper.getItemDefinition().canAdd());
assertEquals("Wrong locality definition.canModify", Boolean.FALSE, (Boolean) localityNameWrapper.getItemDefinition().canModify());
// WHEN
objectWrapper.setShowEmpty(true);
// THEN
additionalNameWrapper = mainContainerWrapper.findPropertyWrapper(UserType.F_ADDITIONAL_NAME);
// not visible, because it is empty
assertEquals("Wrong additionalName visible", Boolean.TRUE, (Boolean) additionalNameWrapper.isVisible());
}
use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.
the class TestIntegrationObjectWrapperFactory method test150CreateWrapperShadow.
@Test
public void test150CreateWrapperShadow() throws Exception {
final String TEST_NAME = "test150CreateWrapperShadow";
TestUtil.displayTestTile(TEST_NAME);
PrismObject<ShadowType> shadow = getShadowModel(accountJackOid);
shadow.findReference(ShadowType.F_RESOURCE_REF).getValue().setObject(resourceDummy);
// WHEN
TestUtil.displayWhen(TEST_NAME);
Task task = taskManager.createTaskInstance(TEST_NAME);
ObjectWrapperFactory factory = new ObjectWrapperFactory(getServiceLocator());
ObjectWrapper<ShadowType> objectWrapper = factory.createObjectWrapper("shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING, task);
// THEN
TestUtil.displayThen(TEST_NAME);
display("Wrapper after", objectWrapper);
WrapperTestUtil.assertWrapper(objectWrapper, "shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING);
assertEquals("wrong number of containers in " + objectWrapper, 9, objectWrapper.getContainers().size());
ContainerWrapper<ShadowAttributesType> attributesContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ATTRIBUTES));
PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
WrapperTestUtil.assertWrapper(attributesContainerWrapper, "prismContainer.shadow.mainPanelDisplayName", new ItemPath(ShadowType.F_ATTRIBUTES), attributesContainer, true, ContainerStatus.MODIFYING);
WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, dummyResourceCtl.getAttributeFullnameQName(), USER_JACK_FULL_NAME);
WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, SchemaConstants.ICFS_NAME, USER_JACK_USERNAME);
assertEquals("wrong number of items in " + attributesContainerWrapper, 16, attributesContainerWrapper.getItems().size());
ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(UserType.F_ACTIVATION));
WrapperTestUtil.assertWrapper(activationContainerWrapper, "ShadowType.activation", UserType.F_ACTIVATION, shadow, ContainerStatus.MODIFYING);
WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, ActivationStatusType.ENABLED);
WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_LOCKOUT_STATUS, null);
assertEquals("Wrong attributes container wrapper readOnly", Boolean.FALSE, (Boolean) attributesContainerWrapper.isReadonly());
ItemWrapper fullnameWrapper = attributesContainerWrapper.findPropertyWrapper(dummyResourceCtl.getAttributeFullnameQName());
// Is this OK?
assertEquals("Wrong attribute fullname readOnly", Boolean.FALSE, (Boolean) fullnameWrapper.isReadonly());
assertEquals("Wrong attribute fullname visible", Boolean.TRUE, (Boolean) fullnameWrapper.isVisible());
ItemDefinition fullNameDefinition = fullnameWrapper.getItemDefinition();
display("fullname attribute definition", fullNameDefinition);
assertEquals("Wrong attribute fullname definition.canRead", Boolean.TRUE, (Boolean) fullNameDefinition.canRead());
assertEquals("Wrong attribute fullname definition.canAdd", Boolean.TRUE, (Boolean) fullNameDefinition.canAdd());
assertEquals("Wrong attribute fullname definition.canModify", Boolean.TRUE, (Boolean) fullNameDefinition.canModify());
// MID-3144
if (fullNameDefinition.getDisplayOrder() == null || fullNameDefinition.getDisplayOrder() < 100 || fullNameDefinition.getDisplayOrder() > 400) {
AssertJUnit.fail("Wrong fullname definition.displayOrder: " + fullNameDefinition.getDisplayOrder());
}
assertEquals("Wrong attribute fullname definition.displayName", "Full Name", fullNameDefinition.getDisplayName());
}
use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.
the class PageAbstractSelfCredentials method loadPageModel.
private MyPasswordsDto loadPageModel() {
LOGGER.debug("Loading user and accounts.");
MyPasswordsDto dto = new MyPasswordsDto();
OperationResult result = new OperationResult(OPERATION_LOAD_USER_WITH_ACCOUNTS);
try {
String userOid = SecurityUtils.getPrincipalUser().getOid();
Task task = createSimpleTask(OPERATION_LOAD_USER);
OperationResult subResult = result.createSubresult(OPERATION_LOAD_USER);
user = getModelService().getObject(UserType.class, userOid, null, task, subResult);
subResult.recordSuccessIfUnknown();
dto.getAccounts().add(createDefaultPasswordAccountDto(user));
CredentialsPolicyType credentialsPolicyType = getPasswordCredentialsPolicy();
if (credentialsPolicyType != null) {
PasswordCredentialsPolicyType passwordCredentialsPolicy = credentialsPolicyType.getPassword();
if (passwordCredentialsPolicy != null) {
CredentialsPropagationUserControlType propagationUserControl = passwordCredentialsPolicy.getPropagationUserControl();
if (propagationUserControl != null) {
dto.setPropagation(propagationUserControl);
}
PasswordChangeSecurityType passwordChangeSecurity = passwordCredentialsPolicy.getPasswordChangeSecurity();
if (passwordChangeSecurity != null) {
dto.setPasswordChangeSecurity(passwordChangeSecurity);
}
}
}
if (dto.getPropagation() == null || dto.getPropagation().equals(CredentialsPropagationUserControlType.USER_CHOICE)) {
PrismReference reference = user.findReference(UserType.F_LINK_REF);
if (reference == null || reference.getValues() == null) {
LOGGER.debug("No accounts found for user {}.", new Object[] { userOid });
return dto;
}
final Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(ShadowType.F_RESOURCE, GetOperationOptions.createResolve());
List<PrismReferenceValue> values = reference.getValues();
for (PrismReferenceValue value : values) {
subResult = result.createSubresult(OPERATION_LOAD_ACCOUNT);
try {
String accountOid = value.getOid();
task = createSimpleTask(OPERATION_LOAD_ACCOUNT);
PrismObject<ShadowType> account = getModelService().getObject(ShadowType.class, accountOid, options, task, subResult);
dto.getAccounts().add(createPasswordAccountDto(account));
subResult.recordSuccessIfUnknown();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load account", ex);
subResult.recordFatalError("Couldn't load account.", ex);
}
}
}
result.recordSuccessIfUnknown();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load accounts", ex);
result.recordFatalError("Couldn't load accounts", ex);
} finally {
result.recomputeStatus();
}
Collections.sort(dto.getAccounts());
if (!result.isSuccess() && !result.isHandledError()) {
showResult(result);
}
return dto;
}
use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.
the class AuditedLogoutHandler method auditEvent.
private void auditEvent(HttpServletRequest request, Authentication authentication) {
MidPointPrincipal principal = SecurityUtils.getPrincipalUser(authentication);
PrismObject<UserType> user = principal != null ? principal.getUser().asPrismObject() : null;
Task task = taskManager.createTaskInstance();
task.setOwner(user);
task.setChannel(SchemaConstants.CHANNEL_GUI_USER_URI);
AuditEventRecord record = new AuditEventRecord(AuditEventType.TERMINATE_SESSION, AuditEventStage.REQUEST);
record.setInitiator(user);
record.setParameter(WebComponentUtil.getName(user));
record.setChannel(SchemaConstants.CHANNEL_GUI_USER_URI);
record.setTimestamp(System.currentTimeMillis());
record.setOutcome(OperationResultStatus.SUCCESS);
// probably not needed, as audit service would take care of it; but it doesn't hurt so let's keep it here
record.setHostIdentifier(request.getLocalName());
record.setRemoteHostAddress(request.getLocalAddr());
record.setNodeIdentifier(taskManager.getNodeId());
record.setSessionIdentifier(request.getRequestedSessionId());
auditService.audit(record, task);
}
use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.
the class PageDebugView method loadObject.
private ObjectViewDto loadObject() {
StringValue objectOid = getPageParameters().get(PARAM_OBJECT_ID);
if (objectOid == null || StringUtils.isEmpty(objectOid.toString())) {
getSession().error(getString("pageDebugView.message.oidNotDefined"));
throw new RestartResponseException(PageDebugList.class);
}
Task task = createSimpleTask(OPERATION_LOAD_OBJECT);
//todo is this result != null ?
OperationResult result = task.getResult();
ObjectViewDto dto = null;
try {
MidPointApplication application = PageDebugView.this.getMidpointApplication();
GetOperationOptions rootOptions = GetOperationOptions.createRaw();
rootOptions.setResolveNames(true);
rootOptions.setTolerateRawData(true);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(rootOptions);
// FIXME: ObjectType.class will not work well here. We need more specific type.
//todo on page debug list create page params, put there oid and class for object type and send that to this page....read it here
Class type = ObjectType.class;
StringValue objectType = getPageParameters().get(PARAM_OBJECT_TYPE);
if (objectType != null && StringUtils.isNotBlank(objectType.toString())) {
type = getPrismContext().getSchemaRegistry().determineCompileTimeClass(new QName(SchemaConstantsGenerated.NS_COMMON, objectType.toString()));
}
// TODO make this configurable (or at least do not show campaign cases in production)
if (UserType.class.isAssignableFrom(type)) {
options.add(SelectorOptions.create(UserType.F_JPEG_PHOTO, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE)));
}
if (LookupTableType.class.isAssignableFrom(type)) {
options.add(SelectorOptions.create(LookupTableType.F_ROW, GetOperationOptions.createRetrieve(new RelationalValueSearchQuery(ObjectPaging.createPaging(PrismConstants.T_ID, OrderDirection.ASCENDING)))));
}
if (AccessCertificationCampaignType.class.isAssignableFrom(type)) {
options.add(SelectorOptions.create(AccessCertificationCampaignType.F_CASE, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE)));
}
PrismObject<ObjectType> object = getModelService().getObject(type, objectOid.toString(), options, task, result);
PrismContext context = application.getPrismContext();
String lex = context.serializerFor(dataLanguage).serialize(object);
dto = new ObjectViewDto(object.getOid(), WebComponentUtil.getName(object), object, lex);
result.recomputeStatus();
} catch (Exception ex) {
result.recordFatalError("Couldn't load object.", ex);
}
if (dto == null) {
showResult(result);
throw new RestartResponseException(PageDebugList.class);
}
showResult(result, false);
if (!WebComponentUtil.isSuccessOrHandledErrorOrWarning(result)) {
showResult(result, false);
throw new RestartResponseException(PageDebugList.class);
}
return dto;
}
Aggregations