当前位置: 首页>>代码示例>>C#>>正文


C# Session.startChannel方法代码示例

本文整理汇总了C#中Session.startChannel方法的典型用法代码示例。如果您正苦于以下问题:C# Session.startChannel方法的具体用法?C# Session.startChannel怎么用?C# Session.startChannel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Session的用法示例。


在下文中一共展示了Session.startChannel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AuthenticateSASLOTPWithInit

        /*
        * Method AuthenticateSASLOTPWithInit is like the others, except
        * that is actually forces the server (if authentication succeeds)
        * to update the OTP db for this user.
        *
        * If you want to do that (I recommend it, then use the NEXT one).
        *
        * @param Session session is the session the user is authenticating on,
        * in other words, represents the peer we want to authenticate to.
        * @param String authorizeId is the identity this peer wants to be
        *               authorized to act as.
        * @param String authenticateId is the identity this peer will
        *               authenticate as
        * @param String pwd is the passphrase to authenticate with (it isn't
        * stored or kept around very long at all, it's only used in computation).
        *
        * @param String newSequence String representation of the new Sequence
        *               integer
        * @param String newAlgorithm name of the algorithm in the new OTP DB
        * @param String newSeed value of the seed in the new OTP DB
        * @param String newHas value of the lastHash in the new OTP DB
        *
        *
        * @throws SASLException if any issue is encountered (usually
        * rejection by the other peer).
        */
        public static Session AuthenticateSASLOTPWithInit(Session session, System.String authorizeId, System.String authenticateId, System.String pwd, System.String newAlgorithm, System.String newHash, System.String newSeed, System.String newSequence)
        {
            bool success = false;

            // Test the values
            convertHexToBytes(newHash);
            newSeed = newSeed.ToLower();

            if (!OTPGenerator.validateSeed(newSeed) || !OTPGenerator.validatePassphrase(pwd) || !OTPGenerator.validateSequence(newSequence))
                throw new SASLException("Unsuitable values for the parameters to init-hex");

            // @todo bad toad - clean this up with tuning move
            clearCredential(session, null);

            OTPAuthenticator auth = SASLOTPProfile.instance().startAuthentication(authorizeId, authenticateId, pwd, newAlgorithm, newHash, newSeed, newSequence);
            Channel ch = null;
            System.String startData = null;
            try
            {
                ch = session.startChannel(SASLOTPProfile.URI, auth);
                startData = ch.StartData;
            }
            catch (BEEPException x)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
                auth.abort(x.Message);
            }

            // @todo EITHER use the Session Event Mechanism once it's detached from
            // the session I/O thread via the Channel Message (EVENT) Queues...
            // OR
            // Embed some tuning profile logic in ChannelZero (hacky) to address stuff.
            // For now, this is ok, the only thread blocked is the users, and it waits
            // until the Authentication succeeds or fails.
            Blob blob = null;

            if ((System.Object) startData != null)
            {
                blob = new Blob(startData);
                if (blob.Status.Equals(SASL_STATUS_ABORT))
                    throw new SASLException(ERR_REJECTED);
            }

            auth.started(ch);
            auth.sendIdentity(authorizeId, authenticateId);

            // We'll get notified when either
            // (a) An Error Occurs
            // (b) The authentication succeeds
            // Everything else from here on out is basically on autopilot
            try
            {
                lock (auth)
                {
                    System.Threading.Monitor.Wait(auth);

                    SessionCredential cred = session.getLocalCredential();

                    if (cred == null)
                    {
                        auth.abort("Authentication Failed");
                    }
                    else
                    {
                        success = true;
                    }
                }
            }
            catch (System.Exception x)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
                auth.abort(x.Message);
            }

//.........这里部分代码省略.........
开发者ID:BDizzle,项目名称:BeepForNet,代码行数:101,代码来源:SASLOTPProfile.cs

示例2: AuthenticateSASLAnonymousPiggyback

        /// <summary> Method authencitateSASLAnonymousPiggyback is an Initiator
        /// routine designed to allow a peer to authenticate to another
        /// one.  It is distinct in that it piggybacks the data for the
        /// authentication request on the startChannel request.
        /// 
        /// </summary>
        /// <param name="session">Session the current session
        /// </param>
        /// <param name="id">The identity of the peer withing to authenticate
        /// 
        /// @throws SASLException if any failure occurs.
        /// </param>
        public static Session AuthenticateSASLAnonymousPiggyback(Session session, System.String id)
        {
            if ((System.Object) id == null)
            {
                id = ANONYMOUS;
            }

            clearCredential(session, null);

            //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
            Channel ch = session.startChannel(SASLAnonymousProfile.uri, false, new Blob(Blob.STATUS_NONE, id).ToString());

            if (((System.Object) ch.StartData != null) && (ch.StartData.IndexOf("<error ") != - 1))
            {
                throw new BEEPException(ch.StartData);
            }

            System.String goo = ch.StartData;

            if ((System.Object) goo != null)
            {
                Blob blob = new Blob(goo);
                if (blob.Status.Equals(Blob.COMPLETE))
                {
                    Instance.finishInitiatorAuthentication(generateCredential(id), ch.Session);
                    return session;
                }
            }
            // @todo allow non-piggybacked
            throw new BEEPException("Auth failed.");
        }
开发者ID:BDizzle,项目名称:BeepForNet,代码行数:43,代码来源:SASLAnonymousProfile.cs

示例3: AuthenticateSASLOTP

        /// <summary> Method AuthenticateSASLOTP starts SASL OTP Authentication
        /// between two peers. This is the NON-Piggybacking version 
        /// (it doesn't send the initial identity information on the 
        /// startChannelRequest).
        /// 
        /// If you want to do that (I recommend it, then use the NEXT one).
        /// 
        /// </summary>
        /// <param name="session">Session is the session the user is authenticating on,
        /// in other words, represents the peer we want to
        /// authenticate to.
        /// </param>
        /// <param name="authorizeId">The identity this peer wants to be
        /// authorized to act as.
        /// </param>
        /// <param name="authenticateId">The identity this peer will
        /// authenticate as
        /// </param>
        /// <param name="pwd">The passphrase to authenticate with (it isn't stored or
        /// kept around very long at all, it's only used in computation).
        /// @throws SASLException if any issue is encountered (usually
        /// rejection by the other peer).
        /// </param>
        public static Session AuthenticateSASLOTP(Session session, System.String authorizeId, System.String authenticateId, System.String pwd)
        {
            bool success = false;

            if ((System.Object) authenticateId == null || session == null || (System.Object) pwd == null)
            {

                throw new InvalidParameterException(ERR_INVALID_ID + authenticateId);
            }

            // @todo bad toad - clean this up with tuning move
            clearCredential(session, null);

            OTPAuthenticator auth = SASLOTPProfile.instance().startAuthentication(authorizeId, authenticateId, pwd);
            Channel ch = null;
            System.String startData = null;
            try
            {
                ch = session.startChannel(SASLOTPProfile.URI, auth);
                startData = ch.StartData;
            }
            catch (BEEPException x)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
                auth.abort(x.Message);
            }

            // @todo EITHER use the Session Event Mechanism once it's
            // detached from the session I/O thread via the Channel
            // Message (EVENT) Queues...
            // OR
            // Embed some tuning profile logic in ChannelZero (hacky) to
            // address stuff.  For now, this is ok, the only thread
            // blocked is the users, and it waits until the Authentication
            // succeeds or fails.
            Blob blob = null;

            if ((System.Object) startData != null)
            {
                blob = new Blob(startData);
                if (blob.Status.Equals(SASL_STATUS_ABORT))
                    throw new SASLException(ERR_REJECTED);
            }

            auth.started(ch);
            auth.sendIdentity(authorizeId, authenticateId);

            // We'll get notified when either
            // (a) An Error Occurs
            // (b) The authentication succeeds
            // Everything else from here on out is basically on autopilot
            try
            {
                lock (auth)
                {
                    System.Threading.Monitor.Wait(auth);
                }
            }
            catch (System.Exception x)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
                auth.abort(x.Message);
            }

            SessionCredential cred = session.getLocalCredential();

            if (cred == null)
            {
                auth.abort("Authentication Failed");
            }
            else
            {
                success = true;
            }

            return session;
        }
开发者ID:BDizzle,项目名称:BeepForNet,代码行数:100,代码来源:SASLOTPProfile.cs

示例4: AuthenticateSASLAnonymous

        /// <summary> Method authencitateSASLAnonymous is an Initiator routine designed
        /// to allow a peer to authenticate to another one. 
        /// 
        /// </summary>
        /// <param name="session">Session the current session
        /// </param>
        /// <param name="id">The identity of the peer withing to authenticate
        /// 
        /// @throws SASLException if any failure occurs.
        /// </param>
        public static Session AuthenticateSASLAnonymous(Session session, System.String id)
        {
            if ((System.Object) id == null)
            {
                id = ANONYMOUS;
            }

            clearCredential(session, null);

            AnonymousAuthenticator auth = new AnonymousAuthenticator(Instance);
            Channel ch = session.startChannel(SASLAnonymousProfile.uri, auth);
            auth.started(ch);
            auth.sendIdentity(id);
            lock (auth)
            {
                try
                {
                    System.Threading.Monitor.Wait(auth);

                    //FIX for bug 469725, if authentication fails no local Cred is
                    //set and a AuthenticationFailureException is thrown
                    if (ch.Session.getLocalCredential() == null)
                    {
                        throw new AuthenticationFailureException("Could not authenticate with SASL/ANON");
                    }

                    return ch.Session;
                }
                catch (System.Threading.ThreadInterruptedException x)
                {
                }
            }
            return null;
        }
开发者ID:BDizzle,项目名称:BeepForNet,代码行数:44,代码来源:SASLAnonymousProfile.cs


注:本文中的Session.startChannel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。