Exemplo n.º 1
0
        public string SignIn(Credential credential)
        {
            try
            {
                string user = credential.user;
                string pass = credential.pass;
                if (PdpUserProvider.IsValidUser(user, pass))
                {
                    Interlocked.Increment(ref actives_users);
                    Interlocked.Increment(ref accesscounter);

                    Session session = new Session();
                    session.user = user;

                    using (var connect = new Connect())
                    {
                        connect.BeginTrx();
                        SqlConnection sqlconn = connect.GetConnection();
                        var           smapper = new SessionDataMapper(sqlconn);
                        smapper.SetTransaction(connect.Transaction);
                        //smapper.Insert(session);
                    }



                    return(authProvider.AutenticateUser(credential));
                }
                return(null);
            }

            catch (Exception exception)
            {
                throw new FaultException <ServerError>(new ServerError());
            }
        }
Exemplo n.º 2
0
        private bool IsAuthorized(string method, string resource)
        {
            string            token   = null;
            MessageProperties msgProp = OperationContext.Current.IncomingMessageProperties;
            var ctxProperty           = msgProp[ContextMessageProperty.Name] as ContextMessageProperty;

            if (ctxProperty.Context.ContainsKey("AccessToken"))
            {
                token = ctxProperty.Context["AccessToken"];
                AutenticationToken authToken = authProvider.GetAutenticationToken(token);

                if (authToken == null || authToken.expire < DateTime.Now)
                {
                    return(false);
                }

                return(PdpUserProvider.IsAutorized(authToken.credential.user, method, resource));
            }
            return(false);
        }
Exemplo n.º 3
0
        public override void Validate(string userName, string password)
        {
            if (userName == null || password == null)
            {
                throw new FaultException("userName cannot be null");
            }

            bool valid = false;

            try
            {
                valid = PdpUserProvider.IsValidUser(userName, password);
            }

            catch (Exception exception)
            {
                throw new Exception("Internal Server Error");
            }

            if (!valid)
            {
                throw new Exception("Incorrect credentials");
            }
        }