Exemplo n.º 1
0
        // On Authentication Settings Page user can:
        // 1. Add new user
        // 2. Add new group
        // 3. See all Users
        // 4. See all Groups
        // 5. Change user passwords
        // 6. Add user to group
        // 7. Remove user from group
        // 8. Delete User (if possible)
        // 9. Delete Group (if possible)

        // Creates a token for the admin user, which the other methods will check, or prints error message
        public bool CreateToken(string userName, string password)
        {
            try
            {
                if (hasToken)
                {
                    Authentication.ReleaseAuthenticationToken(adminToken);
                    hasToken = false;
                }
                if (Authentication.ValidateUserInformation(userName, password).Authenticated)
                {
                    adminToken = Authentication.GetAuthenticationToken(userName, password);
                    if (adminToken.Valid)
                    {
                        if ((adminToken.Access & Authentication.UserAuthenticationLevelEnum.Administrator)
                            == Authentication.UserAuthenticationLevelEnum.Administrator)
                        {
                            CrestronConsole.PrintLine("Admin Token created\r\n");
                            hasToken = true;
                            return(true);
                        }
                        else
                        {
                            panel.StringInput[SerialInputJoins.AdminLoginErrMsg].StringValue =
                                "Inputted credentials are not for an admin account";
                            Authentication.ReleaseAuthenticationToken(adminToken);
                            return(false);
                        }
                    }
                    else
                    {
                        panel.StringInput[SerialInputJoins.AdminLoginErrMsg].StringValue =
                            "The specified username/password pair does not exist on the system";
                        return(false);
                    }
                }
                else
                {
                    panel.StringInput[SerialInputJoins.AdminLoginErrMsg].StringValue =
                        "Unable to validate user";
                    return(false);
                }
            }
            catch (Exception e)
            {
                WriteError("CreateToken", e, SerialInputJoins.AdminLoginErrMsg);
                return(false);
            }
            finally
            {
            }
        }
 public UserToken(Authentication.UserToken userToken)
 {
     _userToken = userToken;
 }
Exemplo n.º 3
0
 static string PrintToken(Authentication.UserToken token)
 {
     return(String.Format("PrintToken: UN: {0}, Access: {1}, Validity: {2}\r\n",
                          token.UserName, token.Access, (token.Valid) ? "Valid" : "Invalid"));
 }
Exemplo n.º 4
0
 bool AdminCheck(Authentication.UserToken token)
 {
     return(token.Valid &&
            ((token.Access & Authentication.UserAuthenticationLevelEnum.Administrator)
             == Authentication.UserAuthenticationLevelEnum.Administrator));
 }