Feature #2356 » redmine-add-cas-support.patch
| app/controllers/account_controller.rb | ||
|---|---|---|
|
helper :custom_fields
|
||
|
include CustomFieldsHelper
|
||
|
|
||
|
@cas_initialized = false
|
||
|
class << self; attr_accessor :cas_initialized; end
|
||
|
# prevents login action to be filtered by check_if_login_required application scope filter
|
||
|
skip_before_filter :check_if_login_required
|
||
|
# Login request and validation
|
||
|
def login
|
||
|
# If we are forcing CAS authentication, bypass everything else and go to it.
|
||
|
if Setting.cas? && Setting.cas_force != '0'
|
||
|
cas_authenticate
|
||
|
end
|
||
|
if request.get?
|
||
|
# Logout user
|
||
|
self.logged_user = nil
|
||
| ... | ... | |
|
redirect_to :action => 'login'
|
||
|
end
|
||
|
|
||
|
def cas_authenticate
|
||
|
unless self.class.cas_initialized
|
||
|
CASClient::Frameworks::Rails::Filter.configure(
|
||
|
:cas_base_url => Setting.cas_base_url
|
||
|
)
|
||
|
self.class.cas_initialized = true
|
||
|
end
|
||
|
CASClient::Frameworks::Rails::Filter.filter(self) unless session[:cas_user]
|
||
|
if session[:cas_user]
|
||
|
user = User.find_or_initialize_by_login(session[:cas_user])
|
||
|
if user.new_record?
|
||
|
# Self-registration off
|
||
|
redirect_to(home_url) && return unless Setting.self_registration?
|
||
|
# Create on the fly
|
||
|
user.login = session[:cas_user]
|
||
|
user.mail = session[:cas_user] + Setting.cas_email_suffix
|
||
|
user.firstname = session[:cas_user]
|
||
|
user.lastname = session[:cas_user]
|
||
|
user.random_password
|
||
|
user.status = User::STATUS_REGISTERED
|
||
|
case Setting.self_registration
|
||
|
when '1'
|
||
|
register_by_email_activation(user) do
|
||
|
onthefly_creation_failed(user)
|
||
|
end
|
||
|
when '3'
|
||
|
register_automatically(user) do
|
||
|
onthefly_creation_failed(user)
|
||
|
end
|
||
|
else
|
||
|
register_manually_by_administrator(user) do
|
||
|
onthefly_creation_failed(user)
|
||
|
end
|
||
|
end
|
||
|
else
|
||
|
# Existing record
|
||
|
if user.active?
|
||
|
successful_authentication(user)
|
||
|
else
|
||
|
account_pending
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
private
|
||
|
def password_authentication
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def successful_authentication(user)
|
||
|
# Valid user
|
||
|
self.logged_user = user
|
||
| app/models/setting.rb | ||
|---|---|---|
|
def self.openid?
|
||
|
Object.const_defined?(:OpenID) && self[:openid].to_i > 0
|
||
|
end
|
||
|
def self.cas?
|
||
|
Object.const_defined?(:CAS) && self[:cas].to_i > 0
|
||
|
end
|
||
|
|
||
|
# Checks if settings have changed since the values were read
|
||
|
# and clears the cache hash if it's the case
|
||
| app/views/account/login.rhtml | ||
|---|---|---|
|
</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<% if Setting.cas? %>
|
||
|
<tr>
|
||
|
<td align="left">
|
||
|
<%= link_to l(:label_cas_login), :controller => 'account', :action => 'cas_authenticate' %>
|
||
|
</td>
|
||
|
</tr>
|
||
|
<% end %>
|
||
|
<td align="left">
|
||
|
<% if Setting.lost_password? %>
|
||
|
<%= link_to l(:label_password_lost), :controller => 'account', :action => 'lost_password' %>
|
||
| app/views/settings/_authentication.rhtml | ||
|---|---|---|
|
<p><%= setting_check_box :openid, :disabled => !Object.const_defined?(:OpenID) %></p>
|
||
|
<p><%= setting_check_box :cas, :disabled => !Object.const_defined?(:CAS) %></p>
|
||
|
<p><%= setting_text_field :cas_base_url, :disabled => !Object.const_defined?(:CAS), :size => 50 %></p>
|
||
|
<p><%= setting_text_field :cas_email_suffix, :disabled => !Object.const_defined?(:CAS), :size => 50 %></p>
|
||
|
<p><%= setting_check_box :cas_force, :disabled => !Object.const_defined?(:CAS) %></p>
|
||
|
<p><%= setting_check_box :rest_api_enabled %></p>
|
||
|
</div>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
setting_file_max_size_displayed: Max size of text files displayed inline
|
||
|
setting_repository_log_display_limit: Maximum number of revisions displayed on file log
|
||
|
setting_openid: Allow OpenID login and registration
|
||
|
setting_cas: Use CAS login and registration
|
||
|
setting_cas_base_url: CAS server base URL
|
||
|
setting_cas_email_suffix: Default email suffix for CAS users
|
||
|
setting_cas_force: ONLY allow login using CAS (this disables normal login)
|
||
|
setting_password_min_length: Minimum password length
|
||
|
setting_new_project_user_role_id: Role given to a non-admin user who creates a project
|
||
|
setting_default_projects_modules: Default enabled modules for new projects
|
||
| ... | ... | |
|
label_register: Register
|
||
|
label_login_with_open_id_option: or login with OpenID
|
||
|
label_password_lost: Lost password
|
||
|
label_cas_login: Login using CAS
|
||
|
label_home: Home
|
||
|
label_my_page: My page
|
||
|
label_my_account: My account
|
||
| config/settings.yml | ||
|---|---|---|
|
default: ''
|
||
|
rest_api_enabled:
|
||
|
default: 0
|
||
|
cas:
|
||
|
default: 0
|
||
|
cas_base_url:
|
||
|
default: ''
|
||
|
cas_email_suffix:
|
||
|
default: ''
|
||
|
cas_force:
|
||
|
default: 0
|
||