public void GetServiceTest()
        {
            var sut = new AuthenticationServiceFactory();

            Assert.IsNotNull(sut);
            Assert.ThrowsException <ArgumentNullException>(() => sut.GetService(null));
            Assert.IsNotNull(sut.GetService(new Mock <IVstsApplication>().Object));
        }
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            var authSrv = new AuthenticationServiceFactory().GetService();

            if (authSrv.HasPermissionsToPdbTab() == false)
            {
                authSrv.RedirectPermissionDenied();
            }
        }
        public void Create_IfServiceForAuthMethodExists_ReturnsService(AuthenticationMethod authMethod, Type expectedType)
        {
            var context = new ApiContext(It.IsAny <Environments>())
            {
                AuthenticationMethod = authMethod
            };

            var service = AuthenticationServiceFactory.Create(context, It.IsAny <string>(), It.IsAny <string>());

            Assert.IsInstanceOf(expectedType, service);
        }
示例#4
0
        static void ConfigureFactories()
        {
            //LoggerFactory.SetCurrent(new TraceSourceLogFactory());
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            AuthenticationServiceFactory.SetCurrent(new FormsAuthenticationFactory());

            var typeAdapterFactory = currentContainer.Resolve <ITypeAdapterFactory>();

            TypeAdapterFactory.SetCurrent(typeAdapterFactory);
        }
        Create_IfServiceForAuthMethodDoesNotExist_ThrowsNotImplementedException(AuthenticationMethod authMethod)
        {
            var context = new ApiContext(It.IsAny <Environments>())
            {
                AuthenticationMethod = authMethod
            };

            Assert.Throws <NotImplementedException>(() =>
            {
                AuthenticationServiceFactory.Create(context, It.IsAny <string>(), It.IsAny <string>());
            });
        }
示例#6
0
 protected void Application_PostAcquireRequestState(object sender, EventArgs e)
 {
     if (HttpContext.Current.Request.CurrentExecutionFilePathExtension == ".aspx" ||
         HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.StartsWith("~/mvc/"))
     {
         var authSrv = new AuthenticationServiceFactory().GetService();
         if (authSrv.HasPermissionsToPdbTab() == false)
         {
             authSrv.RedirectPermissionDenied();
         }
     }
 }
        /// <inheritdoc />
        public IAuthenticationService GetAuthenticationService(ApiContext context)
        {
            const string standardLoginEndpoint = "login";

            try
            {
                return(AuthenticationServiceFactory.Create(context, Host, standardLoginEndpoint));
            }
            catch (NotImplementedException)
            {
                return(null);
            }
        }
示例#8
0
        public void Initialize()
        {
            AuthenticationServiceFactory.SetCurrent(new FormsAuthenticationFactory());
            TypeAdapterFactory.SetCurrent(new AutomapperTypeAdapterFactory());
            MapperHelper.Initialise();

            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            var unitOfWork = new UnitOfWork();

            parametrosOrdemCompraRepository = new Infrastructure.Data.Repository.OrdemCompra.ParametrosOrdemCompraRepository(unitOfWork);
            messageQueue = new MessageQueue();
            parametrosOrcamentoRepository = new ParametrosOrcamentoRepository(unitOfWork);
            parametrosContratoRepository  = new ParametrosContratoRepository(unitOfWork);
            parametrosOrcamentoAppService = new ParametrosOrcamentoAppService(parametrosOrcamentoRepository, messageQueue);
            parametrosContratoAppService  = new ParametrosContratoAppService(parametrosContratoRepository, messageQueue);
        }
示例#9
0
        public void Initialize()
        {
            //System.Data.Entity.Database.SetInitializer<UnitOfWork>(new System.Data.Entity.DropCreateDatabaseAlways<UnitOfWork>());
            TypeAdapterFactory.SetCurrent(new AutomapperTypeAdapterFactory());
            MapperHelper.Initialise();

            AuthenticationServiceFactory.SetCurrent(new FormsAuthenticationFactory());

            messageQueue = new MessageQueue();

            unitOfWork          = new UnitOfWork();
            usuarioRepository   = new UsuarioRepository(unitOfWork);
            logAcessoRepository = new LogAcessoRepository(unitOfWork);
            moduloRepository    = new ModuloRepository(unitOfWork);
            perfilRepository    = new PerfilRepository(unitOfWork);

            usuarioService = new UsuarioAppService(usuarioRepository, logAcessoRepository, perfilRepository, moduloRepository, messageQueue);
        }
    void Awake()
    {
        if (Client != null)
        {
            return;
        }

        var pluginHost = ClientFactory.GetPluginHost(appKey, "development");

        AuthFactory = new AuthenticationServiceFactory(pluginHost);

        Client = UnityClientFactory.GetClient(pluginHost);

        Client.OnConnected       += Client_OnConnected;
        Client.OnFailedToConnect += Client_OnFailedToConnect;
        Client.OnDisconnected    += Client_OnDisconnected;
        Client.Connect();
    }
        public void AuthenticationService_Database_CanRegisterAndLogin()
        {
            // Arrange
            var service = AuthenticationServiceFactory.GetAuthenticationServiceDatabase();

            // Act
            try
            {
                service.Register("*****@*****.**", "mypassword");
            }
            catch (ArgumentException)
            {
            }

            var loggedIn = service.Login("*****@*****.**", "mypassword");

            // Assert
            Assert.IsTrue(loggedIn);
        }
示例#12
0
        public void Initialize()
        {
            AuthenticationServiceFactory.SetCurrent(new FormsAuthenticationFactory());
            TypeAdapterFactory.SetCurrent(new AutomapperTypeAdapterFactory());
            MapperHelper.Initialise();

            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            var unitOfWork = new UnitOfWork();

            parametrosUsuarioRepository = new ParametrosUsuarioRepository(unitOfWork);
            usuarioRepository           = new UsuarioRepository(unitOfWork);
            logAcessoRepository         = new LogAcessoRepository(unitOfWork);
            centroCustoRepository       = new CentroCustoRepository(unitOfWork);
            moduloRepository            = new ModuloRepository(unitOfWork);
            perfilRepository            = new PerfilRepository(unitOfWork);
            messageQueue       = new MessageQueue();
            usuarioAppService  = new UsuarioAppService(usuarioRepository, logAcessoRepository, perfilRepository, moduloRepository, messageQueue);
            centroCustoService = new CentroCustoAppService(centroCustoRepository, usuarioAppService, messageQueue);
        }
        public ValidationResult SaveSettings(HttpRequestMessage config)
        {
            try
            {
                var _authService        = new AuthenticationServiceFactory().GetService();
                var parsedConfiguration = JsonConvert.DeserializeObject <PerformanceDashboardConfigurationSettings>(config.Content.ReadAsStringAsync().Result);

                parsedConfiguration.LastModifiedBy = _authService.GetUserId() != -1 ? _authService.GetUserId().ToString() : "Unknown";
                var result = configurationService.ValidateConfiguration(parsedConfiguration);
                if (result.Valid)
                {
                    configurationService.SetConfiguration(parsedConfiguration);
                }
                return(result);
            }
            catch (Exception ex)
            {
                return(new ValidationResult {
                    Valid = false, Details = ex.ToString()
                });
            }
        }
示例#14
0
        static void Main(string[] args)
        {
            Username = Console.ReadLine();
            if (string.IsNullOrEmpty(Username))
            {
                Username = "******";
            }

            var pluginHost = ClientFactory.GetPluginHost(appKey, "development");

            AuthFactory               = new AuthenticationServiceFactory(pluginHost);
            Client                    = ClientFactory.GetClient(pluginHost);
            Client.OnConnected       += Client_OnConnected;
            Client.OnFailedToConnect += Client_OnFailedToConnect;
            Client.OnDisconnected    += Client_OnDisconnected;
            Console.WriteLine("Connecting");
            Client.Connect();

            Console.WriteLine("Press any key to stop the test");
            Console.Read();
            Console.WriteLine("Test stopped");
        }
示例#15
0
        public void EfetuarLoginObterUsuarioLogado()
        {
            AuthenticationServiceFactory.SetCurrent(new FormsAuthenticationFactory());
            authenticationService = AuthenticationServiceFactory.Create();

            var serializeModel = new CustomPrincipalSerializeModel();

            serializeModel.Id    = 1;
            serializeModel.Nome  = "Wilson Marques";
            serializeModel.Login = "******";
            serializeModel.Roles = new string[] { "Gerente", "Coordenador", "Administrador" };

            var serializer = new JavaScriptSerializer();
            var userData   = serializer.Serialize(serializeModel);

            authenticationService.Login(serializeModel.Nome, true, userData, 20);
            authenticationService.PostAuthenticateRequest();
            var user = authenticationService.GetUser();

            Assert.IsNotNull(user);
            Assert.IsInstanceOfType(user, typeof(CustomPrincipal));
            Assert.AreEqual("wilson", user.Login);
            Assert.IsTrue(user.IsInRole("Gerente"));
        }
示例#16
0
 protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
 {
     AuthenticationServiceFactory.Create().PostAuthenticateRequest();
 }
示例#17
0
 public void Logout()
 {
     AuthenticationServiceFactory.Create().Logout();
     GravarLogAcesso(UsuarioLogado.HostName, UsuarioLogado.Login, "OUT");
 }
示例#18
0
        static async Task <int> Main(string[] args)
        {
            // We don't have access to a built host yet. Get configuration settings using a configuration builder.
            // Required to set initial token credentials.
            var configBuilder = new ConfigurationBuilder();

            ConfigureAppConfiguration(configBuilder);
            var config = configBuilder.Build();

            var authSettings       = config.GetSection(nameof(AuthenticationOptions)).Get <AuthenticationOptions>();
            var authServiceFactory = new AuthenticationServiceFactory(new PathUtility());
            var authStrategy       = AuthenticationStrategy.DeviceCode;

            var credential = await authServiceFactory.GetTokenCredentialAsync(authStrategy, authSettings?.TenantId, authSettings?.ClientId);

            var authProvider = new AzureIdentityAuthenticationProvider(credential, new string[] { "graph.microsoft.com" });

            var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version;
            var options         = new GraphClientOptions {
                GraphProductPrefix = "graph-cli",
                GraphServiceLibraryClientVersion = $"{assemblyVersion.Major}.{assemblyVersion.Minor}.{assemblyVersion.Build}",
                GraphServiceTargetVersion        = "1.0"
            };

            using var httpClient = GraphCliClientFactory.GetDefaultClient(options);
            var core   = new HttpClientRequestAdapter(authProvider, httpClient: httpClient);
            var client = new GraphClient(core);

            var commands     = new List <Command>();
            var loginCommand = new LoginCommand(authServiceFactory);

            commands.Add(loginCommand.Build());

            var logoutCommand = new LogoutCommand(new LogoutService());

            commands.Add(logoutCommand.Build());

            var builder = BuildCommandLine(client, commands).UseDefaults().UseHost(CreateHostBuilder);

            builder.AddMiddleware((invocation) => {
                var host                   = invocation.GetHost();
                var outputFilter           = host.Services.GetRequiredService <IOutputFilter>();
                var outputFormatterFactory = host.Services.GetRequiredService <IOutputFormatterFactory>();
                invocation.BindingContext.AddService <IOutputFilter>(_ => outputFilter);
                invocation.BindingContext.AddService <IOutputFormatterFactory>(_ => outputFormatterFactory);
            });
            builder.UseExceptionHandler((ex, context) => {
                if (ex is AuthenticationRequiredException)
                {
                    Console.ResetColor();
                    Console.ForegroundColor = ConsoleColor.Red;
                    context.Console.Error.WriteLine("Token acquisition failed. Run mgc login command first to get an access token.");
                    Console.ResetColor();
                }
                else
                {
                    Console.ResetColor();
                    Console.ForegroundColor = ConsoleColor.Red;
                    context.Console.Error.WriteLine(ex.Message);
                    context.Console.Error.WriteLine(ex.StackTrace);
                    Console.ResetColor();
                }
            });

            var parser = builder.Build();

            return(await parser.InvokeAsync(args));
        }
示例#19
0
 protected AbstractAuthenticationController()
 {
     _authService = AuthenticationServiceFactory.Create();
 }
        protected override bool IsAuthorized(HttpActionContext actionContext)
        {
            var authSrv = new AuthenticationServiceFactory().GetService();

            return(authSrv.IsSystemAdministrator());
        }