Skip to content
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

Additional JWT Security Token Support #1337

Merged
merged 1 commit into from Oct 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 19 additions & 14 deletions mcs/class/System.IdentityModel/System.IdentityModel-net_4_5.csproj
Expand Up @@ -50,6 +50,7 @@
<Compile Include="Assembly\AssemblyInfo.cs" />
<Compile Include="System.IdentityModel\CookieTransform.cs" />
<Compile Include="System.IdentityModel\OpenObject.cs" />
<Compile Include="System.IdentityModel\SignatureVerificationFailedException.cs" />
<Compile Include="System.IdentityModel.Claims\Claim.cs" />
<Compile Include="System.IdentityModel.Claims\ClaimSet.cs" />
<Compile Include="System.IdentityModel.Claims\ClaimTypes.cs" />
Expand Down Expand Up @@ -147,9 +148,12 @@
<Compile Include="System.IdentityModel.Tokens\SecurityToken.cs" />
<Compile Include="System.IdentityModel.Tokens\SecurityTokenDescriptor.cs" />
<Compile Include="System.IdentityModel.Tokens\SecurityTokenException.cs" />
<Compile Include="System.IdentityModel.Tokens\SecurityTokenHandler.cs" />
<Compile Include="System.IdentityModel.Tokens\SecurityTokenExpiredException.cs" />
<Compile Include="System.IdentityModel.Tokens\SecurityTokenHandler.cs" />
<Compile Include="System.IdentityModel.Tokens\SecurityTokenHandlerCollection.cs" />
<Compile Include="System.IdentityModel.Tokens\SecurityTokenHandlerConfiguration.cs" />
<Compile Include="System.IdentityModel.Tokens\SecurityTokenNotYetValidException.cs" />
<Compile Include="System.IdentityModel.Tokens\SecurityTokenReplayDetectedException.cs" />
<Compile Include="System.IdentityModel.Tokens\SecurityTokenTypes.cs" />
<Compile Include="System.IdentityModel.Tokens\SecurityTokenValidationException.cs" />
<Compile Include="System.IdentityModel.Tokens\SessionSecurityToken.cs" />
Expand All @@ -170,7 +174,8 @@
<Compile Include="System.IdentityModel.Tokens\X509SubjectKeyIdentifierClause.cs" />
<Compile Include="System.IdentityModel.Tokens\X509ThumbprintKeyIdentifierClause.cs" />
<Compile Include="System.IdentityModel.Tokens\X509WindowsSecurityToken.cs" />
<Compile Include="System.Security.Claims\AuthenticationTypes.cs" /> <Compile Include="System.ServiceModel.Security\X509CertificateValidationMode.cs" />
<Compile Include="System.Security.Claims\AuthenticationTypes.cs" />
<Compile Include="System.ServiceModel.Security\X509CertificateValidationMode.cs" />
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand All @@ -180,18 +185,18 @@
</Target>
-->
<PropertyGroup>
<PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">

</PreBuildEvent>
<PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">

</PreBuildEvent>
<PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">

</PreBuildEvent>
<PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">

</PreBuildEvent>

<PostBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">

</PostBuildEvent>
<PostBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">

<PostBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">

</PostBuildEvent>
<PostBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">

</PostBuildEvent>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -236,4 +241,4 @@
<Folder Include="Properties\" />
</ItemGroup>
</Project>

@@ -0,0 +1,54 @@
//
// SecurityTokenExpiredException.cs
//
// Author:
// Noesis Labs (Ryan.Melena@noesislabs.com)
//
// Copyright (C) 2014 Noesis Labs, LLC https://noesislabs.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_4_5

using System;
using System.Runtime.Serialization;

namespace System.IdentityModel.Tokens
{
public class SecurityTokenExpiredException : SecurityTokenValidationException
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement missing exception

{
public SecurityTokenExpiredException()
: base("ID4181: The security token has expired.")
{ }

public SecurityTokenExpiredException(string message)
: base(message)
{ }

public SecurityTokenExpiredException(string message, Exception innerException)
: base(message, innerException)
{ }

public SecurityTokenExpiredException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
}
}
#endif
@@ -0,0 +1,54 @@
//
// SecurityTokenNotYetValidException.cs
//
// Author:
// Noesis Labs (Ryan.Melena@noesislabs.com)
//
// Copyright (C) 2014 Noesis Labs, LLC https://noesislabs.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_4_5

using System;
using System.Runtime.Serialization;

namespace System.IdentityModel.Tokens
{
public class SecurityTokenNotYetValidException : SecurityTokenValidationException
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement missing exception

{
public SecurityTokenNotYetValidException()
: base("ID4182: The security token is not valid yet.")
{ }

public SecurityTokenNotYetValidException(string message)
: base(message)
{ }

public SecurityTokenNotYetValidException(string message, Exception innerException)
: base(message, innerException)
{ }

public SecurityTokenNotYetValidException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
}
}
#endif
@@ -0,0 +1,54 @@
//
// SecurityTokenReplayDetectedException.cs
//
// Author:
// Noesis Labs (Ryan.Melena@noesislabs.com)
//
// Copyright (C) 2014 Noesis Labs, LLC https://noesislabs.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_4_5

using System;
using System.Runtime.Serialization;

namespace System.IdentityModel.Tokens
{
public class SecurityTokenReplayDetectedException : SecurityTokenValidationException
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement missing exception

{
public SecurityTokenReplayDetectedException()
: base("ID1070: Replay has been detected for a SecurityToken.")
{ }

public SecurityTokenReplayDetectedException(string message)
: base(message)
{ }

public SecurityTokenReplayDetectedException(string message, Exception innerException)
: base(message, innerException)
{ }

public SecurityTokenReplayDetectedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
}
}
#endif
Expand Up @@ -3,6 +3,7 @@
Assembly/AssemblyInfo.cs
System.IdentityModel/CookieTransform.cs
System.IdentityModel/OpenObject.cs
System.IdentityModel/SignatureVerificationFailedException.cs
System.IdentityModel.Claims/Claim.cs
System.IdentityModel.Claims/ClaimSet.cs
System.IdentityModel.Claims/ClaimTypes.cs
Expand Down Expand Up @@ -100,9 +101,12 @@ System.IdentityModel.Tokens/SecurityKeyUsage.cs
System.IdentityModel.Tokens/SecurityToken.cs
System.IdentityModel.Tokens/SecurityTokenDescriptor.cs
System.IdentityModel.Tokens/SecurityTokenException.cs
System.IdentityModel.Tokens/SecurityTokenExpiredException.cs
System.IdentityModel.Tokens/SecurityTokenHandler.cs
System.IdentityModel.Tokens/SecurityTokenHandlerCollection.cs
System.IdentityModel.Tokens/SecurityTokenHandlerConfiguration.cs
System.IdentityModel.Tokens/SecurityTokenNotYetValidException.cs
System.IdentityModel.Tokens/SecurityTokenReplayDetectedException.cs
System.IdentityModel.Tokens/SecurityTokenTypes.cs
System.IdentityModel.Tokens/SecurityTokenValidationException.cs
System.IdentityModel.Tokens/SessionSecurityToken.cs
Expand All @@ -124,4 +128,4 @@ System.IdentityModel.Tokens/X509SubjectKeyIdentifierClause.cs
System.IdentityModel.Tokens/X509ThumbprintKeyIdentifierClause.cs
System.IdentityModel.Tokens/X509WindowsSecurityToken.cs
System.Security.Claims/AuthenticationTypes.cs
System.ServiceModel.Security/X509CertificateValidationMode.cs
System.ServiceModel.Security/X509CertificateValidationMode.cs
@@ -0,0 +1,54 @@
//
// SignatureVerificationFailedException.cs
//
// Author:
// Noesis Labs (Ryan.Melena@noesislabs.com)
//
// Copyright (C) 2014 Noesis Labs, LLC https://noesislabs.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_4_5

using System;
using System.Runtime.Serialization;

namespace System.IdentityModel
{
public class SignatureVerificationFailedException : Exception
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement missing exception

{
public SignatureVerificationFailedException()
: base("ID4038: Signature verification failed.")
{ }

public SignatureVerificationFailedException(string message)
: base(message)
{ }

public SignatureVerificationFailedException(string message, Exception innerException)
: base(message, innerException)
{ }

public SignatureVerificationFailedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
}
}
#endif
Expand Up @@ -204,7 +204,12 @@ object ConvertToType (object obj, Type targetType)
}

public object Deserialize (string input, Type targetType) {
return DeserializeObjectInternal (input);
object obj = DeserializeObjectInternal (input);

if (obj == null)
return Activator.CreateInstance (targetType);

return ConvertToType (obj, targetType);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert object before returning to avoid error when calling code attempts to cast

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a test case showing this scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added unit test for non-generic Deserialize overload

}

static object Evaluate (object value) {
Expand Down
Expand Up @@ -833,7 +833,7 @@ bool ProcessCharacter (char ch)

void CreateArray ()
{
var arr = new ArrayList ();
var arr = new List <object> ();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make compatible with MS claims processing code which apparently assumes deserialized json collection can be cast to IEnumerable<object>

PushObject (arr);
}

Expand Down Expand Up @@ -865,7 +865,7 @@ void StoreValue (object o)
{
Dictionary <string, object> dict = PeekObject () as Dictionary <string, object>;
if (dict == null) {
ArrayList arr = PeekObject () as ArrayList;
List <object> arr = PeekObject () as List <object>;
if (arr == null)
throw new InvalidOperationException ("Internal error: current object is not a dictionary or an array.");
arr.Add (o);
Expand Down
Expand Up @@ -415,6 +415,22 @@ public void TestDeserializeUnquotedKeysWithSpaces ()
//object oo = ser.DeserializeObject ("{value:'Purple\\r \\n monkey\\'s:\\tdishwasher'}");
}

[Test]
public void TestDeserializeNonGenericOverload()
{
JavaScriptSerializer ser = new JavaScriptSerializer();
Assert.IsNull(ser.Deserialize("", typeof(X)));

X s = new X();
s.Init();
string x = ser.Serialize(s);

Assert.AreEqual("{\"z\":8,\"ch\":\"v\",\"ch_null\":null,\"str\":\"vwF59g\",\"b\":253,\"sb\":-48,\"sh\":-32740,\"ush\":65511,\"i\":-234235453,\"ui\":4294733061,\"l\":-9223372036854775780,\"ul\":18446744073709551612,\"f\":NaN,\"f1\":-Infinity,\"f2\":Infinity,\"f3\":-3.40282347E+38,\"f4\":3.40282347E+38,\"d\":NaN,\"d1\":-Infinity,\"d2\":Infinity,\"d3\":-1.7976931348623157E+308,\"d4\":1.7976931348623157E+308,\"de\":-1,\"de1\":0,\"de2\":1,\"de3\":-79228162514264337593543950335,\"de4\":79228162514264337593543950335,\"g\":\"000000ea-0002-0162-0102-030405060708\",\"nb\":null,\"dbn\":null,\"uri\":\"http://kostat@mainsoft/adfasdf/asdfasdf.aspx/asda/ads?a=b&c=d\",\"hash\":{\"mykey\":{\"BB\":10}},\"point\":{\"IsEmpty\":false,\"X\":150,\"Y\":150},\"MyEnum\":[1,10,345],\"MyEnum1\":[1,10,345],\"AA\":5,\"AA1\":[{\"BB\":10},{\"BB\":10}],\"BB\":18446744073709551610,\"YY\":[{\"BB\":10},{\"BB\":10}]}", x, "#A1");

X n = ser.Deserialize(x, typeof(X)) as X;
Assert.AreEqual(s, n, "#A2");
}

[Test]
public void TestDeserializeTypeResolver ()
{
Expand Down
5 changes: 4 additions & 1 deletion mcs/class/corlib/System.Security.Claims/Claim.cs
Expand Up @@ -58,6 +58,9 @@ public Claim (string type, string value, string valueType, string issuer, string
throw new ArgumentNullException ("type");
if (value == null)
throw new ArgumentNullException ("value");

Properties = new Dictionary <string, string> ();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make compatible with MS code that seems to assume Properties dictionary is initialized.


Type = type;
Value = value;
ValueType = valueType == null ? ClaimValueTypes.String : valueType;
Expand Down Expand Up @@ -91,4 +94,4 @@ public override string ToString ()
}
}
}
#endif
#endif