Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclude_extra_attributes_from_session option to RackCAS configuration #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ In your `config/application.rb`:
config.rack_cas.extra_attributes_filter = %w(some_attribute some_other_attribute)
```

Depending on your CAS implementation and space considerations, you can also choose to exclude **all** extra attributes from being saved in the session store.
```ruby
config.rack_cas.exclude_extra_attributes_from_session = true
```

Excluding Paths
---------------

Expand Down
7 changes: 4 additions & 3 deletions lib/rack-cas/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module RackCAS
class Configuration
SETTINGS = [:fake, :fake_attributes, :server_url, :session_store, :exclude_path, :exclude_paths, :extra_attributes_filter,
:verify_ssl_cert, :renew, :use_saml_validation, :ignore_intercept_validator, :exclude_request_validator, :protocol,
:redis_options, :login_url, :service]
SETTINGS = [:fake, :fake_attributes, :server_url, :session_store, :exclude_path, :exclude_paths,
:extra_attributes_filter, :exclude_extra_attributes_from_session, :verify_ssl_cert,
:renew, :use_saml_validation, :ignore_intercept_validator, :exclude_request_validator,
:protocol, :redis_options, :login_url, :service]


SETTINGS.each do |setting|
Expand Down
6 changes: 5 additions & 1 deletion lib/rack/cas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ def store_session(request, user, ticket, extra_attrs = {})
extra_attrs.select! { |key, val| RackCAS.config.extra_attributes_filter.map(&:to_s).include? key.to_s }
end

request.session['cas'] = { 'user' => user, 'ticket' => ticket, 'extra_attributes' => extra_attrs }
request.session['cas'] = {
'user' => user,
'ticket' => ticket,
'extra_attributes' => RackCAS.config.exclude_extra_attributes_from_session? ? {} : extra_attrs
}
end

def redirect_to(url, status=302)
Expand Down
8 changes: 8 additions & 0 deletions spec/rack/cas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def app
it { should_not have_key 'title' }
end

context 'with exclude_extra_attributes_from_session set' do
let(:app_options) { { exclude_extra_attributes_from_session: true } }

before { get '/private?ticket=ST-0123456789ABCDEFGHIJKLMNOPQRS' }
subject { last_request.session['cas']['extra_attributes'] }
it { should be_empty }
end

context 'with an invalid ticket' do
before { RackCAS::ServiceValidationResponse.any_instance.stub(:user) { raise RackCAS::ServiceValidationResponse::TicketInvalidError } }
its(:status) { should eql 302 }
Expand Down