Beispiel #1
0
        protected override void WriteTokenCore(XmlWriter writer, SecurityToken token)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            CustomToken c = token as CustomToken;

            if (c != null)
            {
                writer.WriteStartElement(Constants.CustomTokenPrefix, Constants.CustomTokenName, Constants.CustomTokenNamespace);
                writer.WriteAttributeString(Constants.WsUtilityPrefix, Constants.Id, Constants.WsUtilityNamespace, token.Id);
                writer.WriteElementString(Constants.CustomTokenElementName, Constants.CustomTokenNamespace, c.AccessToken);

                writer.WriteEndElement();
                writer.Flush();
            }
            else
            {
                base.WriteTokenCore(writer, token);
            }
        }
Beispiel #2
0
        protected override ReadOnlyCollection <IAuthorizationPolicy> ValidateTokenCore(SecurityToken token)
        {
            CustomToken CustomToken = token as CustomToken;

            CustomJwtSecurityTokenHandler.CustomJwtSecurityTokenHandler customJwtSecurityTokenHandler = new CustomJwtSecurityTokenHandler.CustomJwtSecurityTokenHandler();

            ReadOnlyCollection <System.Security.Claims.ClaimsIdentity> auth = customJwtSecurityTokenHandler.ValidateToken(token);

            List <System.IdentityModel.Claims.Claim> claimList = new List <System.IdentityModel.Claims.Claim>();

            foreach (System.Security.Claims.ClaimsIdentity claimsIdentity in auth)
            {
                foreach (var claim in claimsIdentity.Claims)
                {
                    claimList.Add(new System.IdentityModel.Claims.Claim(claim.Type, claim.Value, Rights.PossessProperty));
                }
            }

            DefaultClaimSet customClaimSet = new DefaultClaimSet(claimList.ToArray());

            List <IAuthorizationPolicy> policies = new List <IAuthorizationPolicy>(1);

            policies.Add(new CustomTokenAuthorizationPolicy(customClaimSet));

            return(policies.AsReadOnly());
        }
Beispiel #3
0
        protected override SecurityToken GetTokenCore(TimeSpan timeout)
        {
            SecurityToken result = new CustomToken(this.AccessToken);

            return(result);
        }