Additional JWT Security Token Support
authorRyan Melena <Ryan.Melena@noesislabs.com>
Tue, 14 Oct 2014 02:03:25 +0000 (21:03 -0500)
committerRyan J. Melena <Ryan.Melena@noesislabs.com>
Mon, 20 Oct 2014 21:00:16 +0000 (16:00 -0500)
Fix line endings.  Add test for JavaScriptSerializer.Deserialize(string input, Type targetType).

mcs/class/System.IdentityModel/System.IdentityModel-net_4_5.csproj
mcs/class/System.IdentityModel/System.IdentityModel.Tokens/SecurityTokenExpiredException.cs [new file with mode: 0644]
mcs/class/System.IdentityModel/System.IdentityModel.Tokens/SecurityTokenNotYetValidException.cs [new file with mode: 0644]
mcs/class/System.IdentityModel/System.IdentityModel.Tokens/SecurityTokenReplayDetectedException.cs [new file with mode: 0644]
mcs/class/System.IdentityModel/System.IdentityModel.dll.sources
mcs/class/System.IdentityModel/System.IdentityModel/SignatureVerificationFailedException.cs [new file with mode: 0644]
mcs/class/System.Web.Extensions/System.Web.Script.Serialization/JavaScriptSerializer.cs
mcs/class/System.Web.Extensions/System.Web.Script.Serialization/JsonDeserializer.cs
mcs/class/System.Web.Extensions/Test/System.Web.Script.Serialization/JavaScriptSerializerTest.cs
mcs/class/corlib/System.Security.Claims/Claim.cs

index 3022c52ab5b9220992a9a41a40f378ca5ea03aec..1e07337738e760ce5424006d4da07641621ae4e8 100644 (file)
@@ -50,6 +50,7 @@
     <Compile Include="Assembly\AssemblyInfo.cs" />\r
        <Compile Include="System.IdentityModel\CookieTransform.cs" />\r
     <Compile Include="System.IdentityModel\OpenObject.cs" />\r
+    <Compile Include="System.IdentityModel\SignatureVerificationFailedException.cs" />\r
     <Compile Include="System.IdentityModel.Claims\Claim.cs" />\r
     <Compile Include="System.IdentityModel.Claims\ClaimSet.cs" />\r
     <Compile Include="System.IdentityModel.Claims\ClaimTypes.cs" />\r
     <Compile Include="System.IdentityModel.Tokens\SecurityToken.cs" />\r
     <Compile Include="System.IdentityModel.Tokens\SecurityTokenDescriptor.cs" />\r
     <Compile Include="System.IdentityModel.Tokens\SecurityTokenException.cs" />\r
-       <Compile Include="System.IdentityModel.Tokens\SecurityTokenHandler.cs" />\r
+    <Compile Include="System.IdentityModel.Tokens\SecurityTokenExpiredException.cs" />\r
+    <Compile Include="System.IdentityModel.Tokens\SecurityTokenHandler.cs" />\r
     <Compile Include="System.IdentityModel.Tokens\SecurityTokenHandlerCollection.cs" />\r
     <Compile Include="System.IdentityModel.Tokens\SecurityTokenHandlerConfiguration.cs" />\r
+    <Compile Include="System.IdentityModel.Tokens\SecurityTokenNotYetValidException.cs" />\r
+    <Compile Include="System.IdentityModel.Tokens\SecurityTokenReplayDetectedException.cs" />\r
     <Compile Include="System.IdentityModel.Tokens\SecurityTokenTypes.cs" />\r
     <Compile Include="System.IdentityModel.Tokens\SecurityTokenValidationException.cs" />\r
     <Compile Include="System.IdentityModel.Tokens\SessionSecurityToken.cs" />\r
     <Compile Include="System.IdentityModel.Tokens\X509SubjectKeyIdentifierClause.cs" />\r
     <Compile Include="System.IdentityModel.Tokens\X509ThumbprintKeyIdentifierClause.cs" />\r
     <Compile Include="System.IdentityModel.Tokens\X509WindowsSecurityToken.cs" />\r
-    <Compile Include="System.Security.Claims\AuthenticationTypes.cs" />\r    <Compile Include="System.ServiceModel.Security\X509CertificateValidationMode.cs" />\r
+    <Compile Include="System.Security.Claims\AuthenticationTypes.cs" />\r
+    <Compile Include="System.ServiceModel.Security\X509CertificateValidationMode.cs" />\r
   </ItemGroup>\r
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
        Other similar extension points exist, see Microsoft.Common.targets.\r
   </Target>\r
   -->\r
   <PropertyGroup>\r
-    <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
-
-    </PreBuildEvent>
-    <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">
-
-    </PreBuildEvent>
+    <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">\r
+\r
+    </PreBuildEvent>\r
+    <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">\r
+\r
+    </PreBuildEvent>\r
+\r
+    <PostBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">\r
+\r
+    </PostBuildEvent>\r
+    <PostBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">\r
 \r
-    <PostBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
-
-    </PostBuildEvent>
-    <PostBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">
-
     </PostBuildEvent>\r
   </PropertyGroup>\r
   <ItemGroup>\r
     <Folder Include="Properties\" />\r
   </ItemGroup>\r
 </Project>\r
-
+\r
diff --git a/mcs/class/System.IdentityModel/System.IdentityModel.Tokens/SecurityTokenExpiredException.cs b/mcs/class/System.IdentityModel/System.IdentityModel.Tokens/SecurityTokenExpiredException.cs
new file mode 100644 (file)
index 0000000..2f10c94
--- /dev/null
@@ -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
+       {
+               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
diff --git a/mcs/class/System.IdentityModel/System.IdentityModel.Tokens/SecurityTokenNotYetValidException.cs b/mcs/class/System.IdentityModel/System.IdentityModel.Tokens/SecurityTokenNotYetValidException.cs
new file mode 100644 (file)
index 0000000..9f15b7b
--- /dev/null
@@ -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
+       {
+               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
diff --git a/mcs/class/System.IdentityModel/System.IdentityModel.Tokens/SecurityTokenReplayDetectedException.cs b/mcs/class/System.IdentityModel/System.IdentityModel.Tokens/SecurityTokenReplayDetectedException.cs
new file mode 100644 (file)
index 0000000..eb4a786
--- /dev/null
@@ -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
+       {
+               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
index 2c86355259a44a1e3fb982560175c28fe6597538..4d705d24d5794a9bb090e62ad31cf76312c4c1e0 100755 (executable)
@@ -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
@@ -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
@@ -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
\ No newline at end of file
+System.ServiceModel.Security/X509CertificateValidationMode.cs
diff --git a/mcs/class/System.IdentityModel/System.IdentityModel/SignatureVerificationFailedException.cs b/mcs/class/System.IdentityModel/System.IdentityModel/SignatureVerificationFailedException.cs
new file mode 100644 (file)
index 0000000..2e1e711
--- /dev/null
@@ -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
+       {
+               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
index 14a03b2f0dc9ce59f09f35a61986f6e4185c62d8..6a147e2e03ea2a7852354cce5011661c460a1b79 100644 (file)
@@ -204,7 +204,12 @@ namespace System.Web.Script.Serialization
                }
 
                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);
                }
 
                static object Evaluate (object value) {
index 46bef52a7b4f64906830397780935780134ab0f5..8593e532bf0a378608bd3abe67687a0ddb2eefb8 100644 (file)
@@ -833,7 +833,7 @@ namespace System.Web.Script.Serialization
 
                void CreateArray ()
                {
-                       var arr = new ArrayList ();
+                       var arr = new List <object> ();
                        PushObject (arr);
                }
                
@@ -865,7 +865,7 @@ namespace System.Web.Script.Serialization
                {
                        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);
index 995590eeb2ec6cf0c5370555a82f0e304a7babeb..8274ef9c3f88a317570f68ad49fbb51451551bdc 100644 (file)
@@ -415,6 +415,22 @@ namespace MonoTests.System.Web.Script.Serialization
                        //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 () 
                {
index ffb7ce734497625671f67efd3f9fcc55231a65e1..0347052d2361252524dfb24e5e57158582f98ddf 100644 (file)
@@ -58,6 +58,9 @@ namespace System.Security.Claims {
                                throw new ArgumentNullException ("type");
                        if (value == null)
                                throw new ArgumentNullException ("value");
+
+                       Properties = new Dictionary <string, string> ();
+
                        Type = type;
                        Value = value;
                        ValueType = valueType == null ? ClaimValueTypes.String : valueType;
@@ -91,4 +94,4 @@ namespace System.Security.Claims {
                }
        }
 }
-#endif
\ No newline at end of file
+#endif