Search in sources :

Example 1 with ConfirmEmailData

use of edu.harvard.iq.dataverse.confirmemail.ConfirmEmailData in project dataverse by IQSS.

the class DataverseUserPage method showVerifyEmailButton.

/**
 * Determines whether the button to send a verification email appears on user page
 * @return
 */
public boolean showVerifyEmailButton() {
    final Timestamp emailConfirmed = currentUser.getEmailConfirmed();
    final ConfirmEmailData confirmedDate = confirmEmailService.findSingleConfirmEmailDataByUser(currentUser);
    return (!getUserAuthProvider().isEmailVerified()) && confirmedDate == null && emailConfirmed == null;
}
Also used : Timestamp(java.sql.Timestamp) ConfirmEmailData(edu.harvard.iq.dataverse.confirmemail.ConfirmEmailData)

Example 2 with ConfirmEmailData

use of edu.harvard.iq.dataverse.confirmemail.ConfirmEmailData in project dataverse by IQSS.

the class AuthenticationServiceBean method deleteAuthenticatedUser.

/**
 * Use with care! This method was written primarily for developers
 * interested in API testing who want to:
 *
 * 1. Create a temporary user and get an API token.
 *
 * 2. Do some work with that API token.
 *
 * 3. Delete all the stuff that was created with the API token.
 *
 * 4. Delete the temporary user.
 *
 * Before calling this method, make sure you've deleted all the stuff tied
 * to the user, including stuff they've created, role assignments, group
 * assignments, etc.
 *
 * Longer term, the intention is to have a "disableAuthenticatedUser"
 * method/command. See https://github.com/IQSS/dataverse/issues/2419
 */
public void deleteAuthenticatedUser(Object pk) {
    AuthenticatedUser user = em.find(AuthenticatedUser.class, pk);
    if (user != null) {
        ApiToken apiToken = findApiTokenByUser(user);
        if (apiToken != null) {
            em.remove(apiToken);
        }
        ConfirmEmailData confirmEmailData = confirmEmailService.findSingleConfirmEmailDataByUser(user);
        if (confirmEmailData != null) {
            /**
             * @todo This could probably be a cascade delete instead.
             */
            em.remove(confirmEmailData);
        }
        userNotificationService.findByUser(user.getId()).forEach(userNotificationService::delete);
        AuthenticationProvider prv = lookupProvider(user);
        if (prv != null && prv.isUserDeletionAllowed()) {
            prv.deleteUser(user.getAuthenticatedUserLookup().getPersistentUserId());
        }
        actionLogSvc.log(new ActionLogRecord(ActionLogRecord.ActionType.Auth, "deleteUser").setInfo(user.getUserIdentifier()));
        em.remove(user.getAuthenticatedUserLookup());
        em.remove(user);
    }
}
Also used : ActionLogRecord(edu.harvard.iq.dataverse.actionlogging.ActionLogRecord) BuiltinAuthenticationProvider(edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProvider) AbstractOAuth2AuthenticationProvider(edu.harvard.iq.dataverse.authorization.providers.oauth2.AbstractOAuth2AuthenticationProvider) ShibAuthenticationProvider(edu.harvard.iq.dataverse.authorization.providers.shib.ShibAuthenticationProvider) ApiToken(edu.harvard.iq.dataverse.authorization.users.ApiToken) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) ConfirmEmailData(edu.harvard.iq.dataverse.confirmemail.ConfirmEmailData)

Example 3 with ConfirmEmailData

use of edu.harvard.iq.dataverse.confirmemail.ConfirmEmailData in project dataverse by IQSS.

the class Admin method startConfirmEmailProcess.

/**
 * This method is used in integration tests.
 *
 * @param userId The database id of an AuthenticatedUser.
 */
@Path("confirmEmail/{userId}")
@POST
public Response startConfirmEmailProcess(@PathParam("userId") long userId) {
    AuthenticatedUser user = authSvc.findByID(userId);
    if (user != null) {
        try {
            ConfirmEmailInitResponse confirmEmailInitResponse = confirmEmailSvc.beginConfirm(user);
            ConfirmEmailData confirmEmailData = confirmEmailInitResponse.getConfirmEmailData();
            return ok(Json.createObjectBuilder().add("tokenCreated", confirmEmailData.getCreated().toString()).add("identifier", user.getUserIdentifier()));
        } catch (ConfirmEmailException ex) {
            return error(Status.BAD_REQUEST, "Could not start confirm email process for user " + userId + ": " + ex.getLocalizedMessage());
        }
    }
    return error(Status.BAD_REQUEST, "Could not find user based on " + userId);
}
Also used : ConfirmEmailException(edu.harvard.iq.dataverse.confirmemail.ConfirmEmailException) ConfirmEmailInitResponse(edu.harvard.iq.dataverse.confirmemail.ConfirmEmailInitResponse) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) ConfirmEmailData(edu.harvard.iq.dataverse.confirmemail.ConfirmEmailData) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

ConfirmEmailData (edu.harvard.iq.dataverse.confirmemail.ConfirmEmailData)3 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 ActionLogRecord (edu.harvard.iq.dataverse.actionlogging.ActionLogRecord)1 BuiltinAuthenticationProvider (edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProvider)1 AbstractOAuth2AuthenticationProvider (edu.harvard.iq.dataverse.authorization.providers.oauth2.AbstractOAuth2AuthenticationProvider)1 ShibAuthenticationProvider (edu.harvard.iq.dataverse.authorization.providers.shib.ShibAuthenticationProvider)1 ApiToken (edu.harvard.iq.dataverse.authorization.users.ApiToken)1 ConfirmEmailException (edu.harvard.iq.dataverse.confirmemail.ConfirmEmailException)1 ConfirmEmailInitResponse (edu.harvard.iq.dataverse.confirmemail.ConfirmEmailInitResponse)1 Timestamp (java.sql.Timestamp)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1