Search in sources :

Example 16 with EncryptionException

use of com.evolveum.midpoint.prism.crypto.EncryptionException in project midpoint by Evolveum.

the class RegistrationConfirmationNotifier method getBody.

@Override
protected String getBody(Event event, GeneralNotifierType generalNotifierType, String transport, Task task, OperationResult result) {
    UserType userType = getUser(event);
    String plainTextPassword = "IhopeYouRememberYourPassword";
    try {
        plainTextPassword = getMidpointFunctions().getPlaintextUserPassword(userType);
    } catch (EncryptionException e) {
    //ignore...????
    }
    StringBuilder messageBuilder = new StringBuilder("Dear ");
    messageBuilder.append(userType.getGivenName()).append(",\n").append("your account was successfully created. To activate your account click on the following confiramtion link. ").append("\n").append(createConfirmationLink(userType, generalNotifierType, result)).append("\n\n").append("After your account is activated, use following credentials to log in: \n").append("username: ").append(userType.getName().getOrig()).append("password: ").append(plainTextPassword);
    return messageBuilder.toString();
}
Also used : EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 17 with EncryptionException

use of com.evolveum.midpoint.prism.crypto.EncryptionException in project midpoint by Evolveum.

the class ObjectImporter method importObjectsInternal.

private void importObjectsInternal(InputStream input, final ImportOptionsType options, final boolean raw, final Task task, final OperationResult parentResult) {
    EventHandler handler = new EventHandler() {

        @Override
        public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
            return EventResult.cont();
        }

        @Override
        public <T extends Objectable> EventResult postMarshall(PrismObject<T> prismObjectObjectable, Element objectElement, OperationResult objectResult) {
            LOGGER.debug("Importing object {}", prismObjectObjectable);
            T objectable = prismObjectObjectable.asObjectable();
            if (!(objectable instanceof ObjectType)) {
                String message = "Cannot process type " + objectable.getClass() + " as it is not a subtype of " + ObjectType.class;
                objectResult.recordFatalError(message);
                LOGGER.error("Import of object {} failed: {}", new Object[] { prismObjectObjectable, message });
                return EventResult.skipObject(message);
            }
            PrismObject<? extends ObjectType> object = (PrismObject<? extends ObjectType>) prismObjectObjectable;
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("IMPORTING object:\n{}", object.debugDump());
            }
            object = migrator.migrate(object);
            Utils.resolveReferences(object, repository, (options == null || options.isReferentialIntegrity() == null) ? false : options.isReferentialIntegrity(), false, EvaluationTimeType.IMPORT, false, prismContext, objectResult);
            objectResult.computeStatus();
            if (!objectResult.isAcceptable()) {
                return EventResult.skipObject(objectResult.getMessage());
            }
            generateIdentifiers(object, repository, objectResult);
            objectResult.computeStatus();
            if (!objectResult.isAcceptable()) {
                return EventResult.skipObject(objectResult.getMessage());
            }
            if (options != null && BooleanUtils.isTrue(options.isValidateDynamicSchema())) {
                validateWithDynamicSchemas(object, objectElement, repository, objectResult);
            }
            objectResult.computeStatus();
            if (!objectResult.isAcceptable()) {
                return EventResult.skipObject(objectResult.getMessage());
            }
            if (options != null && BooleanUtils.isTrue(options.isEncryptProtectedValues())) {
                OperationResult opResult = objectResult.createMinorSubresult(ObjectImporter.class.getName() + ".encryptValues");
                try {
                    CryptoUtil.encryptValues(protector, object);
                    opResult.recordSuccess();
                } catch (EncryptionException e) {
                    opResult.recordFatalError(e);
                }
            }
            if (options == null || (options != null && !BooleanUtils.isTrue(options.isKeepMetadata()))) {
                MetadataType metaData = new MetadataType();
                String channel = SchemaConstants.CHANNEL_OBJECT_IMPORT_URI;
                metaData.setCreateChannel(channel);
                metaData.setCreateTimestamp(clock.currentTimeXMLGregorianCalendar());
                if (task.getOwner() != null) {
                    metaData.setCreatorRef(ObjectTypeUtil.createObjectRef(task.getOwner()));
                }
                object.asObjectable().setMetadata(metaData);
            }
            objectResult.computeStatus();
            if (!objectResult.isAcceptable()) {
                return EventResult.skipObject(objectResult.getMessage());
            }
            try {
                importObjectToRepository(object, options, raw, task, objectResult);
                LOGGER.info("Imported object {}", object);
            } catch (SchemaException e) {
                objectResult.recordFatalError("Schema violation: " + e.getMessage(), e);
                LOGGER.error("Import of object {} failed: Schema violation: {}", object, e.getMessage(), e);
            } catch (ObjectAlreadyExistsException e) {
                objectResult.recordFatalError("Object already exists: " + e.getMessage(), e);
                LOGGER.error("Import of object {} failed: Object already exists: {}", object, e.getMessage(), e);
                LOGGER.error("Object already exists", e);
            } catch (RuntimeException e) {
                objectResult.recordFatalError("Unexpected problem: " + e.getMessage(), e);
                LOGGER.error("Import of object {} failed: Unexpected problem: {}", object, e.getMessage(), e);
            } catch (ObjectNotFoundException e) {
                LOGGER.error("Import of object {} failed: Object referred from this object was not found: {}", object, e.getMessage(), e);
            } catch (ExpressionEvaluationException e) {
                LOGGER.error("Import of object {} failed: Expression evaluation error: {}", object, e.getMessage(), e);
            } catch (CommunicationException e) {
                LOGGER.error("Import of object {} failed: Communication error: {}", object, e.getMessage(), e);
            } catch (ConfigurationException e) {
                LOGGER.error("Import of object {} failed: Configuration error: {}", object, e.getMessage(), e);
            } catch (PolicyViolationException e) {
                LOGGER.error("Import of object {} failed: Policy violation: {}", object, e.getMessage(), e);
            } catch (SecurityViolationException e) {
                LOGGER.error("Import of object {} failed: Security violation: {}", object, e.getMessage(), e);
            }
            objectResult.recordSuccessIfUnknown();
            if (objectResult.isAcceptable()) {
                // Continue import
                return EventResult.cont();
            } else {
                return EventResult.skipObject(objectResult.getMessage());
            }
        }

        @Override
        public void handleGlobalError(OperationResult currentResult) {
        // No reaction
        }
    };
    Validator validator = new Validator(prismContext, handler);
    validator.setVerbose(true);
    if (options != null) {
        validator.setValidateSchema(BooleanUtils.isTrue(options.isValidateStaticSchema()));
        if (options.getStopAfterErrors() != null) {
            validator.setStopAfterErrors(options.getStopAfterErrors().longValue());
        }
        if (BooleanUtils.isTrue(options.isSummarizeErrors())) {
            parentResult.setSummarizeErrors(true);
        }
        if (BooleanUtils.isTrue(options.isSummarizeSucceses())) {
            parentResult.setSummarizeSuccesses(true);
        }
    }
    validator.validate(input, parentResult, OperationConstants.IMPORT_OBJECT);
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) EventHandler(com.evolveum.midpoint.common.validator.EventHandler) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) Validator(com.evolveum.midpoint.common.validator.Validator)

Example 18 with EncryptionException

use of com.evolveum.midpoint.prism.crypto.EncryptionException in project midpoint by Evolveum.

the class ModelInteractionServiceImpl method checkPassword.

@Override
public boolean checkPassword(String userOid, ProtectedStringType password, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
    OperationResult result = parentResult.createMinorSubresult(CHECK_PASSWORD);
    UserType userType;
    try {
        userType = objectResolver.getObjectSimple(UserType.class, userOid, null, task, result);
    } catch (ObjectNotFoundException e) {
        result.recordFatalError(e);
        throw e;
    }
    if (userType.getCredentials() == null || userType.getCredentials().getPassword() == null || userType.getCredentials().getPassword().getValue() == null) {
        return password == null;
    }
    ProtectedStringType currentPassword = userType.getCredentials().getPassword().getValue();
    boolean cmp;
    try {
        cmp = protector.compare(password, currentPassword);
    } catch (EncryptionException e) {
        result.recordFatalError(e);
        throw new SystemException(e.getMessage(), e);
    }
    result.recordSuccess();
    return cmp;
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 19 with EncryptionException

use of com.evolveum.midpoint.prism.crypto.EncryptionException in project midpoint by Evolveum.

the class AuthenticationEvaluatorImpl method decryptAndMatch.

//	protected boolean matchDecryptedValue(ConnectionEnvironment connEnv, @NotNull MidPointPrincipal principal, String decryptedValue,
//			String enteredPassword){
//		return enteredPassword.equals(decryptedValue);
//	}
//	
protected boolean decryptAndMatch(ConnectionEnvironment connEnv, @NotNull MidPointPrincipal principal, ProtectedStringType protectedString, String enteredPassword) {
    ProtectedStringType entered = new ProtectedStringType();
    entered.setClearValue(enteredPassword);
    try {
        return protector.compare(entered, protectedString);
    } catch (SchemaException | EncryptionException e) {
        recordAuthenticationFailure(principal, connEnv, "error decrypting password: " + e.getMessage());
        throw new AuthenticationServiceException("web.security.provider.unavailable", e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException)

Example 20 with EncryptionException

use of com.evolveum.midpoint.prism.crypto.EncryptionException in project midpoint by Evolveum.

the class AuthenticationEvaluatorImpl method getDecryptedValue.

protected String getDecryptedValue(ConnectionEnvironment connEnv, @NotNull MidPointPrincipal principal, ProtectedStringType protectedString) {
    String decryptedPassword;
    if (protectedString.getEncryptedDataType() != null) {
        try {
            decryptedPassword = protector.decryptString(protectedString);
        } catch (EncryptionException e) {
            recordAuthenticationFailure(principal, connEnv, "error decrypting password: " + e.getMessage());
            throw new AuthenticationServiceException("web.security.provider.unavailable", e);
        }
    } else {
        LOGGER.warn("Authenticating user based on clear value. Please check objects, " + "this should not happen. Protected string should be encrypted.");
        decryptedPassword = protectedString.getClearValue();
    }
    return decryptedPassword;
}
Also used : EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException)

Aggregations

EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)20 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)6 Protector (com.evolveum.midpoint.prism.crypto.Protector)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ArrayList (java.util.ArrayList)5 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)4 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 SecurityQuestionAnswerDTO (com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO)3 List (java.util.List)3 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 MailConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.MailConfigurationType)2 MailServerConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.MailServerConfigurationType)2 SecurityQuestionAnswerType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType)2 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 GuardedString (org.identityconnectors.common.security.GuardedString)2