Reputation: 6486
I'm using Rails 4 and Devise with Devise SAML Authenticatable for my Account system.
I've got the SAML working and all, but am trying to work out one thing.
I'd like to change one of the SAML attributes before saving it (since it is formatted incorrectly). Essentially, the Account's SAML request is given a role
attribute which is one of the following Group_admin
, Group_consumer
, Group_supplier
. I have a role
field in my Account
model enumerated as follows:
enum role: [:admin, :consumer, :supplier]
Clearly I can't directly set role
because Group_admin != admin
(etc.). Is there a way to modify the SAML attribute that is given before Devise
saves the field?
I've tried a before_save
filter to no avail.
before_save :fix_role!
private
def fix_role!
self.role = self.role.split('_')[1]
end
Does anyone know of a way to do this? I can post any other code if necessary, I'm just not sure what else is needed. Thanks.
Upvotes: 2
Views: 253
Reputation: 6486
I was able to do the following to fix the problem:
attribute-map.yml
"role": "full_role"
account.rb
before_save :set_role!
attr_accessor :full_role
private
def set_role!
self.role = self.full_role.split('_')[1]
end
Essentially, I used an attr_accessor
to store the incorrectly formatted role given from the SAML response and a before_save
filter to correctly set the "real" role field.
Upvotes: 2