Search in sources :

Example 1 with NonceType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.NonceType in project midpoint by Evolveum.

the class PageRegistrationConfirmation method assignAdditionalRoleIfPresent.

private OperationResult assignAdditionalRoleIfPresent(String userOid, NonceType nonceType, OperationResult result) {
    //		SecurityContextHolder.getContext().setAuthentication(token);
    return runPrivileged(() -> {
        List<ItemDelta> userDeltas = new ArrayList<>();
        if (nonceType.getName() != null) {
            Task task = createAnonymousTask(OPERATION_FINISH_REGISTRATION);
            ObjectDelta<UserType> assignRoleDelta = null;
            try {
                AssignmentType assignment = new AssignmentType();
                assignment.setTargetRef(ObjectTypeUtil.createObjectRef(nonceType.getName(), ObjectTypes.ABSTRACT_ROLE));
                getPrismContext().adopt(assignment);
                userDeltas.add((ItemDelta) ContainerDelta.createModificationAdd(UserType.F_ASSIGNMENT, UserType.class, getPrismContext(), assignment));
                assignRoleDelta = ObjectDelta.createModifyDelta(userOid, userDeltas, UserType.class, getPrismContext());
                assignRoleDelta.setPrismContext(getPrismContext());
            } catch (SchemaException e) {
                result.recordFatalError("Could not create delta");
                return result;
            }
            WebModelServiceUtils.save(assignRoleDelta, result, task, PageRegistrationConfirmation.this);
            result.computeStatusIfUnknown();
        }
        return result;
    });
//		SecurityContextHolder.getContext().setAuthentication(null);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 2 with NonceType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.NonceType in project midpoint by Evolveum.

the class PageSelfRegistration method createCredentials.

private void createCredentials(UserType user, NonceCredentialsPolicyType noncePolicy, Task task, OperationResult result) throws ExpressionEvaluationException, SchemaException, ObjectNotFoundException {
    NonceType nonceType = createNonce(noncePolicy, task, result);
    // PasswordType password = createPassword();
    CredentialsType credentials = user.getCredentials();
    if (user.getCredentials() == null) {
        credentials = new CredentialsType();
        user.setCredentials(credentials);
    }
    credentials.setNonce(nonceType);
// credentials.setPassword(password);
// return credentials;
}
Also used : CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) NonceType(com.evolveum.midpoint.xml.ns._public.common.common_3.NonceType)

Example 3 with NonceType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.NonceType in project midpoint by Evolveum.

the class PageRegistrationConfirmation method removeNonce.

private OperationResult removeNonce(final String userOid, final NonceType nonce) {
    return runPrivileged(() -> {
        OperationResult result = new OperationResult("assignDefaultRoles");
        Task task = createAnonymousTask("assignDefaultRoles");
        ObjectDelta<UserType> userAssignmentsDelta;
        try {
            userAssignmentsDelta = ObjectDelta.createModificationDeleteContainer(UserType.class, userOid, new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_NONCE), getPrismContext(), nonce);
            userAssignmentsDelta.addModificationReplaceProperty(UserType.F_LIFECYCLE_STATE, SchemaConstants.LIFECYCLE_ACTIVE);
        } catch (SchemaException e) {
            result.recordFatalError("Could not create delta");
            LOGGER.error("Could not prepare delta for removing nonce and lyfecycle state {}", e.getMessage());
            return result;
        }
        WebModelServiceUtils.save(userAssignmentsDelta, result, task, PageRegistrationConfirmation.this);
        result.computeStatusIfUnknown();
        return result;
    });
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 4 with NonceType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.NonceType in project midpoint by Evolveum.

the class PageForgotPassword method saveUserNonce.

private OperationResult saveUserNonce(final UserType user, final NonceCredentialsPolicyType noncePolicy) {
    return runPrivileged(new Producer<OperationResult>() {

        private static final long serialVersionUID = 1L;

        @Override
        public OperationResult run() {
            Task task = createAnonymousTask("generateUserNonce");
            task.setChannel(SchemaConstants.CHANNEL_RESET_PASSWORD_URI);
            task.setOwner(user.asPrismObject());
            OperationResult result = new OperationResult("generateUserNonce");
            ProtectedStringType nonceCredentials = new ProtectedStringType();
            try {
                nonceCredentials.setClearValue(generateNonce(noncePolicy, task, user.asPrismObject(), result));
                // NonceType nonceType = new NonceType();
                // nonceType.setValue(nonceCredentials);
                ObjectDelta<UserType> nonceDelta = getPrismContext().deltaFactory().object().createModificationReplaceProperty(UserType.class, user.getOid(), SchemaConstants.PATH_NONCE_VALUE, nonceCredentials);
                WebModelServiceUtils.save(nonceDelta, result, task, PageForgotPassword.this);
            } catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
                result.recordFatalError(getString("PageForgotPassword.message.saveUserNonce.fatalError"));
                LoggingUtils.logException(LOGGER, "Failed to generate nonce for user: " + e.getMessage(), e);
            }
            result.computeStatusIfUnknown();
            return result;
        }
    });
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

Task (com.evolveum.midpoint.task.api.Task)3 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)1 CredentialsType (com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType)1 NonceType (com.evolveum.midpoint.xml.ns._public.common.common_3.NonceType)1 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)1 ArrayList (java.util.ArrayList)1