Apache.Shiro.Authc.SimpleAuthenticationInfo.Merge C# (CSharp) Method

Merge() public method

public Merge ( IAuthenticationInfo other ) : void
other IAuthenticationInfo
return void
        public void Merge(IAuthenticationInfo other)
        {
            if (other == null || other.Principals == null || other.Principals.Count == 0)
            {
                return;
            }

            if (Principals == null)
            {
                Principals = other.Principals;
            }
            else
            {
                if (!(Principals is IMutablePrincipalCollection))
                {
                    Principals = new SimplePrincipalCollection(Principals);
                }
                ((IMutablePrincipalCollection) Principals).AddAll(other.Principals);
            }

            if (other.Credentials == null)
            {
                return;
            }
            if (Credentials == null)
            {
                Credentials = other.Credentials;

                return;
            }

            ISet<object> credentials;
            if (Credentials is ISet<object>)
            {
                credentials = (ISet<object>) Credentials;
            }
            else
            {
                Credentials = credentials = new HashSet<object>();
            }

            if (other.Credentials is IEnumerable)
            {
                var enumerable = (IEnumerable) other.Credentials;

                credentials.UnionWith(enumerable.Cast<object>());
            }
            else
            {
                credentials.Add(other.Credentials);
            }
        }

Usage Example

Example #1
0
        public void Merge(IAuthenticationInfo other)
        {
            _authcInfo.Merge(other);

            if (other is SimpleAccount)
            {
                var account = (SimpleAccount)other;
                if (account.CredentialsExpired)
                {
                    CredentialsExpired = account.CredentialsExpired;
                }
                if (account.Locked)
                {
                    Locked = true;
                }
            }
        }