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?
Issue fork cas-3038279
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
cjokinen commentedIt depends on how you setup the cas module. Looking at auto register user setting it states...
Enable to automatically create local Drupal accounts for first-time CAS logins. If disabled, users must be pre-registered before being allowed to log in.
I am not certain how a pre-register would work as I do not use it. I have auto register enabled. User gets into our site from the sso running cas server and the sso makes use of a migration from a custom database. The flow kinda looks like this
We also use the cas attribute module to map roles and migrate additional information like company name, title, first and last names, etc..
Comment #3
ieguskiza commentedHi,
I think I may have not explain the problem properly. Let me write down an scenario:
- Create a new Drupal site with CAS enabled.
- Configure the site to require administrator approval on new users (this is a Drupal configuration, not CAS).
- Register a new user through the form (user/register)
- The new user is created but is blocked (waiting for administrator approval): this is the expected behavior.
- Configure CAS to Auto Register Users (this is CAS configuration). This means that users that are in CAS but not on Drupal will be automatically registered if they log in.
- Try to log in through CAS with a user that is not on Drupal yet
- The user is created and is active: this goes against the Drupal configuration.
The question is: is this intended, and if so, why? A site administrator may not understand why new users created through CAS are active by default when they configured the site to require adminstrator approval.
Hopefully this will make it easier to understand :)
Comment #4
bkosborneWell, at the very least, I think we could add a message to the CAS configuration page for auto-registration that indicates that the core settings is not respected. That would avoid any confusion.
Beyond that, I'm inclined to keep such a change out of the CAS module since it seems like a somewhat niche use-case. If you could expand on your organizations specific use case maybe that would help me see how this would be useful?
You can already programmatically do this by subscribing to the preregister event and changing their status to 0 there, and that's only a small bit of code.
Comment #5
ieguskiza commentedHi @bkosborne
indeed we are already using the pregister event to solve the issue, but this always shows the "There was a problem logging in, please contact a site administrator." error message even though, in reality, there is no error. We added our own custom message to further explain the situation to users ("Thank you for applying for an account. Your account is currently pending approval by the site administrator.") but its still quite confusing to see seemingly contradictory messages at the same time.
Our organization is divided in several directorates and all of them have their own portals, but the CAS server is common to all of them. What's more, the CAS service allows to create users on the fly by using social media. This coupled with the Auto Register feature means that basically anyone can create a user in the portals that are configured to do so.
Now, we could also circunvent the issue by auto assigning roles with no permissions based on data from the server (directorate, email domain , etc), but one would think that the CAS module should follow the Drupal configuration and add on top of it, not simply ignore it.
I don't believe this a major issue since it has several alternate (although not fully satisfactory) solutions, but I would like to know your opinion on it and if you would consider adding support for it in the long run. I could propose a patch with an initial approach to solve the issue if you think this could help :)
Comment #6
bkosborneIf you can programmatically determine if user attempting to log in to your site is a valid user for that site, then wouldn't you prefer to not have the local accounts created at all, just like you're doing now with the pre register event? If instead the site allowed registration and blocked the users that are not allowed, then someone would have to go in and periodically clean out the invalid users.
If you could control the error message that's displayed based on various different scenarios, I suspect that you'd be much happier, no?
If so, I think the best use of time would be spent on fixing #3013524: Allow specifying custom error and login messages, which would allow site admins to specify custom wording for the messages that the CAS module prints out.
Comment #7
bkosborneI committed #3013524: Allow specifying custom error and login messages, which allows you to customize the messaging displayed to the user when a module prevents registration. It displays it as an error message instead of a status message. If you'd like to display a status message instead, you could blank out the error message that CAS provides in the settings, and then continue adding your own via your subscriber.
I think I'm going to close this as won't fix due to the workarounds in place and to avoid adding complexity to the module configuration.
Comment #9
claudiu.cristeaI 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.
Comment #11
claudiu.cristeaComment #12
bkosborne- why do you have auto registration turned on?
Comment #13
claudiu.cristea> why do you have auto registration turned on?
Because we only allow CAS registration.
Comment #14
bkosborneNo, 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
Comment #15
claudiu.cristeaEveryone 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, they click the link, are redirected to the CAS server where they login or register a 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 (CAS) auto-create 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.
Comment #16
bkosborneOkay. 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
Comment #17
claudiu.cristeaAdded tests.
That works when CAS is being configured. But how about the sites already configured with auto-registration and admin approval set?
Comment #18
bkosborneThen 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.
Comment #19
claudiu.cristea@bkosborne, a kill-switch is a good idea, thanks
Comment #20
saidatomNice work, MR solves the issue for us. It is RTBC.
Comment #21
bkosborneTwo 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 a second time (after their account was registered but blocked), 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 makes sense), but now the user gets no error message.
How about altering this code:
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:
Which will present the proper account blocked message to the user (which admins can configure).
Comment #23
lobsterr commentedIn the previous commit the text fields were replaced with textareas, we need to adapt config schema for them.
Comment #24
claudiu.cristeaAddressed remarks from #21. Ready for review.
Comment #25
bkosborneMerged in the latest 2.x to this branch, and tests still pass. Looks good to me. Thanks all.