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