Skip to content

Commit

Permalink
Align Globus bugfix with OIDC generalization aces#1391
Browse files Browse the repository at this point in the history
Update bugfix to OICD generalization
  • Loading branch information
MontrealSergiy committed Oct 16, 2024
1 parent 5e57ae7 commit 0c89a63
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions BrainPortal/app/controllers/nh_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def edit #:nodoc:
def change_password #:nodoc:
@user = current_user
if user_must_link_to_oidc?(@user)
cb_error "Your account can only authenticate with Globus identities.", :redirect => { :action => :myaccount }
cb_error "Your account can only authenticate with OpenID identities (such as Globus).", :redirect => { :action => :myaccount }
end
end

Expand All @@ -88,8 +88,8 @@ def update
attr_to_update.delete(:zenodo_main_token) if attr_to_update[:zenodo_main_token].blank?

# Do not update password if user must use globus
if user_must_link_to_oidc?(@user)
flash[:error] = "You cannot change the password for your account." if attr_to_update[:password].present?
if user_must_link_to_oidc?(@user) && attr_to_update[:password]
flash[:error] = "You cannot change the password for your account because you should use OpenID." if attr_to_update[:password].present?
attr_to_update.delete(:password)
attr_to_update.delete(:password_confirmation)
end
Expand Down
6 changes: 3 additions & 3 deletions BrainPortal/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ def send_password #:nodoc:
@user = User.where( :login => params[:login], :email => params[:email] ).first

if @user
if user_must_link_to_globus?(@user)
if user_must_link_to_oidc?(@user)
contact = RemoteResource.current_resource.support_email.presence || User.admin.email.presence || "the support staff"
wipe_user_password_after_globus_link(@user) # for legacy or erroneously set users
flash[:error] = "Your account can only authenticate with Globus identities. Thus you are not allowed to use or reset password. Please contact #{contact} for help."
wipe_user_password_after_oidc_link("password-rest", @user) # for legacy or erroneously set users
flash[:error] = "Your account can only authenticate with OpenID identities. Thus you are not allowed to use or reset password. Please contact #{contact} for help."
respond_to do |format|
format.html { redirect_to login_path }
format.any { head :unauthorized }
Expand Down
5 changes: 3 additions & 2 deletions BrainPortal/lib/globus_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ def user_must_link_to_oidc?(user)
end

def wipe_user_password_after_oidc_link(oidc, user)
user.update_attribute(:crypted_password, "Wiped-By-#{oidc.name}-Link-" + User.random_string)
user.update_attribute(:salt , "Wiped-By-#{oidc.name}-Link-" + User.random_string)
wipe_by = oidc.is_a?(String) ? "Wiped-By-#{oidc}-Link-" : "Wiped-By-#{oidc.name}-Link-"
user.update_attribute(:crypted_password, wipe_by + User.random_string)
user.update_attribute(:salt , wipe_by + User.random_string)
user.update_attribute(:password_reset , false)
end

Expand Down
4 changes: 2 additions & 2 deletions BrainPortal/spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@
expect(assigns[:user].password).not_to eq(user.password)
end

context "when the account must use Globus identification only" do
context "when the account must use OIDC identification only" do

it "should display a message" do
allow(mock_user).to receive(:account_locked?).and_return(true)
allow(User).to receive_message_chain(:where, :first).and_return(mock_user)
post :send_password, params: {:login => user.login, :email => user.email}
expect(flash[:error]).to match(/Globus/i)
expect(flash[:error]).to match(/OpenID/i)
end

end
Expand Down

0 comments on commit 0c89a63

Please sign in to comment.