Ejemplo n.º 1
0
 static internal string SerializePolicies(IList <string> policies)
 {
     if (policies.Count == 0)
     {
         return(AuthenticationPolicies.None);
     }
     else
     {
         return(PolicyRequest.ConcatenateListOfElements(policies));
     }
 }
Ejemplo n.º 2
0
        bool IExtensionResponse.Deserialize(IDictionary <string, string> fields, DotNetOpenId.RelyingParty.IAuthenticationResponse response, string typeUri)
        {
            if (fields == null)
            {
                return(false);
            }
            if (!fields.ContainsKey(Constants.ResponseParameters.AuthPolicies))
            {
                return(false);
            }

            ActualPolicies.Clear();
            string[] actualPolicies = fields[Constants.ResponseParameters.AuthPolicies].Split(' ');
            foreach (string policy in actualPolicies)
            {
                if (policy.Length > 0 && policy != AuthenticationPolicies.None)
                {
                    ActualPolicies.Add(policy);
                }
            }

            AuthenticationTimeUtc = null;
            string authTime;

            if (fields.TryGetValue(Constants.ResponseParameters.AuthTime, out authTime))
            {
                DateTime authDateTime;
                if (DateTime.TryParse(authTime, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out authDateTime) &&
                    authDateTime.Kind == DateTimeKind.Utc)                       // may be unspecified per our option above
                {
                    AuthenticationTimeUtc = authDateTime;
                }
                else
                {
                    Logger.ErrorFormat("Invalid format for {0} parameter: {1}",
                                       Constants.ResponseParameters.AuthTime, authTime);
                }
            }

            AssuranceLevels.Clear();
            AliasManager authLevelAliases = PolicyRequest.FindIncomingAliases(fields);

            foreach (string authLevelAlias in authLevelAliases.Aliases)
            {
                string authValue;
                if (fields.TryGetValue(Constants.ResponseParameters.AuthLevelAliasPrefix + authLevelAlias, out authValue))
                {
                    string authLevelType = authLevelAliases.ResolveAlias(authLevelAlias);
                    AssuranceLevels[authLevelType] = authValue;
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Tests equality between two <see cref="PolicyRequest"/> instances.
        /// </summary>
        public override bool Equals(object obj)
        {
            PolicyRequest other = obj as PolicyRequest;

            if (other == null)
            {
                return(false);
            }
            if (MaximumAuthenticationAge != other.MaximumAuthenticationAge)
            {
                return(false);
            }
            if (PreferredPolicies.Count != other.PreferredPolicies.Count)
            {
                return(false);
            }
            foreach (string policy in PreferredPolicies)
            {
                if (!other.PreferredPolicies.Contains(policy))
                {
                    return(false);
                }
            }
            if (PreferredAuthLevelTypes.Count != other.PreferredAuthLevelTypes.Count)
            {
                return(false);
            }
            foreach (string authLevel in PreferredAuthLevelTypes)
            {
                if (!other.PreferredAuthLevelTypes.Contains(authLevel))
                {
                    return(false);
                }
            }
            return(true);
        }