Exemplo n.º 1
0
 protected void NotifyLogout(IPrincipalCollection principals)
 {
     if (LoggedOut != null)
     {
         LoggedOut(this, new LogoutEventArgs(principals));
     }
 }
Exemplo n.º 2
0
 public LogoutEventArgs(IPrincipalCollection principals)
 {
     if (principals == null)
     {
         throw new ArgumentNullException("principals");
     }
     _principals = principals;
 }
Exemplo n.º 3
0
 public SubjectBuilder Principals(IPrincipalCollection principals)
 {
     if (principals != null && principals.Count > 0)
     {
         _subjectContext.Principals = principals;
     }
     return(this);
 }
Exemplo n.º 4
0
 public LogoutEventArgs(IPrincipalCollection principals)
 {
     if (principals == null)
     {
         throw new ArgumentNullException("principals");
     }
     _principals = principals;
 }
Exemplo n.º 5
0
        public SimpleAccount(IPrincipalCollection principals, object credentials,
            ISet<string> roles = null, ISet<IPermission> permissions = null)
        {
            _authcInfo = new SimpleAuthenticationInfo(principals, credentials);

            _authzInfo = (roles == null ? new SimpleAuthorizationInfo() : new SimpleAuthorizationInfo(roles));
            _authzInfo.ObjectPermissions = permissions;
        }
Exemplo n.º 6
0
        public SimpleAccount(IPrincipalCollection principals, object credentials,
                             ISet <string> roles = null, ISet <IPermission> permissions = null)
        {
            _authcInfo = new SimpleAuthenticationInfo(principals, credentials);

            _authzInfo = (roles == null ? new SimpleAuthorizationInfo() : new SimpleAuthorizationInfo(roles));
            _authzInfo.ObjectPermissions = permissions;
        }
Exemplo n.º 7
0
        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);
            }
        }
        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);
            }
        }
Exemplo n.º 9
0
 public void AddAll(IPrincipalCollection principals)
 {
     if (principals.RealmNames != null)
     {
         foreach (string realmName in principals.RealmNames)
         {
             foreach (var principals in principals.FromRealm(realmName))
             {
                 AddAll(principals, realmName);
             }
         }
     }
 }
Exemplo n.º 10
0
        public void Logout()
        {
            try
            {
                SecurityManager.Logout(this);
            }
            finally
            {
                Authenticated = false;
                Principals    = null;

                _session = null;
            }
        }
Exemplo n.º 11
0
        public DelegatingSubject(IPrincipalCollection principals, bool authenticated, string host,
            ISession session, ISecurityManager manager)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }

            Authenticated = authenticated;
            Principals = principals;
            Host = host;
            SecurityManager = manager;

            _session = Decorate(session);
        }
Exemplo n.º 12
0
        public DelegatingSubject(IPrincipalCollection principals, bool authenticated, string host,
                                 ISession session, ISecurityManager manager)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }

            Authenticated   = authenticated;
            Principals      = principals;
            Host            = host;
            SecurityManager = manager;

            _session = Decorate(session);
        }
Exemplo n.º 13
0
        public void Login(IAuthenticationToken token)
        {
            var subject = SecurityManager.Login(this, token);

            string host = null;
            IPrincipalCollection principals;

            if (subject is DelegatingSubject)
            {
                DelegatingSubject delegating = (DelegatingSubject)subject;
                host       = delegating.Host;
                principals = delegating.Principals;
            }
            else
            {
                principals = subject.Principals;
            }

            if (principals == null || principals.Count == 0)
            {
                throw new InvalidSubjectException(Properties.Resources.NullOrEmptyPrincipalsAfterLoginMessage);
            }

            Principals    = principals;
            Authenticated = true;
            if (token is IHostAuthenticationToken)
            {
                host = ((IHostAuthenticationToken)token).Host;
            }
            if (host != null)
            {
                Host = host;
            }

            var session = subject.GetSession(false);

            if (session == null)
            {
                _session = null;
            }
            else
            {
                _session = Decorate(session);
            }

            ThreadContext.Subject = this;
        }
Exemplo n.º 14
0
        public void AddAll(IPrincipalCollection principals)
        {
            if (principals == null)
            {
                throw new ArgumentNullException("principals");
            }

            var realmNames = principals.RealmNames;

            if (realmNames == null || realmNames.Count <= 0)
            {
                return;
            }

            foreach (var realmName in realmNames)
            {
                AddAll(principals.FromRealm(realmName), realmName);
            }
        }
Exemplo n.º 15
0
 public void OnLogout(IPrincipalCollection principals)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 public SimpleAuthenticationInfo(IPrincipalCollection principals, object credentials)
 {
     Principals = principals;
     Credentials = credentials;
 }
Exemplo n.º 17
0
 public SimplePrincipalCollection(IPrincipalCollection principals)
 {
     AddAll(principals);
 }
Exemplo n.º 18
0
 public void OnLogout(IPrincipalCollection principals)
 {
     NotifyLogout(principals);
 }
Exemplo n.º 19
0
 public SimpleAuthenticationInfo(IPrincipalCollection principals, object credentials)
 {
     Principals  = principals;
     Credentials = credentials;
 }
Exemplo n.º 20
0
 public SubjectBuilder Principals(IPrincipalCollection principals)
 {
     if (principals != null && principals.Count > 0)
     {
         _subjectContext.Principals = principals;
     }
     return this;
 }
Exemplo n.º 21
0
 public SimpleAuthenticationInfo(object principal, object credentials, string realmName)
 {
     this.principals  = new SimplePrincipalCollection(principal, realmName);
     this.credentials = credentials;
 }