コード例 #1
0
    }//END createDefaultPassword method

    // ==================================================================================
    /// <summary>
    /// THis method generates a default user password.
    /// </summary>
    /// <param name="AdUserProfile">Evado.ActiveDirectoryServices.EvAdsUserProfile</param>
    //  ----------------------------------------------------------------------------------
    private void addCustomerGroup (
      Evado.ActiveDirectoryServices.EvAdsUserProfile AdUserProfile )
    {
      this.LogMethod ( "addCustomerGroup" );
      this.LogValue ( "adUserProfile.SamAccountName: " + AdUserProfile.SamAccountName );
      bool hasCustomerGroup = false;

      //
      // get the customer group from the users groups.
      //
      if ( AdUserProfile.EvGroups.Count > 0 )
      {
        //
        // Iterate through the user's groups.
        //
        foreach ( Evado.ActiveDirectoryServices.EvAdsGroupProfile group in AdUserProfile.EvGroups )
        {
          if ( group == null )
          {
            continue;
          }
          this.LogValue ( "profile.Name: " + group.Name );
          this.LogValue ( "Customer group found" );
          hasCustomerGroup = true;
        }
      }

      //
      // Add a group if is not present in the member list.
      //
      if ( ( AdUserProfile.EvGroups.Count == 0
        || hasCustomerGroup == false )
        && (  this.AdapterObjects.Settings.AdsGroupName != null ) )
      {
        AdUserProfile.EvGroups.Add ( this.Session.AdsCustomerGroup );
        this.LogValue ( "ADS Customer group added" );
      }

      this.LogMethodEnd ( "addCustomerGroup" );

    }//END addCustomerGroup method
コード例 #2
0
    }//ENd getAdsCustomerGroup method

    #endregion

    #region Update ADS User process

    // ==================================================================================
    /// <summary>
    /// THis method updates the ADS user details.
    /// </summary>
    /// <returns>Application Data object</returns>
    //  ----------------------------------------------------------------------------------
    public EvEventCodes updateAdUserProfile ( )
    {
      this.LogMethod ( "updateAdUserProfile" );
      this.LogDebug ( "this.Session.AdsEnabled: " + this.Session.AdsEnabled );
      //
      // Skip update if a new user.
      //
      if ( this.Session.AdsEnabled == false )
      {
        this.LogValue ( "ADS disabled" );
        this.LogMethodEnd ( "updateAdUserProfile" );
        return EvEventCodes.Ok;
      }

      //
      // Skip update if a new user.
      //
      if ( this.AdapterObjects.Settings.AdsGroupName == null
        || this.Session.AdsCustomerGroup.Name == null )
      {
        this.LogValue ( "Debug Authenication or AD Group is null" );
        this.LogMethodEnd ( "updateAdUserProfile" );
        return EvEventCodes.Ok;
      }
      this.LogDebug ( "AdminUserProfile.UserId: " + this.Session.AdminUserProfile.UserId );
      this.LogDebug ( "AdminUserProfile.Password: "******"AdminUserProfile.GivenName: " + this.Session.AdminUserProfile.GivenName );
      this.LogDebug ( "AdminUserProfile.FamilyName: " + this.Session.AdminUserProfile.FamilyName );
      this.LogDebug ( "AdsCustomerGroup.Name: " + this.Session.AdsCustomerGroup.Name );

      //
      // Initialise the ADS services
      //
      Evado.ActiveDirectoryServices.EvAdsProfiles adsProfiles = new ActiveDirectoryServices.EvAdsProfiles ( );
      ActiveDirectoryServices.EvAdsUserProfile outUser = new ActiveDirectoryServices.EvAdsUserProfile ( );
      ActiveDirectoryServices.EvAdsGroupProfile customerGroup = new ActiveDirectoryServices.EvAdsGroupProfile ( );
      bool newUser = false;

      this.LogValue ( "domain name: " + adsProfiles.DomainName );

      //
      // Attempt to retrieve the user profile.
      //
      Evado.ActiveDirectoryServices.EvAdsUserProfile adUserProfile =
        adsProfiles.GetUser ( this.Session.AdminUserProfile.UserId );

      //
      // If the user does not exist add them as a new user.
      //
      if ( adUserProfile == null )
      {
        this.LogValue ( "user null: initialise a new user." );
        //
        // create the default password.
        //
        this.createDefaultPassword ( );

        adUserProfile = new ActiveDirectoryServices.EvAdsUserProfile ( );
        newUser = true;
        adUserProfile.UserId = this.Session.AdminUserProfile.UserId;
        adUserProfile.SamAccountName = this.Session.AdminUserProfile.UserId;
        adUserProfile.UserPrincipalName = adUserProfile.UserId + "@" + adsProfiles.DomainName;
        adUserProfile.AddEvGroup ( this.Session.AdsCustomerGroup );
      }

      this.addCustomerGroup ( adUserProfile );

      adUserProfile.GivenName = this.Session.AdminUserProfile.GivenName;
      adUserProfile.Surname = this.Session.AdminUserProfile.FamilyName;
      adUserProfile.DisplayName = this.Session.AdminUserProfile.CommonName;
      adUserProfile.EmailAddress = this.Session.AdminUserProfile.EmailAddress;
      adUserProfile.Password = this.Session.AdminUserProfile.Password;
      adUserProfile.Enabled = true;
      string description = adUserProfile.Description;

      if ( adUserProfile.Description != String.Empty )
      {
        adUserProfile.Description += "\r\n ";
      }

      adUserProfile.Description +=
        "Updated by " + this.Session.AdminUserProfile.CommonName + " on " + DateTime.Now.ToString ( "dd-MMM-yyyy HH:mm" );

      if ( this.Session.UserProfile.Password != String.Empty )
      {
        adUserProfile.Password = this.Session.AdminUserProfile.Password;
      }

      //
      // update the active directory object.
      //
      ActiveDirectoryServices.EvAdsCallResult result = adsProfiles.SaveItem ( adUserProfile, newUser, out outUser );

      // 
      // get the debug log.
      // 
      this.LogValue ( "adsProfiles.ApplicationLog:" + adsProfiles.Log );

      if ( result != ActiveDirectoryServices.EvAdsCallResult.Success )
      {
        this.LogValue ( "EvAdsCallResult: " + result );
        this.LogMethodEnd ( "updateAdUserProfile" );

        return EvEventCodes.Active_Directory_General_Error;
      }

      this.LogMethodEnd ( "updateAdUserProfile" );

      return EvEventCodes.Ok;

    }//ENd updateAdUserProfile method