Example #1
0
    protected void Submit_UserModify(object sender, EventArgs e)
    {
        //Create a new client to store authentication
        RestClient authenticationClient = UiDrivenLogin.Authenticate(TenantUrl, AdminServiceAccount);
        //Parse result challenge list. This is a service account so we can assume the results will be password and that there will only be one result.
        Dictionary <string, dynamic> mech = authenticationClient.ChallengeCollection[0]["Mechanisms"][0];

        //Login for service account is assumed to only require password and no MFA.
        if (mech["AnswerType"] == "Text")
        {
            //Call advance authentication with our service account credentials
            UiDrivenLogin.AdvanceForMech(authenticationClient, authenticationClient.TenantId, authenticationClient.SessionId, true, mech, null, AdminServicePass);
        }
        //Something other then text was returned which indicates that the service account is not set up correctly.
        else
        {
            FailureText.Text     = "The service account is not set up correctly. It should only require a password an no MFA.";
            ErrorMessage.Visible = true;

            UserInfo_div.Visible        = false;
            MyAccount_Start_div.Visible = false;
        }

        //Create a new userManagementClient and pass our authenticated rest client from our login call.
        UserManagement userManagementClient = new UserManagement(authenticationClient);
        CDUser         cUser = new CDUser();

        cUser.Name         = LoginName.Text + "@" + Alias_DropDownList.SelectedItem.ToString();
        cUser.ID           = UserUUID.Text;
        cUser.DisplayName  = DisplayName.Text;
        cUser.Mail         = Email.Text;
        cUser.OfficeNumber = OfficeNumber.Text;
        cUser.MobileNumber = MobileNumber.Text;
        cUser.HomeNumber   = HomeNumber.Text;

        Dictionary <string, dynamic> modifyUserResult = userManagementClient.ChangeUser(cUser, InEverybodyRole.Checked);

        if (modifyUserResult["success"])
        {
            SuccessText.Text       = "User " + LoginName.Text + " was successfully modified.";
            SuccessMessage.Visible = true;

            //hide unneeded elements.
            UserInfo_div.Visible        = false;
            MyAccount_Start_div.Visible = false;
        }
        else
        {
            FailureText.Text     = "There was an error modifying the user: "******"Message"];
            ErrorMessage.Visible = true;

            //hide unneeded elements.
            UserInfo_div.Visible        = false;
            MyAccount_Start_div.Visible = false;
        }
    }
    protected void Submit_Registration(object sender, EventArgs e)
    {
        //ClientCreds Flow Example. Scope to CreateUser
        RestClient authenticationClient = new OAuthClient().Centrify_OAuthClientCredentials(TenantUrl, OAuthAppId, ClientId, ClientSecret, "CreateUser");

        //Set up dictionary to hold our create user results.
        Dictionary <string, dynamic> createUserResult = null;

        //Check if the passwords match
        if (Password.Text == Confirm_Password.Text)
        {
            //Create a new userManagementClient and pass our authenticated rest client from our login call.
            UserManagement userManagementClient = new UserManagement(authenticationClient);

            //Call the create user api and pass the contents of our registration form.
            CDUser cUser = new CDUser();
            cUser.Name         = LoginName.Text + DefaultDomain;
            cUser.Mail         = Email.Text;
            cUser.DisplayName  = DisplayName.Text;
            cUser.Password     = Password.Text;
            cUser.OfficeNumber = OfficeNumber.Text;
            cUser.MobileNumber = MobileNumber.Text;
            cUser.HomeNumber   = HomeNumber.Text;

            createUserResult = userManagementClient.CreateUser(cUser, false, false, false, false, true);
        }
        //The passwords did not match
        else
        {
            FailureText.Text     = "Password and Confirm Password do not match. Please refresh the page and try again.";
            ErrorMessage.Visible = true;

            Registration.Visible = false; //Hide our registration form.
        }

        //Check if the create user call was successful and present the results if it was.
        if (createUserResult["success"])
        {
            SuccessText.Text       = "User " + LoginName.Text + " was successfully created. Please here to <a href=\"Login.aspx\">login.";
            SuccessMessage.Visible = true;

            Registration.Visible = false; //Hide our registration form.
        }
        //The create user api call was not successful. Present the returned error message from the api.
        else
        {
            FailureText.Text     = createUserResult["Message"];
            ErrorMessage.Visible = true;

            Registration.Visible = false; //Hide our registration form.
        }
    }
    protected void Submit_UserCreate(object sender, EventArgs e)
    {
        //Pull authentication client from session
        RestClient authenticationClient = (RestClient)Session["AuthenticaitonClient"];

        //Set up dictionary to hold our create user results.
        Dictionary <string, dynamic> createUserResult = null;

        //Check if the passwords match

        //Create a new userManagementClient and pass our authenticated rest client from our login call.
        UserManagement userManagementClient = new UserManagement(authenticationClient);

        //Call the create user api and pass the contents of our registration form.
        CDUser cUser = new CDUser();

        cUser.Name         = LoginName.Text + "@" + Alias_DropDownList.SelectedItem.ToString();
        cUser.Mail         = Email.Text;
        cUser.DisplayName  = DisplayName.Text;
        cUser.OfficeNumber = OfficeNumber.Text;
        cUser.MobileNumber = MobileNumber.Text;
        cUser.HomeNumber   = HomeNumber.Text;

        createUserResult = userManagementClient.CreateUser(cUser, PassNeverExpires.Checked, ForcePassChange.Checked, SendEmailInvite.Checked, SendSmsInvite.Checked, InEverybodyRole.Checked);

        //Check if the create user call was successful and present the results if it was.
        if (createUserResult["success"])
        {
            SuccessText.Text       = "User " + LoginName.Text + " was successfully created. The new users UUID is: " + createUserResult["Result"] + ".";
            SuccessMessage.Visible = true;

            CreateUser_div.Visible           = false;
            UserInfo_div.Visible             = false;
            Create_Submit_Button_Div.Visible = false;
        }
        //The create user api call was not successful. Present the returned error message from the api.
        else
        {
            FailureText.Text     = createUserResult["Message"];
            ErrorMessage.Visible = true;

            CreateUser_div.Visible           = false;
            UserInfo_div.Visible             = false;
            Create_Submit_Button_Div.Visible = false;
        }
    }
    protected void Submit_UserModify(object sender, EventArgs e)
    {
        //Pull authentication client from session
        RestClient authenticationClient = (RestClient)Session["AuthenticaitonClient"];

        //Create a new userManagementClient and pass our authenticated rest client from our login call.
        UserManagement userManagementClient = new UserManagement(authenticationClient);
        CDUser         cUser = new CDUser();

        cUser.ID           = UserUUID.Text;
        cUser.Name         = LoginName.Text + "@" + Alias_DropDownList.SelectedItem.ToString();
        cUser.DisplayName  = DisplayName.Text;
        cUser.Mail         = Email.Text;
        cUser.OfficeNumber = OfficeNumber.Text;
        cUser.MobileNumber = MobileNumber.Text;
        cUser.HomeNumber   = HomeNumber.Text;

        Dictionary <string, dynamic> modifyUserResult = userManagementClient.ChangeUser(cUser, InEverybodyRole.Checked);

        if (modifyUserResult["success"])
        {
            SuccessText.Text       = "User " + LoginName.Text + " was successfully modified.";
            SuccessMessage.Visible = true;

            //hide unneeded elements.
            ModifyUser_div.Visible           = false;
            UserInfo_div.Visible             = false;
            Modify_Submit_Button_Div.Visible = false;
        }
        else
        {
            FailureText.Text = "There was an error modifying the user: "******"Message"];

            //hide unneeded elements.
            ErrorMessage.Visible             = true;
            ModifyUser_div.Visible           = false;
            UserInfo_div.Visible             = false;
            Modify_Submit_Button_Div.Visible = false;
        }
    }
    protected void Submit_Registration(object sender, EventArgs e)
    {
        //Create a new client to store authentication
        RestClient authenticationClient = UiDrivenLogin.Authenticate(TenantUrl, AdminServiceAccount);
        //Parse result challenge list. This is a service account so we can assume the results will be password and that there will only be one result.
        Dictionary <string, dynamic> mech = authenticationClient.ChallengeCollection[0]["Mechanisms"][0];

        //Login for service account is assumed to only require password and no MFA.
        if (mech["AnswerType"] == "Text")
        {
            //Call advance authentication with our service account credentials
            UiDrivenLogin.AdvanceForMech(authenticationClient, authenticationClient.TenantId, authenticationClient.SessionId, true, mech, null, AdminServicePass);
        }
        //Something other then text was returned which indicates that the service account is not set up correctly.
        else
        {
            FailureText.Text     = "The service account is not set up correctly. It should only require a password an no MFA.";
            ErrorMessage.Visible = true;

            Registration.Visible = false; //Hide our registration form.
        }

        //Set up dictionary to hold our create user results.
        Dictionary <string, dynamic> createUserResult = null;

        //Check if the passwords match
        if (Password.Text == Confirm_Password.Text)
        {
            //Create a new userManagementClient and pass our authenticated rest client from our login call.
            UserManagement userManagementClient = new UserManagement(authenticationClient);

            //Call the create user api and pass the contents of our registration form.
            CDUser cUser = new CDUser();
            cUser.Name         = LoginName.Text + DefaultDomain;
            cUser.Mail         = Email.Text;
            cUser.DisplayName  = DisplayName.Text;
            cUser.Password     = Password.Text;
            cUser.OfficeNumber = OfficeNumber.Text;
            cUser.MobileNumber = MobileNumber.Text;
            cUser.HomeNumber   = HomeNumber.Text;

            createUserResult = userManagementClient.CreateUser(cUser, false, false, false, false, true);
        }
        //The passwords did not match
        else
        {
            FailureText.Text     = "Password and Confirm Password do not match. Please refresh the page and try again.";
            ErrorMessage.Visible = true;

            Registration.Visible = false; //Hide our registration form.
        }

        //Check if the create user call was successful and present the results if it was.
        if (createUserResult["success"])
        {
            SuccessText.Text       = "User " + LoginName.Text + " was successfully created. Please here to <a href=\"Login.aspx\">login.";
            SuccessMessage.Visible = true;

            Registration.Visible = false; //Hide our registration form.
        }
        //The create user api call was not successful. Present the returned error message from the api.
        else
        {
            FailureText.Text     = createUserResult["Message"];
            ErrorMessage.Visible = true;

            Registration.Visible = false; //Hide our registration form.
        }
    }