Ejemplo n.º 1
0
        public void GetLoggedInIndicator(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] AuthenticationComponent sut,
            int contextId,
            string regex)
        {
            // ARRANGE
            var json = new JObject(
                new JProperty("logged_in_regex", regex));

            httpClientMock.SetupApiCall(sut, CallType.View, "getLoggedInIndicator",
                                        new Parameters
            {
                { "contextId", contextId }
            })
            .Returns(json.ToString())
            .Verifiable();

            // ACT
            var result = sut.GetLoggedInIndicator(contextId);

            // ASSERT
            result.Should().Be(regex);
            httpClientMock.Verify();
        }
Ejemplo n.º 2
0
 public ZapClient(string host, int port, Protocols protocol = Protocols.http)
 {
     Protocol          = protocol;
     Host              = host;
     Port              = port;
     Acsrf             = new AcsrfComponent(this);
     AjaxSpider        = new AjaxSpiderComponent(this);
     Ascan             = new AscanComponent(this);
     Authentication    = new AuthenticationComponent(this);
     Authorization     = new AuthorizationComponent(this);
     Autoupdate        = new AutoupdateComponent(this);
     Break             = new BreakComponent(this);
     Context           = new ContextComponent(this);
     Core              = new CoreComponent(this);
     ForcedUser        = new ForcedUserComponent(this);
     HttpSessions      = new HttpSessionsComponent(this);
     Params            = new ParamsComponent(this);
     Pscan             = new PscanComponent(this);
     Reveal            = new RevealComponent(this);
     Script            = new ScriptComponent(this);
     Search            = new SearchComponent(this);
     Selenium          = new SeleniumComponent(this);
     SessionManagement = new SessionManagementComponent(this);
     Spider            = new SpiderComponent(this);
     Users             = new UsersComponent(this);
 }
Ejemplo n.º 3
0
        public void GetAuthenticationMethodConfigParameters(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] AuthenticationComponent sut,
            string authenticationMethodName,
            IEnumerable <ConfigurationParameter> authenticationMethodConfigParameters)
        {
            // ARRANGE
            var json = new JObject(
                new JProperty("methodConfigParams", JArray.FromObject(authenticationMethodConfigParameters)));

            httpClientMock.SetupApiCall(sut, CallType.View, "getAuthenticationMethodConfigParams",
                                        new Parameters
            {
                { "authMethodName", authenticationMethodName }
            })
            .Returns(json.ToString())
            .Verifiable();

            // ACT
            var result = sut.GetAuthenticationMethodConfigParameters(authenticationMethodName);

            // ASSERT
            result.ShouldBeEquivalentTo(authenticationMethodConfigParameters);
            httpClientMock.Verify();
        }
Ejemplo n.º 4
0
        public void SetAuthenticationMethod(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] AuthenticationComponent sut,
            int contextId,
            AuthenticationMethod authenticationMethod)
        {
            // ARRANGE
            var parameters = new Parameters
            {
                { "contextId", contextId },
                { "authMethodName", authenticationMethod.MethodName }
            };

            foreach (var parameter in authenticationMethod.Parameters)
            {
                parameters.Add(parameter.Key, parameter.Value);
            }
            httpClientMock.SetupApiCall(sut, CallType.Action, "setAuthenticationMethod", parameters)
            .ReturnsOkResult()
            .Verifiable();

            // ACT
            sut.SetAuthenticationMethod(contextId, authenticationMethod);

            // ASSERT
            httpClientMock.Verify();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Changes the password.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="oldPassword">The old password.</param>
        /// <param name="newPassword">The new password.</param>
        /// <param name="warningMessage">The warning message.</param>
        /// <returns>
        /// A <see cref="System.Boolean" /> value that indicates if the password change was successful. <c>true</c> if successful; otherwise <c>false</c>.
        /// </returns>
        /// <exception cref="System.Exception">Cannot change password on external service type</exception>
        public override bool ChangePassword(UserLogin user, string oldPassword, string newPassword, out string warningMessage)
        {
            warningMessage = null;
            AuthenticationComponent authenticationComponent = AuthenticationContainer.GetComponent(user.EntityType.Name);

            if (authenticationComponent == null || !authenticationComponent.IsActive)
            {
                throw new Exception(string.Format("'{0}' service does not exist, or is not active", user.EntityType.FriendlyName));
            }

            if (authenticationComponent.ServiceType == AuthenticationServiceType.External)
            {
                throw new Exception("Cannot change password on external service type");
            }

            if (!authenticationComponent.Authenticate(user, oldPassword))
            {
                return(false);
            }

            user.Password = authenticationComponent.EncodePassword(user, newPassword);
            user.LastPasswordChangedDateTime = RockDateTime.Now;

            return(true);
        }
Ejemplo n.º 6
0
        public async Task <bool> SetPassword(string oldPassword, string newPassword)
        {
            var user = await GetUser();

            var result = await AuthenticationComponent.TryChangePassword(user, oldPassword, newPassword);

            return(result);
        }
Ejemplo n.º 7
0
        public void ComponentName(
            [Greedy] AuthenticationComponent sut)
        {
            // ACT
            var result = sut.ComponentName;

            // ASSERT
            result.Should().Be("authentication");
        }
        public async Task <AuthorizationResponse> GetAuthorizationToken(string email, string password)
        {
            var jwtUser = await AuthenticationComponent.GetAuthorizationToken(email, password);

            return(new AuthorizationResponse
            {
                ConfirmationRequired = jwtUser.IsUserExists && !jwtUser.IsEmailConfirmed,
                Token = jwtUser.JwtToken
            });
        }
        public async Task <bool> ConfirmEmail(string guid, string confirmCode)
        {
            var user = await GetUserByGuid(guid);

            if (user == null)
            {
                return(false);
            }

            return(await AuthenticationComponent.TryConfirmEmail(user, confirmCode));
        }
        public async Task <bool> SendPasswordReset(string email)
        {
            var user = await GetUser(email);

            if (user == null)
            {
                return(false);
            }

            return(await AuthenticationComponent.TrySendPasswordReset(user));
        }
        public async Task <bool> ChangePassword(string guid, string confirmCode, string password)
        {
            var user = await GetUserByGuid(guid);

            if (user == null)
            {
                return(false);
            }

            return(await AuthenticationComponent.TryResetPassword(user, confirmCode, password));
        }
        public async Task <bool> SendEmail(string email)
        {
            var user = await GetUser(email);

            if (user == null)
            {
                return(false);
            }

            return(await AuthenticationComponent.TrySendEmailConfirmation(user));
        }
        public async Task SetFireBaseId([FromBody] string fireBaseId)
        {
            var user = await GetUser();

            if (user == null)
            {
                return;
            }

            await AuthenticationComponent.SetFireBaseId(user, fireBaseId);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Changes the password.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="password">The password.</param>
        public void ChangePassword(UserLogin user, string password)
        {
            if (user.ServiceType == AuthenticationServiceType.External)
            {
                throw new Exception("Cannot change password on external service type");
            }

            AuthenticationComponent authenticationComponent = GetComponent(user.ServiceName);

            if (authenticationComponent == null)
            {
                throw new Exception(string.Format("'{0}' service does not exist, or is not active", user.ServiceName));
            }

            user.Password = authenticationComponent.EncodePassword(user, password);
            user.LastPasswordChangedDate = DateTime.Now;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates a new user.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="serviceType">Type of the service.</param>
        /// <param name="serviceName">Name of the service.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="isConfirmed">if set to <c>true</c> [is confirmed].</param>
        /// <param name="currentPersonId">The current person id.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentOutOfRangeException">username;Username already exists</exception>
        /// <exception cref="System.ArgumentException">serviceName</exception>
        public UserLogin Create(Rock.Model.Person person,
                                AuthenticationServiceType serviceType,
                                string serviceName,
                                string username,
                                string password,
                                bool isConfirmed,
                                int?currentPersonId)
        {
            UserLogin user = this.GetByUserName(username);

            if (user != null)
            {
                throw new ArgumentOutOfRangeException("username", "Username already exists");
            }

            DateTime createDate = DateTime.Now;

            user                         = new UserLogin();
            user.ServiceType             = serviceType;
            user.ServiceName             = serviceName;
            user.UserName                = username;
            user.IsConfirmed             = isConfirmed;
            user.CreationDate            = createDate;
            user.LastPasswordChangedDate = createDate;
            if (person != null)
            {
                user.PersonId = person.Id;
            }

            if (serviceType == AuthenticationServiceType.Internal)
            {
                AuthenticationComponent authenticationComponent = GetComponent(serviceName);
                if (authenticationComponent == null)
                {
                    throw new ArgumentException(string.Format("'{0}' service does not exist, or is not active", serviceName), "serviceName");
                }

                user.Password = authenticationComponent.EncodePassword(user, password);
            }

            this.Add(user, currentPersonId);
            this.Save(user, currentPersonId);

            return(user);
        }
Ejemplo n.º 16
0
        public void GetSupportedAuthenticationMethods(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] AuthenticationComponent sut,
            IEnumerable <string> supportedAuthenticationMethods)
        {
            // ARRANGE
            var json = new JObject(
                new JProperty("supportedMethods", JArray.FromObject(supportedAuthenticationMethods)));

            httpClientMock.SetupApiCall(sut, CallType.View, "getSupportedAuthenticationMethods")
            .Returns(json.ToString())
            .Verifiable();

            // ACT
            var result = sut.GetSupportedAuthenticationMethods();

            // ASSERT
            result.ShouldBeEquivalentTo(supportedAuthenticationMethods);
            httpClientMock.Verify();
        }
Ejemplo n.º 17
0
        public void SetLoggedOutIndicator(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] AuthenticationComponent sut,
            int contextId,
            string indicatorRegex)
        {
            // ARRANGE
            httpClientMock.SetupApiCall(sut, CallType.Action, "setLoggedOutIndicator",
                                        new Parameters
            {
                { "contextId", contextId },
                { "loggedOutIndicatorRegex", indicatorRegex },
            })
            .ReturnsOkResult()
            .Verifiable();

            // ACT
            sut.SetLoggedOutIndicator(contextId, indicatorRegex);

            // ASSERT
            httpClientMock.Verify();
        }
Ejemplo n.º 18
0
        public void GetAuthenticationMethod(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] AuthenticationComponent sut,
            int contextId,
            AuthenticationMethod authenticationMethod)
        {
            // ARRANGE
            var json = JObject.FromObject(authenticationMethod);

            httpClientMock.SetupApiCall(sut, CallType.View, "getAuthenticationMethod",
                                        new Parameters
            {
                { "contextId", contextId }
            })
            .Returns(json.ToString())
            .Verifiable();

            // ACT
            var result = sut.GetAuthenticationMethod(contextId);

            // ASSERT
            result.ShouldBeEquivalentTo(authenticationMethod);
            httpClientMock.Verify();
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            //Display general Info
            printLogo();

            Console.Title = "Wolpertinger Fileserver";
            Console.WriteLine();
            ConsoleHelper.WriteLine(ConsoleColor.Red, " Wolpertinger.FileServer {0}", Assembly.GetExecutingAssembly().GetName().Version.ToString());
            ConsoleHelper.WriteLine(ConsoleColor.Red, " Wolpertinger.Core       {0}", Assembly.GetAssembly(typeof(DefaultConnectionManager)).GetName().Version.ToString());
            Console.WriteLine();

            //Set up XmlSerializer
            XmlSerializer.RegisterType(typeof(ClientInfo), "clientInfo");
            XmlSerializer.RegisterType(typeof(DirectoryObject), "directoryObject");
            XmlSerializer.RegisterType(typeof(FileObject), "fileObject");
            XmlSerializer.RegisterType(typeof(Permission), "permission");
            XmlSerializer.RegisterType(typeof(MountInfo), "mountInfo");
            XmlSerializer.RegisterType(typeof(SnapshotInfo), "snapshotInfo");
            XmlSerializer.RegisterType(typeof(RemoteMethodCall), "remoteMethodCall");
            XmlSerializer.RegisterType(typeof(RemoteMethodResponse), "remoteMethodResponse");
            XmlSerializer.RegisterType(typeof(RemoteError), "remoteError");


            //Set up logger
            LoggerService.SetLogger(new CompositeLogger(new Wolpertinger.Core.ConsoleLogger(), new XmppLogger()));
            logger = LoggerService.GetLogger("Wolpertinger.Fileserver");


            FileObject.HashingService = HashingService.GetHashingService();

            AuthenticationComponent foo = new AuthenticationComponent();


            if (!Directory.Exists(Path.GetDirectoryName(folder)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(folder));
            }

            //Set up AppData directory
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            //Set up databasefolder
            if (!Directory.Exists(DatabaseFolder))
            {
                Directory.CreateDirectory(DatabaseFolder);
            }


            //Initalize ConnectionManager
            //TODO manager.AddProfile(Profile.FileServer);
            //manager.AddComponent(typeof(ClientInfoProvider), typeof(XmppLoggingConfigurator), typeof(FileShare));

            connectionManager = new DefaultConnectionManager();
            //connectionManager.ComponentFactory = new DefaultComponentFactory();
            connectionManager.LoadSettings(folder);
            //connectionManager.Connect();
            connectionManager.AcceptIncomingConnections = true;
            XmppLogger.ConnectionManager = connectionManager;
            XmppLogger.LoadSettings();

            //Load setting specific to this role
            connectionManager.WolpertingerUsername = settingsFile.GetItem <string>("AdminUsername");
            connectionManager.WolpertingerPassword = settingsFile.GetItem <string>("AdminPassword").ToSecureString();


            FileShareServerComponent.Init();

            //Console.WriteLine("Account: " + connectionManager.XmppUsername + "@" + connectionManager.XmppServer);

            Console.ReadLine();
        }
Ejemplo n.º 20
0
        public Session(string target, IConnectionManager connectionManager)
        {
            this.connectionManager = connectionManager;

            this.Target = target;
            this.Name   = target;

            this.connection = connectionManager.GetClientConnection(target);
            if (connection == null)
            {
                connection = connectionManager.AddClientConnection(target);
                connection.ConnectionReset     += connection_ConnectionReset;
                connection.ConnectionTimedOut  += connection_ConnectionTimedOut;
                connection.RemoteErrorOccurred += connection_RemoteErrorOccurred;
            }
            //authComponent = (AuthenticationComponent)connection.GetClientComponent(ComponentNamesExtended.Authentication);
            //clientInfoComponent = (ClientInfoClientComponent)connection.GetClientComponent(ComponentNamesExtended.ClientInfoProvider);
            //loggingConfigurator = (XmppLoggingConfiguratorComponent)connection.GetClientComponent(ComponentNamesExtended.XmppLoggingConfigurator);
            //fileShareComponent = (FileShareClientComponent)connection.GetClientComponent(ComponentNamesExtended.FileShare);

            authComponent = new AuthenticationComponent()
            {
                ClientConnection = connection
            };
            clientInfoComponent = new ClientInfoClientComponent()
            {
                ClientConnection = connection
            };
            loggingConfigurator = new XmppLoggingConfiguratorComponent()
            {
                ClientConnection = connection
            };
            fileShareComponent = new FileShareClientComponent()
            {
                ClientConnection = connection
            };


            //CommandInfo info = new CommandInfo();

            commands.Add("get-status", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = getStatusCommand, CheckConnection = false
            });
            commands.Add("connect", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = connectCommand, CheckConnection = false
            });
            commands.Add("disconnect", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = disconnectCommand
            });
            commands.Add("userauth", new CommandInfo()
            {
                ParameterCount = 1, CommandMethod = userauthCommand
            });
            commands.Add("get-info", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = getInfoCommand
            });
            commands.Add("exit-session", new CommandInfo()
            {
                CheckConnection = false, ParameterCount = 0, CommandMethod = exitSessionCommand
            });


            commands.Add("logger.get-enabled", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = loggerGetEnabledCommand
            });
            commands.Add("logger.set-enabled", new CommandInfo()
            {
                ParameterCount = 1, CommandMethod = loggerSetEnabledCommand
            });
            commands.Add("logger.get-loglevel", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = loggerGetLogLevelCommand
            });
            commands.Add("logger.set-loglevel", new CommandInfo()
            {
                ParameterCount = 1, CommandMethod = loggerSetLogLevelCommand
            });
            commands.Add("logger.get-recipient", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = loggerGetRecipientCommand
            });
            commands.Add("logger.set-recipient", new CommandInfo()
            {
                ParameterCount = 1, CommandMethod = loggerSetRecipientCommand
            });
            commands.Add("logger.get-debuglogging", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = loggerGetDebugLoggingCommand
            });
            commands.Add("logger.set-debuglogging", new CommandInfo()
            {
                ParameterCount = 1, CommandMethod = loggerSetDebugLoggingCommand
            });
            commands.Add("logger.test-logging", new CommandInfo()
            {
                ParameterCount = 1, CommandMethod = loggerTestLoggingCommand
            });

            commands.Add("fileshare.add-directory", new CommandInfo()
            {
                ParameterCount = 2, CommandMethod = fileshareAddDirectoryCommand
            });
            commands.Add("fileshare.remove-directory", new CommandInfo()
            {
                ParameterCount = 1, CommandMethod = fileshareRemoveDirectoryCommand
            });
            commands.Add("fileshare.get-directory", new CommandInfo()
            {
                ParameterCount = 1, CommandMethod = fileshareGetDirectoryCommand
            });
            commands.Add("fileshare.get-file", new CommandInfo()
            {
                ParameterCount = 1, CommandMethod = fileshareGetFileCommand
            });
            commands.Add("fileshare.add-permission", new CommandInfo()
            {
                ParameterCount = -2, CommandMethod = fileshareAddPermissionCommand
            });
            commands.Add("fileshare.remove-permission", new CommandInfo()
            {
                ParameterCount = 1, CommandMethod = fileshareRemovePermissionCommand
            });
            commands.Add("fileshare.get-mounts", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = fileshareGetMountsCommand
            });
            commands.Add("fileshare.check-permission", new CommandInfo()
            {
                ParameterCount = 1, CommandMethod = fileshareCheckPermissionCommand
            });
            commands.Add("fileshare.get-permissions", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = fileshareGetPermissionsCommand
            });
            commands.Add("fileshare.get-rootdirectory", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = fileshareGetRootDirectoryCommand
            });
            commands.Add("fileshare.set-rootdirectory", new CommandInfo()
            {
                ParameterCount = 1, CommandMethod = fileshareSetRootDirectoryCommand
            });

            commands.Add("fileshare.create-snapshot", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = fileshareCreateSnapshotCommand
            });
            commands.Add("fileshare.get-snapshots", new CommandInfo()
            {
                ParameterCount = 0, CommandMethod = fileshareGetSnapshotsCommand
            });
        }
 public async Task <bool> Register(UserCData user)
 {
     return(await AuthenticationComponent.TryRegister(user));
 }