Search in sources :

Example 1 with SchoolDataBridgeUnauthorizedException

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();
    }
}
Also used : SchoolDataSource(fi.otavanopisto.muikku.model.base.SchoolDataSource) UserPendingPasswordChange(fi.otavanopisto.muikku.plugins.user.UserPendingPasswordChange) SchoolDataBridgeUnauthorizedException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 2 with SchoolDataBridgeUnauthorizedException

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());
    }
}
Also used : UserAddress(fi.otavanopisto.muikku.schooldata.entity.UserAddress) Address(fi.otavanopisto.pyramus.rest.model.Address) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) SchoolDataBridgeUnauthorizedException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException) PyramusRestClientUnauthorizedException(fi.otavanopisto.muikku.plugins.schooldatapyramus.rest.PyramusRestClientUnauthorizedException)

Example 3 with SchoolDataBridgeUnauthorizedException

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;
}
Also used : UserPendingPasswordChange(fi.otavanopisto.muikku.plugins.user.UserPendingPasswordChange) SchoolDataBridgeUnauthorizedException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 4 with SchoolDataBridgeUnauthorizedException

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();
    }
}
Also used : UserPendingPasswordChange(fi.otavanopisto.muikku.plugins.user.UserPendingPasswordChange) SchoolDataBridgeUnauthorizedException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 5 with SchoolDataBridgeUnauthorizedException

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());
    }
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) SchoolDataBridgeUnauthorizedException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException) UserCredentials(fi.otavanopisto.pyramus.rest.model.UserCredentials) PyramusRestClientUnauthorizedException(fi.otavanopisto.muikku.plugins.schooldatapyramus.rest.PyramusRestClientUnauthorizedException)

Aggregations

SchoolDataBridgeUnauthorizedException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException)6 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)3 UserPendingPasswordChange (fi.otavanopisto.muikku.plugins.user.UserPendingPasswordChange)3 PyramusRestClientUnauthorizedException (fi.otavanopisto.muikku.plugins.schooldatapyramus.rest.PyramusRestClientUnauthorizedException)2 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)2 SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 SchoolDataSource (fi.otavanopisto.muikku.model.base.SchoolDataSource)1 SchoolDataBridgeException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeException)1 UserAddress (fi.otavanopisto.muikku.schooldata.entity.UserAddress)1 Address (fi.otavanopisto.pyramus.rest.model.Address)1 UserCredentials (fi.otavanopisto.pyramus.rest.model.UserCredentials)1 Builder (javax.ws.rs.client.Invocation.Builder)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1