Search in sources :

Example 1 with EncryptionException

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

the class XNodeProcessorUtil method transformEncryptedValue.

private static void transformEncryptedValue(ProtectedDataType protectedType, PrismContext prismContext) throws SchemaException {
    Protector protector = prismContext.getDefaultProtector();
    if (protector == null) {
        return;
    }
    //		protector.init();
    try {
        protector.decrypt(protectedType);
        Object clearValue = protectedType.getClearValue();
        if (clearValue instanceof String) {
            String clear = (String) clearValue;
            if (clear.startsWith("<value>") && clear.endsWith("</value>")) {
                clear = clear.replace("<value>", "").replace("</value>", "");
                clearValue = (String) clear;
            }
            protectedType.setClearValue(clearValue);
            protector.encrypt(protectedType);
        }
    } catch (EncryptionException ex) {
        //System.out.println("failed to encrypt..");
        throw new IllegalArgumentException("failed to encrypt. " + ex);
    }
}
Also used : EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) Protector(com.evolveum.midpoint.prism.crypto.Protector)

Example 2 with EncryptionException

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

the class AuthenticationEvaluatorImpl method getPassword.

private String getPassword(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)

Example 3 with EncryptionException

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

the class PageSecurityQuestions method createUsersSecurityQuestionsList.

public List<SecurityQuestionAnswerDTO> createUsersSecurityQuestionsList(PrismObject<UserType> user) {
    SecurityQuestionsCredentialsType credentialsPolicyType = user.asObjectable().getCredentials().getSecurityQuestions();
    if (credentialsPolicyType == null) {
        return null;
    }
    List<SecurityQuestionAnswerType> secQuestAnsList = credentialsPolicyType.getQuestionAnswer();
    if (secQuestAnsList != null) {
        List<SecurityQuestionAnswerDTO> secQuestAnswListDTO = new ArrayList<SecurityQuestionAnswerDTO>();
        for (Iterator iterator = secQuestAnsList.iterator(); iterator.hasNext(); ) {
            SecurityQuestionAnswerType securityQuestionAnswerType = (SecurityQuestionAnswerType) iterator.next();
            Protector protector = getPrismContext().getDefaultProtector();
            String decoded = "";
            if (securityQuestionAnswerType.getQuestionAnswer().getEncryptedDataType() != null) {
                try {
                    decoded = protector.decryptString(securityQuestionAnswerType.getQuestionAnswer());
                } catch (EncryptionException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            secQuestAnswListDTO.add(new SecurityQuestionAnswerDTO(securityQuestionAnswerType.getQuestionIdentifier(), decoded));
        }
        return secQuestAnswListDTO;
    } else {
        return null;
    }
}
Also used : SecurityQuestionsCredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionsCredentialsType) SecurityQuestionAnswerDTO(com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) SecurityQuestionAnswerType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType) Protector(com.evolveum.midpoint.prism.crypto.Protector)

Example 4 with EncryptionException

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

the class AbstractIntegrationTest method repoAddObjectsFromFile.

// these objects can be of various types
protected List<PrismObject> repoAddObjectsFromFile(File file, OperationResult parentResult) throws SchemaException, ObjectAlreadyExistsException, IOException {
    OperationResult result = parentResult.createSubresult(AbstractIntegrationTest.class.getName() + ".addObjectsFromFile");
    result.addParam("file", file);
    LOGGER.trace("addObjectsFromFile: {}", file);
    List<PrismObject> objects = (List) PrismTestUtil.parseObjects(file);
    for (PrismObject object : objects) {
        try {
            repoAddObject(object, result);
        } catch (ObjectAlreadyExistsException e) {
            throw new ObjectAlreadyExistsException(e.getMessage() + " while adding " + object + " from file " + file, e);
        } catch (SchemaException e) {
            new SchemaException(e.getMessage() + " while adding " + object + " from file " + file, e);
        } catch (EncryptionException e) {
            new EncryptionException(e.getMessage() + " while adding " + object + " from file " + file, e);
        }
    }
    result.recordSuccess();
    return objects;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ArrayList(java.util.ArrayList) List(java.util.List) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 5 with EncryptionException

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

the class ExpressionUtil method convertValue.

/**
	 * Slightly more powerful version of "convert" as compared to
	 * JavaTypeConverter. This version can also encrypt/decrypt and also handles
	 * polystrings.
	 */
public static <I, O> O convertValue(Class<O> finalExpectedJavaType, Function<Object, Object> additionalConvertor, I inputVal, Protector protector, PrismContext prismContext) {
    if (inputVal == null) {
        return null;
    }
    if (finalExpectedJavaType.isInstance(inputVal)) {
        return (O) inputVal;
    }
    Object intermediateVal;
    if (finalExpectedJavaType == ProtectedStringType.class) {
        String valueToEncrypt;
        if (inputVal instanceof String) {
            valueToEncrypt = (String) inputVal;
        } else {
            valueToEncrypt = JavaTypeConverter.convert(String.class, inputVal);
        }
        try {
            intermediateVal = protector.encryptString(valueToEncrypt);
        } catch (EncryptionException e) {
            throw new SystemException(e.getMessage(), e);
        }
    } else if (inputVal instanceof ProtectedStringType) {
        try {
            intermediateVal = protector.decryptString((ProtectedStringType) inputVal);
        } catch (EncryptionException e) {
            throw new SystemException(e.getMessage(), e);
        }
    } else {
        intermediateVal = inputVal;
    }
    if (additionalConvertor != null) {
        intermediateVal = additionalConvertor.apply(intermediateVal);
    }
    O convertedVal = JavaTypeConverter.convert(finalExpectedJavaType, intermediateVal);
    PrismUtil.recomputeRealValue(convertedVal, prismContext);
    return convertedVal;
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

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