@SuppressWarnings("unchecked")
    public void activateUser(String tokenValue) throws Exception {

        RegistrationToken token = registrationTokenService.findByTokenValue(tokenValue);

        LOG.debug("Trying to activate user account with token: " + tokenValue);

        // throws Exception if token is not valid
        registrationTokenService.validateToken(token);

        // set active=true
        E user = (E) token.getUser();
        user.setActive(true);

        // set the persisted default user role if available
        if (defaultUserRole != null) {
            final String defaultRoleName = defaultUserRole.getName();
            Role persistedDefaultUserRole = roleService.findByRoleName(defaultRoleName);

            if (persistedDefaultUserRole != null) {
                // assign the default user role
                user.getRoles().add(persistedDefaultUserRole);
            }
        }

        // update the user
        dao.saveOrUpdate((E) user);

        // delete the token
        registrationTokenService.deleteTokenAfterActivation(token);

        LOG.info("The user '" + user.getAccountName()
            + "' has successfully been activated.");
    }
@ SuppressWarnings ( "unchecked" ) public void activateUser ( String tokenValue ) throws Exception { RegistrationToken token = registrationTokenService . findByTokenValue ( tokenValue ) ; LOG . debug ( "Trying to activate user account with token: " + tokenValue ) ; registrationTokenService . validateToken ( token ) ; E user = ( E ) token . getUser ( ) ; user . setActive ( true ) ; if ( defaultUserRole != null ) { final String defaultRoleName = defaultUserRole . getName ( ) ; Role persistedDefaultUserRole = roleService . findByRoleName ( defaultRoleName ) ; if ( persistedDefaultUserRole != null ) { user . getRoles ( ) . add ( persistedDefaultUserRole ) ; } } dao . saveOrUpdate ( ( E ) user ) ; registrationTokenService . deleteTokenAfterActivation ( token ) ; LOG . info ( "The user '" + user . getAccountName ( ) + "' has successfully been activated." ) ; }
@throws Exception