use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class ConsistencyTest method test999Shutdown.
@Test
public void test999Shutdown() throws Exception {
taskManager.shutdown();
waitFor("waiting for task manager shutdown", new Checker() {
@Override
public boolean check() throws CommonException {
try {
return taskManager.getLocallyRunningTasks(new OperationResult("dummy")).isEmpty();
} catch (TaskManagerException e) {
throw new SystemException(e);
}
}
@Override
public void timeout() {
// No reaction, the test will fail right after return from this
}
}, 10000);
AssertJUnit.assertEquals("Some tasks left running after shutdown", new HashSet<Task>(), taskManager.getLocallyRunningTasks(new OperationResult("dummy")));
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class PageLogin method initCustomLayer.
@Override
protected void initCustomLayer() {
MidpointForm form = new MidpointForm(ID_FORM);
form.add(AttributeModifier.replace("action", new IModel<String>() {
@Override
public String getObject() {
return getUrlProcessingLogin();
}
}));
add(form);
BookmarkablePageLink<String> link = new BookmarkablePageLink<>(ID_FORGET_PASSWORD, PageForgotPassword.class);
Task task = createAnonymousTask(OPERATION_LOAD_RESET_PASSWORD_POLICY);
OperationResult parentResult = new OperationResult(OPERATION_LOAD_RESET_PASSWORD_POLICY);
SecurityPolicyType securityPolicy = null;
try {
securityPolicy = getModelInteractionService().getSecurityPolicy((PrismObject<? extends FocusType>) null, task, parentResult);
} catch (CommonException e) {
LOGGER.warn("Cannot read credentials policy: " + e.getMessage(), e);
}
SecurityPolicyType finalSecurityPolicy = securityPolicy;
link.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
if (finalSecurityPolicy == null) {
return false;
}
if (finalSecurityPolicy != null && finalSecurityPolicy.getCredentialsReset() != null && StringUtils.isNotBlank(finalSecurityPolicy.getCredentialsReset().getAuthenticationSequenceName())) {
AuthenticationSequenceType sequence = SecurityUtils.getSequenceByName(finalSecurityPolicy.getCredentialsReset().getAuthenticationSequenceName(), finalSecurityPolicy.getAuthentication());
if (sequence != null && (sequence.getChannel() == null || StringUtils.isBlank(sequence.getChannel().getUrlSuffix()))) {
return false;
}
}
CredentialsPolicyType creds = finalSecurityPolicy.getCredentials();
// TODO: Not entirely correct. This means we have reset somehow configured, but not necessarily enabled.
if (creds != null && ((creds.getSecurityQuestions() != null && creds.getSecurityQuestions().getQuestionNumber() != null) || (finalSecurityPolicy.getCredentialsReset() != null))) {
return true;
}
return false;
}
});
if (securityPolicy != null && securityPolicy.getCredentialsReset() != null && StringUtils.isNotBlank(securityPolicy.getCredentialsReset().getAuthenticationSequenceName())) {
AuthenticationSequenceType sequence = SecurityUtils.getSequenceByName(securityPolicy.getCredentialsReset().getAuthenticationSequenceName(), securityPolicy.getAuthentication());
if (sequence != null) {
if (sequence.getChannel() == null || StringUtils.isBlank(sequence.getChannel().getUrlSuffix())) {
String message = "Sequence with name " + securityPolicy.getCredentialsReset().getAuthenticationSequenceName() + " doesn't contain urlSuffix";
LOGGER.error(message, new IllegalArgumentException(message));
error(message);
}
link.add(AttributeModifier.replace("href", new IModel<String>() {
@Override
public String getObject() {
return "./" + ModuleWebSecurityConfiguration.DEFAULT_PREFIX_OF_MODULE + "/" + sequence.getChannel().getUrlSuffix();
}
}));
}
}
form.add(link);
BookmarkablePageLink<String> registration = new BookmarkablePageLink<>(ID_SELF_REGISTRATION, PageSelfRegistration.class);
registration.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
OperationResult parentResult = new OperationResult(OPERATION_LOAD_REGISTRATION_POLICY);
RegistrationsPolicyType registrationPolicies = null;
try {
Task task = createAnonymousTask(OPERATION_LOAD_REGISTRATION_POLICY);
registrationPolicies = getModelInteractionService().getFlowPolicy(null, task, parentResult);
} catch (CommonException e) {
LOGGER.warn("Cannot read credentials policy: " + e.getMessage(), e);
}
boolean linkIsVisible = false;
if (registrationPolicies != null && registrationPolicies.getSelfRegistration() != null) {
linkIsVisible = true;
}
return linkIsVisible;
}
});
if (securityPolicy != null) {
SelfRegistrationPolicyType policy = SecurityPolicyUtil.getSelfRegistrationPolicy(securityPolicy);
if (policy != null) {
String sequenceName = policy.getAdditionalAuthenticationSequence() == null ? policy.getAdditionalAuthenticationName() : policy.getAdditionalAuthenticationSequence();
if (StringUtils.isNotBlank(sequenceName)) {
AuthenticationSequenceType sequence = SecurityUtils.getSequenceByName(sequenceName, securityPolicy.getAuthentication());
if (sequence != null) {
registration.add(AttributeModifier.replace("href", () -> "./" + ModuleWebSecurityConfiguration.DEFAULT_PREFIX_OF_MODULE + "/" + sequence.getChannel().getUrlSuffix()));
}
}
}
}
form.add(registration);
WebMarkupContainer csrfField = SecurityUtils.createHiddenInputForCsrf(ID_CSRF_FIELD);
form.add(csrfField);
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class PageRegistrationFinish method assignDefaultRoles.
private void assignDefaultRoles(String userOid, PrismObject<UserType> administrator, OperationResult parentResult) throws CommonException {
List<ObjectReferenceType> rolesToAssign = getSelfRegistrationConfiguration().getDefaultRoles();
if (CollectionUtils.isEmpty(rolesToAssign)) {
return;
}
OperationResult result = parentResult.createSubresult(OPERATION_ASSIGN_DEFAULT_ROLES);
try {
PrismContext prismContext = getPrismContext();
List<AssignmentType> assignmentsToCreate = rolesToAssign.stream().map(ref -> ObjectTypeUtil.createAssignmentTo(ref, prismContext)).collect(Collectors.toList());
ObjectDelta<Objectable> delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).addRealValues(assignmentsToCreate).asObjectDelta(userOid);
runAsChecked(() -> {
Task task = createSimpleTask(OPERATION_ASSIGN_DEFAULT_ROLES);
WebModelServiceUtils.save(delta, result, task, PageRegistrationFinish.this);
return null;
}, administrator);
} catch (CommonException | RuntimeException e) {
result.recordFatalError(getString("PageRegistrationConfirmation.message.assignDefaultRoles.fatalError"), e);
throw e;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class PageRegistrationFinish method assignAdditionalRoleIfPresent.
private void assignAdditionalRoleIfPresent(String userOid, NonceType nonceType, PrismObject<UserType> administrator, OperationResult parentResult) throws CommonException {
if (nonceType.getName() == null) {
return;
}
OperationResult result = parentResult.createSubresult(OPERATION_ASSIGN_ADDITIONAL_ROLE);
try {
runAsChecked(() -> {
Task task = createAnonymousTask(OPERATION_ASSIGN_ADDITIONAL_ROLE);
ObjectDelta<UserType> assignRoleDelta;
AssignmentType assignment = new AssignmentType();
assignment.setTargetRef(ObjectTypeUtil.createObjectRef(nonceType.getName(), ObjectTypes.ABSTRACT_ROLE));
getPrismContext().adopt(assignment);
List<ItemDelta> userDeltas = new ArrayList<>();
userDeltas.add(getPrismContext().deltaFactory().container().createModificationAdd(UserType.F_ASSIGNMENT, UserType.class, assignment));
assignRoleDelta = getPrismContext().deltaFactory().object().createModifyDelta(userOid, userDeltas, UserType.class);
assignRoleDelta.setPrismContext(getPrismContext());
WebModelServiceUtils.save(assignRoleDelta, result, task, PageRegistrationFinish.this);
return null;
}, administrator);
} catch (CommonException | RuntimeException e) {
result.recordFatalError(getString("PageRegistrationConfirmation.message.assignAdditionalRoleIfPresent.fatalError"), e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't assign additional role", e);
throw e;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class PageRegistrationConfirmation method init.
private void init(final PageParameters pageParameters) {
PageParameters params = pageParameters;
if (params == null) {
params = getPageParameters();
}
OperationResult result = new OperationResult(OPERATION_FINISH_REGISTRATION);
if (params == null) {
LOGGER.error("Confirmation link is not valid. No credentials provided in it");
String msg = createStringResource("PageSelfRegistration.invalid.registration.link").getString();
getSession().error(createStringResource(msg));
result.recordFatalError(msg);
initLayout(result);
return;
}
StringValue userNameValue = params.get(SchemaConstants.USER_ID);
Validate.notEmpty(userNameValue.toString());
StringValue tokenValue = params.get(SchemaConstants.TOKEN);
Validate.notEmpty(tokenValue.toString());
try {
UserType user = checkUserCredentials(userNameValue.toString(), tokenValue.toString(), result);
PrismObject<UserType> administrator = getAdministratorPrivileged(result);
assignDefaultRoles(user.getOid(), administrator, result);
result.computeStatus();
if (result.getStatus() == OperationResultStatus.FATAL_ERROR) {
LOGGER.error("Failed to assign default roles, {}", result.getMessage());
} else {
NonceType nonceClone = user.getCredentials().getNonce().clone();
removeNonceAndSetLifecycleState(user.getOid(), nonceClone, administrator, result);
assignAdditionalRoleIfPresent(user.getOid(), nonceClone, administrator, result);
result.computeStatus();
}
initLayout(result);
} catch (CommonException | AuthenticationException e) {
result.computeStatus();
initLayout(result);
}
}
Aggregations