Add option to respect Drupal's registration configuration when auto-registration is enabled

Created on 7 March 2019, about 6 years ago
Updated 28 May 2024, 11 months ago

The Drupal configuration allows new user creation to require Administration approval. This option makes it so that newly created users are blocked by default and are then activated by an administrator with the appropriate permissions.

However, when using CAS and enabling the Auto Register Users option, newly registered users are always active on creation, disregarding whatever configuration option is set in the site at the moment.

Is this an intented behavior? If so, could we explain the rationale behind it?

✨ Feature request
Status

Fixed

Version

2.0

Component

CAS

Created by

πŸ‡¬πŸ‡§United Kingdom ieguskiza

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    claudiu.cristea β†’ made their first commit to this issue’s fork.

  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    I think this is a legit request. Recently, we were spammed by tons of accounts being created in Drupal but we have no control over the CAS server. We would like to be able to moderate registration of the users that are auto-creating accounts. Trying to get some code.

  • Merge request !23Be aware of admin approval setting β†’ (Merged) created by claudiu.cristea
  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄
    • Needs tests
    • BC issue: Some sites might have the Who can register accounts? set to _Visitors, but administrator approval is required_, knowing that, with CAS module, that setting have no effect. If we merge this change their new accounts will be suddenly moderated. Even their config is wrong, we have to deal with this but how? Should se provide an update script and set the option to _Visitors_? Then the behavior will bot change.
  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    I think this is a legit request. Recently, we were spammed by tons of accounts being created in Drupal but we have no control over the CAS server.

    - why do you have auto registration turned on?

  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    > why do you have auto registration turned on?

    Because we only allow CAS registration.

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    No, what I mean is, why do you have CAS configured to allow anyone with a CAS account to have an account auto created? Why don't you require that an administrator manually register users to the site that require access?

    I'm just playing devil's advocate to verify we really need the additional complexity this adds

  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    Everyone on Earth with a CAS account should be able to register. There's no admin pre-register. People are coming on the site and, if they want to login, the click the link, are redirected to the CAS server where they login ore register new CAS user. Then they are redirected back to our site. If they have a local account they are logging in. In the case there's no local account, we auto-creare one and log them in. But in some critical circumstances, admins want to moderate the registration. . This is a native Drupal feature. As I told, we cannot do that on CAS Server level as the server is a service that we don't control. We would like to turn the switch and CAS to honour that configuration.

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    Okay. I guess it makes sense to add this support for such cases. It's just a little odd of course, because the user already "logged in" via CAS, but is being denied an account on the site. But I understand the use case now.

    For existing sites, the safest solution to to make this opt-in via a feature flag checkbox that's revealed if the user enables auto-registration. "Respect user moderation setting" or something? I think implementing this change without considering the number of existing sites that might break is not a good idea

  • Issue was unassigned.
  • Status changed to Needs review over 2 years ago
  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    Added tests.

    For existing sites, the safest solution to to make this opt-in via a feature flag checkbox that's revealed if the user enables auto-registration. "Respect user moderation setting" or something?

    That works when CAS is being configured. But how about the sites already configured with auto-registration and admin approval set?

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    Then the new feature flag we have set will be "off", thus disabling this new event subscriber, and behavior is unchanged. Basically I'm suggesting we have a checkbox to controls if this event subscriber is used or not.

  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    @bkosborne, a kill-switch is a good idea, thanks

  • Status changed to RTBC about 2 years ago
  • πŸ‡΅πŸ‡ΉPortugal saidatom Lisbon

    Nice work, MR solves the issue for us. It is RTBC.

  • Status changed to Needs work about 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    Two things from my review:

    Missing post-update hook

    Can you add a post_update hook to set new config option in cas.settings.yml for existing sites? I understand it's false by default, and retrieving it from settings when it doesn't exist will return null (which is falsy), but I think it's best if we set the default config anyway on existing sites.

    Confusing behavior

    After a user tries logging in via CAS after the initial attempt, they are denied login, but there's no error message displayed. That's because you're returning an empty string for this type of login failure in ServiceController::getLoginErrorMessage(). I understand you did this because your event subscriber returns a message instead. However, it only does this when the account is initially being registered. After it's already registered, the event subscriber doesn't fire (which is good), but now the user gets no wording.

    I think we need to do something for that use case. How about altering this:

        if ($this->isAdminApprovalNeeded() && $account->isBlocked()) {
          // Cannot log in until the admins are not approving the new account. Note
          // that CAS module provides, by default, the normal Drupal behavior by
          // showing a status message and, if configured, sending email
          // notifications to user and admins. This is achieved by listening to
          // ExternalAuthEvents::REGISTER event. Third-party may override this
          // behavior by providing a subscriber with a higher priority, implementing
          // their logic and stopping the event propagation.
          // @see \Drupal\cas\Subscriber\CasAdminApprovalRegistrationSubscriber
          $this->casHelper->log(LogLevel::DEBUG, 'Login denied as new account needs admin approval.');
          throw new CasLoginException("Cannot login, admin approval is required for new accounts", CasLoginException::ADMIN_APPROVAL_REQUIRED);
        }
    

    So it only executes if it's a brand new account being registered (not for existing account logins).

    Then, existing accounts that attempt to login but are already blocked will allow this existing code to execute:

        // Check if the retrieved user is blocked before moving forward.
        if (!$account->isActive()) {
          throw new CasLoginException(sprintf('The username %s has not been activated or is blocked.', $account->getAccountName()), CasLoginException::ACCOUNT_BLOCKED);
        }
    

    Which will present the proper account blocked message to the user (which admins can configure).

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update almost 2 years ago
    102 pass
  • First commit to issue fork.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    102 pass
  • πŸ‡§πŸ‡ͺBelgium lobsterr

    In the previous commit the text fields were replaced with textareas, we need to adapt config schema for them.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    102 pass
  • Status changed to Needs review over 1 year ago
  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    Addressed remarks from #21. Ready for review.

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    Merged in the latest 2.x to this branch, and tests still pass. Looks good to me. Thanks all.

  • Pipeline finished with Skipped
    12 months ago
    #172725
  • Status changed to Fixed 12 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024