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);
}
}
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;
}
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;
}
}
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;
}
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;
}
Aggregations