Пример #1
0
        public CouchSessionFactory(string uriBase, IUserCredential userCredential, AuthenticationLevel authLevel)
            : base(uriBase, userCredential, authLevel)
        {
            if (string.IsNullOrWhiteSpace(uriBase))
                throw new CouchParameterException("UriBase on IJSessionConfig cannot be empty or null.", "uriBase");

            if (userCredential == null)
                throw new CouchParameterException("userCredential on IJSessionConfig cannot be null.", "userCredential");

            try
            {
                this.EchoCouch();
            }
            catch (Exception ex)
            {
                throw new CouchException(ex.Message, ex);
            }

            serializerSettings = new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore,
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                    TypeNameHandling = TypeNameHandling.None,
                    ContractResolver = new CamelCasePropertyNamesContractResolver(),
                    ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
                };

            this.sessionUsers = new HashSet<IJDocumentSession>();
        }
Пример #2
0
        public DatabaseValidator(IUserCredential credential, IDatabaseRepository databaseRepository, IUserRepository userRepository)
        {
            this.credential         = credential ?? throw new NullReferenceException("User credentials doesn't exist.");
            this.databaseRepository = databaseRepository;
            this.userRepository     = userRepository;

            ConnectionStatus = ConnectionStatus.Failure;
        }
        public async Task <JsonResult> Login([FromBody] IUserCredential userCredential)
        {
            var apiResponse = await this.httpClient.PostAsync(this.serviceUrls.Authenticate, JsonConvert.SerializeObject(userCredential));

            var apiResult = JsonConvert.DeserializeObject <dynamic>(apiResponse.Content);

            return(this.Json(apiResult));
        }
Пример #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="uriBase"></param>
        /// <param name="userCredential"></param>
        /// <param name="authLevel"></param>
        protected internal CouchStoreChannel(string uriBase, IUserCredential userCredential, AuthenticationLevel authLevel)
        {
            if (string.IsNullOrWhiteSpace(uriBase))
                throw new CouchParameterException("UriBase on IJSessionConfig cannot be empty or null.", "uriBase");

            this.uriBase = uriBase;
            this.userCredential = userCredential;
            this.authLevel = authLevel;
        }
Пример #5
0
        /// ログイン
        /// </summary>
        /// <param name="credential"></param>
        /// <returns></returns>
        public async Task <bool> Login(IUserCredential credential)
        {
            if (this.context.IsLogin)
            {
                return(true);
            }

            bool result = await this.context.LoginAsync(credential.Username, credential.Password);

            return(result);
        }
Пример #6
0
        public IValidUser IsValidEntity(IUserCredential userCredential)
        {
            var param = new Specification <UserCredential>(x => (x.UserName == userCredential.UserName &&
                                                                 x.Password == userCredential.Password));
            var entity = UserRepository.GetBySpecification(param).FirstOrDefault();

            if (entity == null)
            {
                return(new ValidUser
                {
                    Id = 0,
                    isValid = false
                });
            }
            return(new ValidUser
            {
                Id = entity.Id,
                isValid = true
            });
        }
Пример #7
0
        public async Task <SignUpResponse> SignUp(IUserCredential userCredentialImp)
        {
            var signUpRequest = new SignUpRequest
            {
                ClientId = _clientId,
                Password = userCredentialImp.Password,
                Username = userCredentialImp.Username
            };
            var emailAttribute = new AttributeType
            {
                Name  = "email",
                Value = userCredentialImp.Email
            };
            var nicknameAttribute = new AttributeType
            {
                Name  = "nickname",
                Value = userCredentialImp.Username
            };

            signUpRequest.UserAttributes.Add(nicknameAttribute);
            signUpRequest.UserAttributes.Add(emailAttribute);
            return(await _client.SignUpAsync(signUpRequest));
        }
Пример #8
0
        public bool Authenticate(IUserCredential tool, string role)
        {
            if (IsStandAlone)
            {
                UserIdentity principal = new UserIdentity(UserInfo.Empty, true, new TimeSpan(0), "local");
                AppDomain.CurrentDomain.SetThreadPrincipal(principal);

                _userCollection.Add(principal);
            }
            else
            {
                if (_loginServiceClient == null)
                {
                    _callBack = new LoginServiceCallback(_userCollection);
                    _loginServiceClient = new DuplexClient<ILoginService>(new InstanceContext(_callBack), _configuration.PingInterval);
                    _loginServiceClient.Open();
                    _loginServiceClient.OnChanged += new EventHandler<ClientState>(_loginServiceClient_OnChanged);
                }
                string loginName, password;
            again: ;

                if (tool.GetUserCredential(out loginName, out password))
                {
                    byte[] hash = SecurityUtils.PasswordToHash(password);

                    UserIdentity principal = loginService.Login(loginName, hash, Environment.MachineName);
                    if (principal == null || !principal.IsAuthenticated)
                    {
                        tool.FailedLogin();
                        goto again;
                    }

                    if (role != null && !principal.IsInRole(role))
                    {
                        tool.FailedRole(role);
                        loginService.Logoff(principal);
                        goto again;
                    }

                    AppDomain.CurrentDomain.SetThreadPrincipal(principal);

                    loginService.Subscribe(principal);

                    _userCollection.AddRange(loginService.GetUserLoginCollection());
                }
                else
                {
                    return false;
                    //throw new ApplicationException("User cancel");
                }
            }
            return true;
        }
Пример #9
0
 public RtAccountApiController()
 {
     _emplpoyeeRepository = RTUnityMapper.GetInstance <IEmployee>();
     _userCredential      = RTUnityMapper.GetInstance <IUserCredential>();
 }
Пример #10
0
 public UserCredentialService(IUserCredential userCredential)
 {
     _userCredential = userCredential;
 }
Пример #11
0
 public Account(IEnumerable <IValidator> validators, IUserCredential userCredential)
 {
     this.userCredential = userCredential ?? throw new NullReferenceException("Credentials doesn't exist");
     this.validators     = validators ?? throw new NullReferenceException("Validators doesn't exist.");
     AccountStatus       = AccountStatus.NotLogged;
 }
Пример #12
0
        private IJDocumentSession GetSession(string databaseName, IUserCredential credential, AuthenticationLevel level)
        {
            IJDocumentSession session = this.sessionUsers.FirstOrDefault(
                advSession =>
                advSession.AuthLevel == level && advSession.DatabaseName.Equals(databaseName) &&
                advSession.UserCredential.Equals(credential));

            if (session == null)
            {
                session = new CouchDocumentSession(this.UriBase, databaseName, credential, level,
                                                   this.SerializerSettings);
                this.sessionUsers.Add(session);
            }

            return session;
        }
Пример #13
0
 public IJDocumentSession OpenSession(string databaseName, IUserCredential credential, AuthenticationLevel level)
 {
     return this.GetSession(databaseName, credential, level);
 }
Пример #14
0
 public DomainValidator(IUserCredential userCredential)
 {
     this.userCredential = userCredential ?? throw new NullReferenceException("User credentials doesn't exist");
     ConnectionStatus    = ConnectionStatus.Failure;
 }
Пример #15
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="timeout"></param>
 /// <param name="credential"></param>
 public CouchWebHttpRequest(string uri, int timeout, IUserCredential credential)
     : this(uri, timeout)
 {
     if (credential != null)
         customRequest.Headers.Add("Authorization", credential.Encode());
 }
Пример #16
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="credential"></param>
 public CouchWebHttpRequest(string uri, IUserCredential credential)
     : this(uri, 1000, credential)
 {
 }
Пример #17
0
 public AccountFactory(DomainValidator domainValidator, DatabaseValidator databaseValidator, IUserCredential userCredential)
 {
     this.userCredential    = userCredential;
     this.domainValidator   = domainValidator ?? throw new NullReferenceException("Domain validator doesn't exist.");;
     this.databaseValidator = databaseValidator ?? throw new NullReferenceException("Database validator doesn't exist.");;;
 }
Пример #18
0
 public IJDocumentResponse DeleteAdminUser(IUserCredential credential)
 {
     throw new NotImplementedException();
 }