Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F905084
saml.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Aug 29, 8:57 PM
Size
1 KB
Mime Type
text/x-ruby
Expires
Sun, Aug 31, 8:57 PM (8 h, 57 m)
Engine
blob
Format
Raw Data
Handle
252444
Attached To
rWEBDNS WebDNS (edet4)
saml.rb
View Options
require
'securerandom'
require
'devise/strategies/authenticatable'
module
Devise
module
Strategies
class
SamlAuthenticatable
<
Authenticatable
def
valid?
return
false
unless
remote_user
.
present?
return
false
unless
mail
.
present?
return
true
if
WebDNS
.
settings
[
:saml_required_entitlement
].
nil?
entitlement
.
present?
&&
entitlement
.
include?
(
WebDNS
.
settings
[
:saml_required_entitlement
]
)
end
def
authenticate!
if
!
WebDNS
.
settings
[
:saml
]
return
fail
!
(
'SAML is disabled'
)
end
identifier
=
[
'saml'
,
remote_user
].
join
(
':'
)
user
=
mapping
.
to
.
find_or_initialize_by
(
identifier
:
identifier
)
return
fail
!
(
'Wrong credentials'
)
unless
user
# Update user attributes
user
.
email
=
mail
user
.
password
=
SecureRandom
.
hex
(
15
)
if
user
.
new_record?
user
.
save!
success!
(
user
)
end
private
def
remote_user
request
.
headers
[
'HTTP_REMOTE_USER'
]
end
def
mail
request
.
headers
[
'MAIL'
]
end
def
entitlement
request
.
headers
[
'ENTITLEMENT'
]
end
end
end
end
Warden
::
Strategies
.
add
(
:saml
,
Devise
::
Strategies
::
SamlAuthenticatable
)
Event Timeline
Log In to Comment