コード例 #1
0
ファイル: AMFSerializer.cs プロジェクト: Elophant/Client
 private void WriteHeader(AMFHeader header, ObjectEncoding objectEncoding)
 {
     base.Reset();
     base.WriteUTF(header.Name);
     base.WriteBoolean(header.MustUnderstand);
     base.WriteInt32(-1);
     base.WriteData(objectEncoding, header.Content);
 }
コード例 #2
0
 /// <summary>
 /// Removes the named header from teh AMF packet.
 /// </summary>
 /// <param name="header">The name of the header.</param>
 public void RemoveHeader(string header)
 {
     for (int i = 0; _headers != null && i < _headers.Count; i++)
     {
         AMFHeader amfHeader = _headers[i] as AMFHeader;
         if (amfHeader.Name == header)
         {
             _headers.RemoveAt(i);
         }
     }
 }
コード例 #3
0
ファイル: AMFMessage.cs プロジェクト: Joy011024/PickUpData
 public void RemoveHeader(string header)
 {
     for (int i = 0; (this._headers != null) && (i < this._headers.Count); i++)
     {
         AMFHeader header2 = this._headers[i];
         if (header2.Name == header)
         {
             this._headers.RemoveAt(i);
         }
     }
 }
コード例 #4
0
 /// <summary>
 /// Gets the value of a single AMF header object by name.
 /// </summary>
 /// <param name="header">The name of the header.</param>
 /// <returns>The header referenced by name.</returns>
 public AMFHeader GetHeader(string header)
 {
     for (int i = 0; _headers != null && i < _headers.Count; i++)
     {
         AMFHeader amfHeader = _headers[i] as AMFHeader;
         if (amfHeader.Name == header)
         {
             return(amfHeader);
         }
     }
     return(null);
 }
コード例 #5
0
ファイル: AMFMessage.cs プロジェクト: Joy011024/PickUpData
 public AMFHeader GetHeader(string header)
 {
     for (int i = 0; (this._headers != null) && (i < this._headers.Count); i++)
     {
         AMFHeader header2 = this._headers[i];
         if (header2.Name == header)
         {
             return(header2);
         }
     }
     return(null);
 }
コード例 #6
0
 /// <summary>
 /// Adds a header to the AMF packet.
 /// </summary>
 /// <param name="header">The header object to add.</param>
 public void AddHeader(AMFHeader header)
 {
     this._headers.Add(header);
 }
コード例 #7
0
ファイル: ContextFilter.cs プロジェクト: apakian/fluorinefx
        public override void Invoke(AMFContext context)
        {
			MessageOutput messageOutput = context.MessageOutput;
            for (int i = 0; i < context.AMFMessage.BodyCount; i++)
            {
                AMFBody amfBody = context.AMFMessage.GetBodyAt(i);
                //Check for Flex2 messages
                if (amfBody.IsEmptyTarget)
                {
                    object content = amfBody.Content;
                    if (content is IList)
                        content = (content as IList)[0];
                    IMessage message = content as IMessage;
                    if (message != null)
                    {
                        Client client = null;
                        HttpSession session = null;
                        if (FluorineContext.Current.Client == null)
                        {
                            IClientRegistry clientRegistry = _endpoint.GetMessageBroker().ClientRegistry;
                            string clientId = message.GetFlexClientId();
                            if (!clientRegistry.HasClient(clientId))
                            {
                                lock (clientRegistry.SyncRoot)
                                {
                                    if (!clientRegistry.HasClient(clientId))
                                    {
                                        client = _endpoint.GetMessageBroker().ClientRegistry.GetClient(clientId) as Client;
                                    }
                                }
                            }
                            if (client == null)
                                client = _endpoint.GetMessageBroker().ClientRegistry.GetClient(clientId) as Client;
                            FluorineContext.Current.SetClient(client);
                        }
                        session = _endpoint.GetMessageBroker().SessionManager.GetHttpSession(HttpContext.Current);
                        FluorineContext.Current.SetSession(session);
                        //Context initialized, notify listeners.
                        if (session != null && session.IsNew)
                            session.NotifyCreated();
                        if (client != null)
                        {
                            if (session != null)
                                client.RegisterSession(session);
                            if (client.IsNew)
                            {
                                client.Renew(_endpoint.ClientLeaseTime);
                                client.NotifyCreated();
                            }
                        }
                        /*
                        RemotingConnection remotingConnection = null;
                        foreach (IConnection connection in client.Connections)
                        {
                            if (connection is RemotingConnection)
                            {
                                remotingConnection = connection as RemotingConnection;
                                break;
                            }
                        }
                        if (remotingConnection == null)
                        {
                            remotingConnection = new RemotingConnection(_endpoint, null, client.Id, null);
                            remotingConnection.Initialize(client, session);
                        }
                        FluorineContext.Current.SetConnection(remotingConnection);
                        */
                    }
                }
                else
                {
                    //Flash remoting
                    AMFHeader amfHeader = context.AMFMessage.GetHeader(AMFHeader.AMFDSIdHeader);
                    string amfDSId = null;
                    if (amfHeader == null )
                    {
                        amfDSId = Guid.NewGuid().ToString("D");
                        ASObject asoObjectDSId = new ASObject();
                        asoObjectDSId["name"] = AMFHeader.AMFDSIdHeader;
                        asoObjectDSId["mustUnderstand"] = false;
                        asoObjectDSId["data"] = amfDSId;//set
                        AMFHeader headerDSId = new AMFHeader(AMFHeader.RequestPersistentHeader, true, asoObjectDSId);
                        context.MessageOutput.AddHeader(headerDSId);
                    }
                    else
                        amfDSId = amfHeader.Content as string;

                    Client client = null;
                    HttpSession session = null;
                    if (FluorineContext.Current.Client == null)
                    {
                        IClientRegistry clientRegistry = _endpoint.GetMessageBroker().ClientRegistry;
                        string clientId = amfDSId;
                        if (!clientRegistry.HasClient(clientId))
                        {
                            lock (clientRegistry.SyncRoot)
                            {
                                if (!clientRegistry.HasClient(clientId))
                                {
                                    client = _endpoint.GetMessageBroker().ClientRegistry.GetClient(clientId) as Client;
                                }
                            }
                        }
                        if (client == null)
                            client = _endpoint.GetMessageBroker().ClientRegistry.GetClient(clientId) as Client;
                    }
                    FluorineContext.Current.SetClient(client);
                    session = _endpoint.GetMessageBroker().SessionManager.GetHttpSession(HttpContext.Current);
                    FluorineContext.Current.SetSession(session);
                    //Context initialized, notify listeners.
                    if (session != null && session.IsNew)
                        session.NotifyCreated();
                    if (client != null)
                    {
                        if (session != null)
                            client.RegisterSession(session);
                        if (client.IsNew)
                        {
                            client.Renew(_endpoint.ClientLeaseTime);
                            client.NotifyCreated();
                        }
                    }
                }
            }
        }
コード例 #8
0
		private void WriteHeader(AMFHeader header, ObjectEncoding objectEncoding)
		{
			base.Reset();
			base.WriteUTF(header.Name);
			base.WriteBoolean(header.MustUnderstand);
			base.WriteInt32(-1);
			base.WriteData(objectEncoding, header.Content);
		}
コード例 #9
0
ファイル: LoginManager.cs プロジェクト: apakian/fluorinefx
        public bool Logout()
        {
            bool result = false;
            if (_loginCommand != null)
            {
                result = _loginCommand.Logout(this.Principal);
                if (this.IsPerClientAuthentication)
                {
                    if (FluorineContext.Current.Client != null)
                        FluorineContext.Current.Client.Principal = null;
                }
                else
                {
                    if (FluorineContext.Current.Session != null)
                        FluorineContext.Current.Session.Invalidate();
                }
            }
            else
            {
                if (FluorineContext.Current.Session != null)
                    FluorineContext.Current.Session.Invalidate();

                if (log.IsErrorEnabled)
                    log.Error(__Res.GetString(__Res.Security_LoginMissing));
                //FluorineFx.Messaging.SecurityException se = new FluorineFx.Messaging.SecurityException(NoLoginCommand, FluorineFx.Messaging.SecurityException.ServerAuthorizationCode);
                //throw se;
                throw new UnauthorizedAccessException(__Res.GetString(__Res.Security_LoginMissing));
            }
            if (HttpContext.Current != null)
            {
                /*
                HttpCookie authCookie = HttpContext.Current.Request.Cookies.Get(FormsAuthCookieName);
                if (authCookie != null)
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
                    if (ticket != null && ticket.UserData != null && ticket.UserData.StartsWith(FluorineContext.FluorineTicket))
                    {
                        HttpRuntime.Cache.Remove(ticket.UserData);
                    }
                }
                */
                FormsAuthentication.SignOut();

            }
            if (AMFContext.Current != null)
            {
                AMFContext amfContext = AMFContext.Current;
                AMFHeader amfHeader = amfContext.AMFMessage.GetHeader(AMFHeader.CredentialsIdHeader);
                if (amfHeader != null)
                {
                    amfContext.AMFMessage.RemoveHeader(AMFHeader.CredentialsIdHeader);
                    ASObject asoObjectCredentialsId = new ASObject();
                    asoObjectCredentialsId["name"] = AMFHeader.CredentialsIdHeader;
                    asoObjectCredentialsId["mustUnderstand"] = false;
                    asoObjectCredentialsId["data"] = null;//clear
                    AMFHeader headerCredentialsId = new AMFHeader(AMFHeader.RequestPersistentHeader, true, asoObjectCredentialsId);
                    amfContext.MessageOutput.AddHeader(headerCredentialsId);
                }
            } 
            return result;
        }
コード例 #10
0
		public override void Invoke(AMFContext context)
		{
            MessageBroker messageBroker = _endpoint.GetMessageBroker();
            try
            {
                AMFHeader amfHeader = context.AMFMessage.GetHeader(AMFHeader.CredentialsHeader);
                if (amfHeader != null && amfHeader.Content != null)
                {
                    string userId = ((ASObject)amfHeader.Content)["userid"] as string;
                    string password = ((ASObject)amfHeader.Content)["password"] as string;
                    //Clear credentials header, further requests will not send the credentials
                    ASObject asoObject = new ASObject();
                    asoObject["name"] = AMFHeader.CredentialsHeader;
                    asoObject["mustUnderstand"] = false;
                    asoObject["data"] = null;//clear
                    AMFHeader header = new AMFHeader(AMFHeader.RequestPersistentHeader, true, asoObject);
                    context.MessageOutput.AddHeader(header);
                    IPrincipal principal = _endpoint.GetMessageBroker().LoginManager.Login(userId, amfHeader.Content as IDictionary);
                    string key = EncryptCredentials(_endpoint, principal, userId, password);
                    ASObject asoObjectCredentialsId = new ASObject();
                    asoObjectCredentialsId["name"] = AMFHeader.CredentialsIdHeader;
                    asoObjectCredentialsId["mustUnderstand"] = false;
                    asoObjectCredentialsId["data"] = key;//set
                    AMFHeader headerCredentialsId = new AMFHeader(AMFHeader.RequestPersistentHeader, true, asoObjectCredentialsId);
                    context.MessageOutput.AddHeader(headerCredentialsId);
                }
                else
                {
                    amfHeader = context.AMFMessage.GetHeader(AMFHeader.CredentialsIdHeader);
                    if (amfHeader != null)
                    {
                        string key = amfHeader.Content as string;
                        if (key != null)
                            _endpoint.GetMessageBroker().LoginManager.RestorePrincipal(key);
                    }
                    else
                    {
                        _endpoint.GetMessageBroker().LoginManager.RestorePrincipal();
                    }
                }
            }
            catch (UnauthorizedAccessException exception)
            {
                for (int i = 0; i < context.AMFMessage.BodyCount; i++)
                {
                    AMFBody amfBody = context.AMFMessage.GetBodyAt(i);
                    ErrorResponseBody errorResponseBody = new ErrorResponseBody(amfBody, exception);
                    context.MessageOutput.AddBody(errorResponseBody);
                }
            }
            catch (Exception exception)
            {
                if (log != null && log.IsErrorEnabled)
                    log.Error(exception.Message, exception);
                for (int i = 0; i < context.AMFMessage.BodyCount; i++)
                {
                    AMFBody amfBody = context.AMFMessage.GetBodyAt(i);
                    ErrorResponseBody errorResponseBody = new ErrorResponseBody(amfBody, exception);
                    context.MessageOutput.AddBody(errorResponseBody);
                }
            }
		}