use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException in project muikku by otavanopisto.
the class ForgotPasswordRESTService method confirmResetPassword.
@Path("/confirm")
@GET
@RESTPermitUnimplemented
public Response confirmResetPassword(ConfirmResetPassword crp) {
UserPendingPasswordChange passwordChange = userPendingPasswordChangeDAO.findByConfirmationHash(crp.getResetCode());
UserEntity userEntity = userEntityController.findUserEntityById(passwordChange.getUserEntity());
// TODO: tis a guesstimate of the datasource
SchoolDataSource schoolDataSource = userEntity.getDefaultSchoolDataSource();
try {
userSchoolDataController.confirmResetPassword(schoolDataSource, crp.getResetCode(), crp.getNewPassword());
return Response.noContent().build();
} catch (SchoolDataBridgeUnauthorizedException e) {
return Response.status(Status.FORBIDDEN).build();
}
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException in project muikku by otavanopisto.
the class PyramusUserSchoolDataBridge method updateUserAddress.
@Override
public void updateUserAddress(SchoolDataIdentifier studentIdentifier, SchoolDataIdentifier identifier, String street, String postalCode, String city, String country) {
Long addressId = identifierMapper.getPyramusAddressId(identifier.getIdentifier());
Long studentId = identifierMapper.getPyramusStudentId(studentIdentifier.getIdentifier());
if (addressId == null) {
throw new SchoolDataBridgeInternalException(String.format("Malformed identifier %s", identifier));
}
if (studentId == null) {
throw new SchoolDataBridgeInternalException(String.format("Malformed identifier %s", studentIdentifier));
}
try {
Address address = pyramusClient.get(String.format("/students/students/%d/addresses/%d", studentId, addressId), Address.class);
if (address == null) {
throw new SchoolDataBridgeInternalException(String.format("Address %d of student %d not found", addressId, studentId));
}
address.setStreetAddress(street);
address.setPostalCode(postalCode);
address.setCity(city);
address.setCountry(country);
pyramusClient.put(String.format("/students/students/%d/addresses/%s", studentId, addressId), address);
} catch (PyramusRestClientUnauthorizedException purr) {
throw new SchoolDataBridgeUnauthorizedException(purr.getMessage());
}
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException in project muikku by otavanopisto.
the class ForgotPasswordController method resetPassword.
public boolean resetPassword(String confirmationHash, String password) {
UserPendingPasswordChange userPendingPasswordChange = userPendingPasswordChangeDAO.findByConfirmationHash(confirmationHash);
if (userPendingPasswordChange != null) {
UserEntity userEntity = userEntityController.findUserEntityById(userPendingPasswordChange.getUserEntity());
if (userEntity == null) {
logger.severe(String.format("UserPendingPasswordChange with hash %s contained invalid userEnityId", confirmationHash));
return false;
}
try {
userSchoolDataController.confirmResetPassword(userEntity.getDefaultSchoolDataSource(), confirmationHash, password);
} catch (SchoolDataBridgeUnauthorizedException e) {
logger.log(Level.SEVERE, "Failed to process password reset request", e);
return false;
}
userPendingPasswordChangeDAO.delete(userPendingPasswordChange);
return true;
}
return false;
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException in project muikku by otavanopisto.
the class ForgotPasswordRESTService method resetPassword.
@Path("/reset")
@GET
@RESTPermitUnimplemented
public Response resetPassword(@QueryParam("email") String email) {
UserEntity userEntity = userEntityController.findUserEntityByEmailAddress(email);
if (userEntity == null)
return Response.status(Status.NOT_FOUND).build();
try {
UserPendingPasswordChange passwordChange = userPendingPasswordChangeDAO.findByUserEntity(userEntity);
schoolDataBridgeSessionController.startSystemSession();
try {
String confirmationHash = userSchoolDataController.requestPasswordResetByEmail(userEntity.getDefaultSchoolDataSource(), email);
if (passwordChange != null)
passwordChange = userPendingPasswordChangeDAO.updateHash(passwordChange, confirmationHash);
else
passwordChange = userPendingPasswordChangeDAO.create(userEntity, confirmationHash);
// TODO Email could be added to the reset link for added security (email+hash rather than just hash)
String resetLink = baseUrl + "/forgotpassword/reset?h=" + passwordChange.getConfirmationHash();
String mailSubject = localeController.getText(sessionController.getLocale(), "plugin.forgotpassword.mailSubject");
String mailContent = localeController.getText(sessionController.getLocale(), "plugin.forgotpassword.mailContent", new String[] { resetLink });
// TODO System sender address needs to be configurable
mailer.sendMail(systemSettingsController.getSystemEmailSenderAddress(), email, mailSubject, mailContent);
} finally {
schoolDataBridgeSessionController.endSystemSession();
}
return Response.noContent().build();
} catch (SchoolDataBridgeUnauthorizedException e) {
return Response.status(Status.FORBIDDEN).build();
}
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException in project muikku by otavanopisto.
the class PyramusUserSchoolDataBridge method updateUserCredentials.
@Override
public void updateUserCredentials(String userIdentifier, String oldPassword, String newUsername, String newPassword) {
Long personId = getPersonId(userIdentifier);
if (personId == null) {
logger.warning(String.format("PyramusUserSchoolDataBridge.updateUserCredentials malformed user identifier %s", userIdentifier));
throw new SchoolDataBridgeInternalException(String.format("Malformed user identifier %s\n%s", userIdentifier, ExceptionUtils.getStackTrace(new Throwable())));
}
try {
UserCredentials change = new UserCredentials(oldPassword, newUsername, newPassword);
pyramusClient.put("/persons/persons/" + personId + "/credentials", change);
} catch (PyramusRestClientUnauthorizedException purr) {
throw new SchoolDataBridgeUnauthorizedException(purr.getMessage());
}
}
Aggregations