Example #1
0
 public ClaimsPrincipal Transform(ClaimsPrincipal principal, IDictionary <string, string> inputs,
                                  IExternalClaimTransformationPipelineContext pipelineContext)
 {
     if (principal == null)
     {
         throw new ArgumentNullException(nameof(principal));
     }
     if (principal.Claims.Any(claim => claim.Value.Equals("ctexception")))
     {
         throw new GenericProviderSampleException("Generic provider exception is thrown on GenericProviderSampleClaimTransformation as requested");
     }
     principal.Identities.First()
     .AddClaim(new Claim("a_sample_static_claim_type", "a_sample_static_claim_value"));
     _identifyLogWriter.WriteInformation(
         $"A Static claim('{"a_sample_static_claim_type"}'.'{"a_sample_static_claim_value"}') is added");
     return(principal);
 }
        public ClaimsPrincipal Transform(ClaimsPrincipal principal, IDictionary <string, string> inputs, IExternalClaimTransformationPipelineContext pipelineContext)
        {
            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }

            try
            {
                var type = GetType();
                // each identity provider may add its own identity to the claims principal object
                // at the time the principal object is passed to this transformation rule, how many identities it contains depends on
                // what previous transformations it has gone through.
                // Normally speaking:
                // 1. After Identify receives a token from an upstream Idp or from the UserNamePassword login, it creates the principal with one identity.
                // 2. After that, Identify loads claims from the local store into another identity and adds it to the principal (2 identities so far)
                // 3. There is a setting called "Execute before loading claims from local store" in the claims transformation configuration page which controls
                // if a transformation should be executed before or after the second identity is added.
                // 4. Note 1: Other transformations may add more identities to the claims principal.
                // 5. Note 2: One can choose to add claims to one identity or to all identities depending on specific need.
                foreach (var identity in principal.Identities)
                {
                    identity.AddClaim(new Claim(type.FullName, type.AssemblyQualifiedName));
                    identifyLogWriter.WriteInformation(string.Format(CultureInfo.InvariantCulture,
                                                                     "A new claim is added: [{0},{1}]", type.FullName,
                                                                     type.AssemblyQualifiedName));
                }
            }
            catch (InvalidOperationException ex)   // this exception type is caught for illustration purpose only
            {
                // Ids from 4830 to 4899 are reserved for external components. Pick one that doesn't conflict with other external events in the same set up
                identifyLogWriter.WriteError(4830, ex);
            }

            return(principal);
        }
Example #3
0
        public ClaimsPrincipal Transform(ClaimsPrincipal principal, IDictionary <string, string> inputs, IExternalClaimTransformationPipelineContext pipelineContext)
        {
            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }

            // At the time this sample code is written, Identify supports only one identity
            var type = GetType();

            foreach (var identity in principal.Identities)
            {
                identity.AddClaim(new Claim(type.FullName, type.AssemblyQualifiedName));
                identifyLogWriter.WriteInformation(string.Format(CultureInfo.InvariantCulture,
                                                                 "A new claim is added: [{0},{1}]", type.FullName,
                                                                 type.AssemblyQualifiedName));
            }

            return(principal);
        }
        public ClaimsPrincipal Transform(ClaimsPrincipal principal, IDictionary <string, string> inputs, IExternalClaimTransformationPipelineContext pipelineContext)
        {
            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }

            try
            {
                var identity = principal.Identities.FirstOrDefault(x => x.BootstrapContext != null);

                if (identity == null)
                {
                    identifyLogWriter.WriteDebug("No Identify has BootstrapContext");
                    return(principal);
                }

                var bootstrapContext = identity.BootstrapContext as BootstrapContext;
                if (bootstrapContext == null)
                {
                    identifyLogWriter.WriteDebug("The identity.BootstrapContext object is not of BootstrapContext type.");
                    return(principal);
                }
                identifyLogWriter.WriteDebug("The identity.BootstrapContext is valid");
            }
            catch (InvalidOperationException ex)   // this exception type is caught for illustration purpose only
            {
                // Ids from 4830 to 4899 are reserved for external components. Pick one that doesn't conflict with other external events in the same set up
                identifyLogWriter.WriteError(4830, ex);
            }

            return(principal);
        }
Example #5
0
        public ClaimsPrincipal Transform(ClaimsPrincipal principal, IDictionary <string, string> inputs, IExternalClaimTransformationPipelineContext pipelineContext)
        {
            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }

            AddConnectionEntityIdentifiers(principal);
            return(principal);
        }