mardi 4 août 2015

Modify Devise SAML Attributes

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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire