Example #1
0
        static public CASTicketResult GetToken(DbBase database, Uri service, String grantTicket, String username)
        {
            CASTicketResult ret = null;

            if (service != null)
            {
                DataTable dtTickets = database.ExecuteDataTable(String.Format("select * from [CAS_Ticket] where [Service_Uri] = '{0}' and (Grant_Ticket = '{1}' or User_Name = '{2}')", CASPluginService.Normalize(service).AbsoluteUri, grantTicket, username));
                if ((dtTickets != null) && (dtTickets.Rows.Count > 0))
                {
                    ret                     = new CASTicketResult();
                    ret.Success             = true;
                    ret.Service             = CASPluginService.Normalize(dtTickets.Rows[0]["Service_Uri"].ToString());
                    ret.UserId              = dtTickets.Rows[0]["User_Id"].ToString();
                    ret.UserName            = dtTickets.Rows[0]["User_Name"].ToString();
                    ret.GrantTicket         = dtTickets.Rows[0]["Grant_Ticket"].ToString();
                    ret.LongTicket          = dtTickets.Rows[0]["Long_Ticket"].ToString();
                    ret.ProxyTicket         = dtTickets.Rows[0]["Proxy_Ticket"].ToString();
                    ret.CreateDate          = (DateTime)dtTickets.Rows[0]["Create_Date"];
                    ret.Expires             = (DateTime)dtTickets.Rows[0]["Expires"];
                    ret.CreateByCredentials = (Boolean)dtTickets.Rows[0]["Create_By_Credentials"];
                }
            }

            if (ret == null)
            {
                ret = new CASTicketResult();
            }

            if (ret.Success)
            {
                if (service == null)
                {
                    ret.Success = false;
                    return(ret);
                }

                //Verifica se o ticket pode ser validado no serviço atual
                if ((ret.Service == null) || (!ret.Service.Equals(service)))
                {
                    if (database.ExecuteScalar <Int64>(String.Format("select COUNT(*) from [CAS_Service] where Uri = '{0}' and Context_Name = (select Context_Name from [CAS_Service] where Uri = '{1}')", CASPluginService.Normalize(service).AbsoluteUri, ret.Service.AbsoluteUri)) > 0)
                    {
                        ret.CreateByCredentials = false; //Define que as informações foram copiadas de outro token e não a partir de uma autenticação usuário/senha
                    }
                    else
                    {
                        ret.Success = false;
                    }
                }

                //Define o serviço atual
                ret.Service = service;

                //Salva o token copiado
                //ret.SaveToFile(basePath);
                ret.SaveToDb(database);
            }

            return(ret);
        }
Example #2
0
 public CASUserInfo(CASTicketResult ticket)
     : base()
 {
     this.Success    = ticket.Success;
     this.Service    = ticket.Service;
     this.UserName   = ticket.UserName;
     this.ErrorText  = ticket.ErrorText;
     this.Attributes = ticket.Attributes;
 }
Example #3
0
        public void DestroyTicket(String ticket, String username)
        {
            CASTicketResult t = CASTicketResult.GetToken(this.Database, Service, ticket, username);

            if (t.Success)
            {
                t.Destroy(this.Database);
            }
        }
Example #4
0
        public void DestroyTicket(String ticket, String username)
        {
            CASTicketResult t = CASTicketResult.GetToken(Path.Combine(BasePath.FullName, "tickets"), Service, ticket, username);

            if (t.Success)
            {
                t.Destroy(BasePath.FullName);
            }
        }
Example #5
0
        public CASTicketResult Grant(String username, String password)
        {
            //Checa se ha um ticket para este usuário
            CASTicketResult t = CASTicketResult.GetToken(this.Database, Service, null, username);

            if ((!t.Success) && (t.UserName != username))
            {
                t = null;
            }

            String   checkLog = "";
            LogEvent l        = new LogEvent(delegate(Object sender, PluginLogType type, String text)
            {
                if (type == PluginLogType.Error)
                {
                    checkLog += text + Environment.NewLine;
                }
            });

            this.Log += l;

            CASTicketResult ret = new CASTicketResult();

            try
            {
                if (!CheckInputConfig(this.Config, true, l))
                {
                    throw new Exception("Erro on check configurarion", new Exception(checkLog));
                }

                ret = iGrant(t, username, password);
            }
            catch { }

            this.Log -= l;

            //Se houver um ticket para este usuário utiliza os mesmos tokens
            if ((t != null) && (t.Success) && (t.UserName == ret.UserName))
            {
                ret.GrantTicket = t.GrantTicket;
                ret.LongTicket  = t.LongTicket;
                ret.ProxyTicket = t.ProxyTicket;
            }

            return(ret);
        }
Example #6
0
        //Valida através dos tokens existentes
        public CASTicketResult Grant(String ticket, Boolean renew, Boolean warm)
        {
            if (renew)
            {
                return(new CASTicketResult("Renew selected"));
            }

            CASTicketResult tgc = CASTicketResult.GetToken(this.Database, Service, ticket);

            if (warm && !tgc.CreateByCredentials)
            {
                return(new CASTicketResult());
            }
            else
            {
                return(tgc);
            }
        }
Example #7
0
        //Valida através dos tokens existentes
        public CASTicketResult Grant(String ticket, Boolean renew, Boolean warm)
        {
            if (renew)
            {
                return(new CASTicketResult("Renew selected"));
            }

            CASTicketResult tgc = CASTicketResult.GetToken(Path.Combine(BasePath.FullName, "tickets"), Service, ticket);

            if (warm && !tgc.CreateByCredentials)
            {
                return(new CASTicketResult());
            }
            else
            {
                return(tgc);
            }
        }
Example #8
0
        public Object Clone()
        {
            CASTicketResult newItem = new CASTicketResult();

            newItem.Success                 = this.Success;
            newItem.Service                 = CASPluginService.Normalize(this.Service);
            newItem.UserId                  = this.UserId;
            newItem.UserName                = this.UserName;
            newItem.GrantTicket             = this.GrantTicket;
            newItem.LongTicket              = this.LongTicket;
            newItem.ProxyTicket             = this.ProxyTicket;
            newItem.CreateDate              = this.CreateDate;
            newItem.Expires                 = this.Expires;
            newItem.CreateByCredentials     = this.CreateByCredentials;
            newItem.ChangePasswordNextLogon = this.ChangePasswordNextLogon;
            newItem.ErrorText               = this.ErrorText;
            newItem.Attributes              = this.Attributes;

            return(newItem);
        }
Example #9
0
 public override CASChangePasswordResult ChangePassword(CASTicketResult ticket, String password)
 {
     return(new CASChangePasswordResult("Not implemented"));
 }
Example #10
0
        protected override CASTicketResult iGrant(CASTicketResult oldToken, String username, String password)
        {
            CASTicketResult ret = new CASTicketResult();

            return(ret);
        }
Example #11
0
 //Método para troca de senha
 public abstract CASChangePasswordResult ChangePassword(CASTicketResult ticket, String password);
Example #12
0
 //Valida através do plugin, ou seja consulta usuário e senha
 protected abstract CASTicketResult iGrant(CASTicketResult oldTicket, String username, String password);
Example #13
0
 public void SaveTicket(CASTicketResult ticket)
 {
     //ticket.SaveToFile(Path.Combine(BasePath.FullName, "tickets"));
     ticket.SaveToDb(this.Database);
 }
Example #14
0
 public void SaveTicket(CASTicketResult ticket)
 {
     ticket.SaveToFile(Path.Combine(BasePath.FullName, "tickets"));
 }