The UserIdentityToken class.
コード例 #1
0
ファイル: UserIdentity.cs プロジェクト: benvert/pfe
        /// <summary>
        /// Initializes the object with a UA identity token
        /// </summary>
        private void Initialize(UserIdentityToken token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            m_policyId = token.PolicyId;

            UserNameIdentityToken usernameToken = token as UserNameIdentityToken;

            if (usernameToken != null)
            {
                Initialize(new UserNameSecurityToken(usernameToken.UserName, usernameToken.DecryptedPassword));
                return;
            }

            X509IdentityToken x509Token = token as X509IdentityToken;

            if (x509Token != null)
            {
                X509Certificate2 certificate = CertificateFactory.Create(x509Token.CertificateData, true);
                Initialize(new X509SecurityToken(certificate));
                return;
            }

            IssuedIdentityToken wssToken = token as IssuedIdentityToken;

            if (wssToken != null)
            {
                Initialize(wssToken, WSSecurityTokenSerializer.DefaultInstance, null);
                return;
            }

            AnonymousIdentityToken anonymousToken = token as AnonymousIdentityToken;

            if (anonymousToken != null)
            {
                m_tokenType       = UserTokenType.Anonymous;
                m_issuedTokenType = null;
                m_displayName     = "Anonymous";
                m_token           = null;
                return;
            }

            throw new ArgumentException("Unrecognized UA user identity token type.", "token");
        }
コード例 #2
0
        /// <summary>
        /// Initializes the object with a UA identity token
        /// </summary>
        private void Initialize(UserIdentityToken token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            m_policyId = token.PolicyId;

            AnonymousIdentityToken anonymousToken = token as AnonymousIdentityToken;

            if (anonymousToken != null)
            {
                m_tokenType       = UserTokenType.Anonymous;
                m_issuedTokenType = null;
                m_displayName     = "Anonymous";
                return;
            }

            throw new ArgumentException("Unrecognized UA user identity token type.", "token");
        }
コード例 #3
0
 /// <summary>
 /// Initializes the object with a UA identity token.
 /// </summary>
 /// <param name="token">The user identity token.</param>
 public UserIdentity(UserIdentityToken token)
 {
     Initialize(token);
 }
コード例 #4
0
        /// <summary>
        /// Initializes the object with a UA identity token
        /// </summary>
        private void Initialize(UserIdentityToken token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            m_token = token;

            UserNameIdentityToken usernameToken = token as UserNameIdentityToken;

            if (usernameToken != null)
            {
                m_tokenType       = UserTokenType.UserName;
                m_issuedTokenType = null;
                m_displayName     = usernameToken.UserName;
                return;
            }

            X509IdentityToken x509Token = token as X509IdentityToken;

            if (x509Token != null)
            {
                m_tokenType       = UserTokenType.Certificate;
                m_issuedTokenType = null;
                if (x509Token.Certificate != null)
                {
                    m_displayName = x509Token.Certificate.Subject;
                }
                else
                {
                    X509Certificate2 cert = CertificateFactory.Create(x509Token.CertificateData, true);
                    m_displayName = cert.Subject;
                }
                return;
            }

            IssuedIdentityToken issuedToken = token as IssuedIdentityToken;

            if (issuedToken != null)
            {
                if (issuedToken.IssuedTokenType == Ua.IssuedTokenType.JWT)
                {
                    if (issuedToken.DecryptedTokenData == null || issuedToken.DecryptedTokenData.Length == 0)
                    {
                        throw new ArgumentException("JSON Web Token has no data associated with it.", "token");
                    }

                    m_tokenType       = UserTokenType.IssuedToken;
                    m_issuedTokenType = new XmlQualifiedName("", Opc.Ua.Profiles.JwtUserToken);
                    m_displayName     = "JWT";
                    return;
                }
                else
                {
                    throw new NotSupportedException("Only JWT Issued Tokens are supported!");
                }
            }

            AnonymousIdentityToken anonymousToken = token as AnonymousIdentityToken;

            if (anonymousToken != null)
            {
                m_tokenType       = UserTokenType.Anonymous;
                m_issuedTokenType = null;
                m_displayName     = "Anonymous";
                return;
            }

            throw new ArgumentException("Unrecognized UA user identity token type.", "token");
        }
コード例 #5
0
 /// <summary>
 /// Initializes the object with a UA identity token.
 /// </summary>
 /// <param name="token">The user identity token.</param>
 public UserIdentity(UserIdentityToken token)
 {
     Initialize(token);
 }
コード例 #6
0
        /// <summary>
        /// Initializes the object with a UA identity token
        /// </summary>
        private void Initialize(UserIdentityToken token)
        {
            if (token == null) throw new ArgumentNullException("token");

            m_policyId = token.PolicyId;
  
            AnonymousIdentityToken anonymousToken = token as AnonymousIdentityToken;
            if (anonymousToken != null)
            {
                m_tokenType = UserTokenType.Anonymous;
                m_issuedTokenType = null;
                m_displayName = "Anonymous";
                return;
            }        
  
            throw new ArgumentException("Unrecognized UA user identity token type.", "token");
        }
コード例 #7
0
ファイル: UserIdentity.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Initializes the object with a UA identity token
        /// </summary>
        private void Initialize(UserIdentityToken token)
        {
            if (token == null) throw new ArgumentNullException("token");

            m_policyId = token.PolicyId;
  
            UserNameIdentityToken usernameToken = token as UserNameIdentityToken;

            if (usernameToken != null)
            {
                Initialize(new UserNameSecurityToken(usernameToken.UserName, usernameToken.DecryptedPassword));
                return;
            }        
  
            X509IdentityToken x509Token = token as X509IdentityToken;

            if (x509Token != null)
            {
                X509Certificate2 certificate = CertificateFactory.Create(x509Token.CertificateData, true);  
                Initialize(new X509SecurityToken(certificate));
                return;
            }
   
            IssuedIdentityToken wssToken = token as IssuedIdentityToken;
            
            if (wssToken != null)
            {
                Initialize(wssToken, WSSecurityTokenSerializer.DefaultInstance, null);                
                return;
            }
            
            AnonymousIdentityToken anonymousToken = token as AnonymousIdentityToken;

            if (anonymousToken != null)
            {
                m_tokenType = UserTokenType.Anonymous;
                m_issuedTokenType = null;
                m_displayName = "Anonymous";
                m_token = null;
                return;
            }        
  
            throw new ArgumentException("Unrecognized UA user identity token type.", "token");
        }
コード例 #8
0
        /// <summary>
        /// Initializes the object with a UA identity token
        /// </summary>
        private void Initialize(UserIdentityToken token)
        {
            if (token == null) throw new ArgumentNullException("token");

            m_token = token;
  
            UserNameIdentityToken usernameToken = token as UserNameIdentityToken;
            if (usernameToken != null)
            {
                m_tokenType = UserTokenType.UserName;
                m_issuedTokenType = null;
                m_displayName = usernameToken.UserName;
                return;
            }

            X509IdentityToken x509Token = token as X509IdentityToken;
            if (x509Token != null)
            {
                m_tokenType = UserTokenType.Certificate;
                m_issuedTokenType = null;
                if (x509Token.Certificate != null)
                {
                    m_displayName = x509Token.Certificate.Subject;
                }
                else
                {
                    X509Certificate2 cert = CertificateFactory.Create(x509Token.CertificateData, true);
                    m_displayName = cert.Subject;
                }
                return;
            }

            IssuedIdentityToken issuedToken = token as IssuedIdentityToken;
            if (issuedToken != null)
            {
                if (issuedToken.IssuedTokenType == Ua.IssuedTokenType.JWT)
                {
                    if (issuedToken.DecryptedTokenData == null || issuedToken.DecryptedTokenData.Length == 0)
                    {
                        throw new ArgumentException("JSON Web Token has no data associated with it.", "token");
                    }

                    m_tokenType = UserTokenType.IssuedToken;
                    m_issuedTokenType = new XmlQualifiedName("", "http://opcfoundation.org/UA/UserTokenPolicy#JWT");
                    m_displayName = "JWT";
                    return;
                }
                else
                {
                    throw new NotSupportedException("Only JWT Issued Tokens are supported!");
                }
            }

            AnonymousIdentityToken anonymousToken = token as AnonymousIdentityToken;
            if (anonymousToken != null)
            {
                m_tokenType = UserTokenType.Anonymous;
                m_issuedTokenType = null;
                m_displayName = "Anonymous";
                return;
            }        
  
            throw new ArgumentException("Unrecognized UA user identity token type.", "token");
        }