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);
        }
        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>());
            });
        }
        /// <inheritdoc />
        public IAuthenticationService GetAuthenticationService(ApiContext context)
        {
            const string standardLoginEndpoint = "login";

            try
            {
                return(AuthenticationServiceFactory.Create(context, Host, standardLoginEndpoint));
            }
            catch (NotImplementedException)
            {
                return(null);
            }
        }
示例#4
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"));
        }
示例#5
0
 protected AbstractAuthenticationController()
 {
     _authService = AuthenticationServiceFactory.Create();
 }
示例#6
0
 public void Logout()
 {
     AuthenticationServiceFactory.Create().Logout();
     GravarLogAcesso(UsuarioLogado.HostName, UsuarioLogado.Login, "OUT");
 }
示例#7
0
 protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
 {
     AuthenticationServiceFactory.Create().PostAuthenticateRequest();
 }