+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to add custom claims

How to add custom claims

6 posts, 0 answered
  1. Jerome SERANE
    Jerome SERANE avatar
    5 posts
    Registered:
    05 May 2009
    19 May 2014
    Link to this post

    Hi,

    How to add custom claims with Sitemanager 6.x ?

     I tried to override SitefinityClaimsAuthenticationModule.AuthenticatePrincipalWithCurrentToken(IClaimsPrincipal principal, bool persistent) but it is not marked as virtual.

     Any ideas ?

  2. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    22 May 2014
    Link to this post
    Hi Jerome,

    You could inherit from the SFClaimsAuthenticationManager and override the Authenticate method. You can create a custom login widget that will use your manager and custom logic. Another option is to try overriding the base ClaimsAuthenticationManager and the same method.

    public class MySFClaimsManager : SFClaimsAuthenticationManager
       {
           public override Microsoft.IdentityModel.Claims.IClaimsPrincipal Authenticate(string resourceName, Microsoft.IdentityModel.Claims.IClaimsPrincipal incomingPrincipal)
           {
               return base.Authenticate(resourceName, incomingPrincipal);
           }
       }
     
       public class MyClaimsManager : ClaimsAuthenticationManager
       {
           public override IClaimsPrincipal Authenticate(string resourceName, IClaimsPrincipal incomingPrincipal)
           {
               return base.Authenticate(resourceName, incomingPrincipal);
           }
       }

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Jerome SERANE
    Jerome SERANE avatar
    5 posts
    Registered:
    05 May 2009
    22 May 2014
    Link to this post

    Hi Nikola,

     I'm using SecurityManager.AuthenticateUser and SFClaimsAuthenticationManager.Authenticate  is never called.

    Overriding SitefinityClaimsAuthenticationModule.AuthenticatePrincipalWithCurrentToken could do the job, but the method is not marked as virtual :

    public class MySitefinityClaimsAuthenticationModule : SitefinityClaimsAuthenticationModule
    {
        public override void AuthenticatePrincipalWithCurrentToken(IClaimsPrincipal principal, bool persistent)
        {
            ((SitefinityIdentity) principal.Identity).Claims.Add(new Claim("MyClaimType", "MyClaimValue"));
            base.AuthenticatePrincipalWithCurrentToken(IClaimsPrincipal principal, bool persistent)
        }
    }

  4. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    27 May 2014
    Link to this post
    Hi Jerome,

    You should replace the default Claims manager in the web.config to use your custom one. Then, the Authenticate method will be called from your Authentication Manager.

    <microsoft.identityModel>
        <service>
           
          <!--<claimsAuthenticationManager type="Telerik.Sitefinity.Security.Claims.SFClaimsAuthenticationManager, Telerik.Sitefinity"/>-->
          <claimsAuthenticationManager type="SitefinityWebApp.MySFClaimsManager, SitefinityWebApp"/>
     
    ...

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  5. Jerome SERANE
    Jerome SERANE avatar
    5 posts
    Registered:
    05 May 2009
    13 Jun 2014
    Link to this post

    Fixed after migrating to v7.0.5109.

    We can now override SitefinityClaimsAuthenticationModule.AuthenticatePrincipalWithCurrentToken(IClaimsPrincipal principal, bool persistent) and add any custom claims.

  6. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    16 Jun 2014
    Link to this post
    Hi Jerome,

    I am glad you have resolved the issue. It has been decided to expose this method in the currently penultimate internal build - 7.0.5109.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
6 posts, 0 answered