• Decrease Text SizeIncrease Text Size

Setting up Custom Authentication Source

Posted Date: 5/2/2023
    Printer Friendly Version   Email A Friend   Add This   Increase Text Size   Decrease Text Size


using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Xml.XPath;
using System.Data.SqlClient;
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using Centralpoint;
using Centralpoint.Web;
using Centralpoint.Web.Cms;
using Centralpoint.Web.UI;
using Centralpoint.Web.UI.Controls;
using System.Net;
using System.Text.RegularExpressions;

namespace Centralpoint.WebSite.Custom
{
 /// <summary>
 /// This class accesses the template authentication sources.
 /// </summary>
 public class SampleAuthenticationSource : Centralpoint.WebSite.Modules.ICustomAuthenticationSource
 {
  public string IntegrationId { get; private set; }
  public string Email { get; private set; }
  public string DisplayName { get; private set; }
  public DateTime StartDate { get; private set; }
  public DateTime EndDate { get; private set; }
  public string[] AudienceIds { get; private set; }
  public string AllAudiencesIntegrationId { get; private set; }
  public string[] AudienceIntegrationIds { get; private set; }
  public string[] RoleIds { get; private set; }
  public string[] RoleIntegrationIds { get; private set; }
  public CpCollection Properties { get; set; }
  public CpCollection Personalization { get; set; }
  public CpCollection Configuration { get; set; }

  /// <summary>
  /// This method is the default constructor.
  /// </summary>
  public SampleAuthenticationSource()
  {
   this.AllAudiencesIntegrationId = "ALL_AUDIENCES";
  }

  /// <summary>
  /// This method access the custom authentication source and authenticates the user.
  /// </summary>
  /// <param name="source">The Admin > Global Login record that is currently in use.
  /// <param name="username">The users username.
  /// <param name="password">The users password.
  /// <returns>Whether the user has been sucessfully authenticated.</returns>
  public bool Authenticate(DataInfo source, string username, string password)
  {
   try
   {
    string parameters = source.Attributes.Get("CustomParameters");	
                // the value of the Admin > Global Login > Custom Parameters attribute related to the record currently in use
    HttpContext.Current.Trace.Write("TemplateAuthenticationSource.Authenticate", parameters);

                //here you can call you your custom authentication source passing "username" and "password" and based on results set user information.
                // if user was found and can login you need to return true otherwise return false
    if ((username == "Template") && (password == "Template"))
    {
                    //required fields
                    // this must be set to the users unique identifier and must return the same value every time the same user is authenticated
     this.IntegrationId = "USERS_UNIQUE_ID";	

     this.Email = "centralpoint@oxcyon.com";
     this.DisplayName = "Display Name";
     this.StartDate = Centralpoint.Utilities.General.SqlMinDate;
     this.EndDate = Centralpoint.Utilities.General.SqlMaxDate;
                    //end of required fields


                    //each item should relate to an Audience Id in the Site Architecture > Audiences module
     this.AudienceIds = new string[] { };	
                    //each item should relate to an Integration Id in the Site Architecture > Audiences module
     this.AudienceIntegrationIds = new string[] { this.AllAudiencesIntegrationId };	

                    //each item should relate to a Role Id in the Admin > Roles module
     this.RoleIds = new string[] { };	
                    //each item should relate to an Integration Id in the Admin > Roles module
     this.RoleIntegrationIds = new string[] { };		

                    //set user properties
     this.Properties.Set("ContactFirstName", "Display");
     this.Properties.Set("ContactLastName", "Name");

                    //set user configuration
     //this.Configuration.Set("Property", "Value");

                     //set user personalization
     //this.Personalization.Set("Property", "Value");
     return true;
    }
    else
     return false;
   }
   catch (Exception ex)
   {
    HttpContext.Current.Trace.Warn("Error", ex.Message);
    HttpContext.Current.Trace.Warn("Error", ex.StackTrace);
    return false;
   }
  }
 }
 }






Related Taxonomy

Comments:

Be the first to leave a comment.
Please Login to post comments.