-
-
Notifications
You must be signed in to change notification settings - Fork 573
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
Restored support for NIL as well as empty AttributeValues #135
Conversation
Great work ! Thank you. I think I will be able to deal with some attributes like { "ATTRIBUTE_NAME" => "" } |
@Lordnibbler Before leaving, I will also need this one :) |
@sebastienluquet @borgand please confirm you want this PR merged |
I'd vote against the use of |
I'll prefer this one but ridiculous comment suggest a little refactoring |
@ridiculous - I hadn't thought about that. I'll look into it and see if I come up with a better solution. PS. Can I update this pull-request somehow with new code? |
@borgand : Yes you can, Pull Request is auto-magically updated :). |
OK, I got this far with # attribute_value.rb
require 'delegate'
module OneLogin
module RubySaml
# Wrapper for AttributeValue with multiple values
# For most duck typing purposes AttributeValue behaves as the first value type (String, nil, etc)
# unless specifically asked for (i.e AttributeValue#class would not lie)
# Use AttributeValue#values to get all values as an array
class AttributeValue < SimpleDelegator
def initialize(*args)
super
@values = []
end
attr_accessor :values
# Redefine nil? so that we properly respond to actual nil delegate
def nil?
__getobj__.send(:nil?)
end
end
end
end and then in the # Retain first value's type while transporting all values
attr_value = AttributeValue.new values.first
attr_value.values = values.reverse # retain XML order This passes all tests, including not polluting value = AttributeValue.new(nil)
# passes inverted truthiness:
puts !v ? 'falsey' : 'truthy' # => falsey
# but fails all direct truthiness tests:
v || 1 # => nil
v && 1 # => 1
puts v ? 'truthy' : 'falsey' # => truthy
puts "should not" if v # => should not As you can see, we can not do much about the C-level Anybody have any better ideas? |
This collection can be queried for both the default first value or all values of the attribute.
Seems that this monkey-patching attribute values was not that great idea after all. So I'm reverting back to my initial idea that I did not realize at first -- making As I understand my previous multi-value pull-request has not been released as gem yet so there should not be too many users whom this will hurt. response.attributes['mail']
# => '[email protected]'
response.attributes.multi('mail')
# => ['[email protected]', '[email protected]'] As a bonus I added a switch that downstream users can use to turn the backwards compatibility off: OneLogin::RubySaml::Attributes.single_value_compatibility = false
response.attributes['mail']
# => ['[email protected]', '[email protected]']
response.attributes.single('mail')
# => '[email protected]' This default could be changed at some later time (say 1.0) |
I'm leaving tomorrow :( |
@sebastienluquet, would this implementation work for you? |
Actually it create some regression since I expect .attributes to be an Hash and some of my .attributes.with_indifferent_access do not work anymore :( |
@sebastienluquet - what do you do with the # stringifies all names so both 'email' and :email return the same result
def canonize_name(name)
name.to_s
end This makes response.attributes['mail’]
response.attributes[:mail] Does this fit your needs? I kept from making
|
You're right I did not really need with_indifferent_access. Refactoring ok for me. Ready to merge :) |
Seems like this one #137 achieves the same thing with a lot less code changes and no regression worries. |
SAML does allow specific Of course, with a bit more look into this matter, maybe a |
Maybe an |
Sorry, I don't catch where to raise the error. Can you elaborate? |
If any empty attribute is given without an appropriate value set for |
Then it is to be interpreted as empty string as my implementation should do.
|
@borgand @ridiculous please confirm you want this PR reviewed and merged |
@pitbulk @inakidelamadrid @luisvm can you guys review? lgtm 👍 |
👍 I prefer this over #137 as this follows spec more closely. |
Agree with @borgand as this approach closely follows standards: <saml:AttributeStatement>
<saml:Attribute Name="novalue" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
</saml:Attribute>
<saml:Attribute Name="blankvalue" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
<saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string"/>
</saml:Attribute>
<saml:Attribute Name="multiplevalue" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
<saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">test1</saml:AttributeValue>
<saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">test2</saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="nilvalue" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
<saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string" xsi:nil="true"/>
</saml:Attribute>
</saml:AttributeStatement>
👍 |
@inakidelamadrid @pitbulk @pwnetrationguru please review |
👍 |
We're going to merge this one in and close 137 |
Restored support for NIL as well as empty AttributeValues
@sebastienluquet commented on 3e7a9a9:
What I read from SAMLCore:
This pull request restores parsing empty
<AttributeValue/>
intonil
or""
as per specs. Note that (2) above does not define empty string, but currentlyruby-saml
does not supportxsi:type
and regards all values as strings, thus empty value essentially means empty string inruby-saml
current implementation.NB! this does not fully resolve @sebastienluquet's issue, if his XML does not contain the
xsi:nil
attribute, but it would be against specs to parse that intonil
.