Exemplo n.º 1
0
        public ProvisionInfo InitializeUserInfo(string user)
        {
            ProvisionInfo info = null;

            Simias.Server.EnterpriseDomain enterpriseDomain =
                new Simias.Server.EnterpriseDomain(false);
            if (enterpriseDomain == null)
            {
                throw new SimiasException("Enterprise server domain does not exist.");
            }

            Store store = Store.GetStore();

            Simias.Storage.Domain domain = store.GetDomain(enterpriseDomain.ID);
            if (domain == null)
            {
                throw new SimiasException("Enterprise server domain does not exist.");
            }

            // find user
            Member member = domain.GetMemberByName(user);

            if (member != null)
            {
                info        = new ProvisionInfo();
                info.UserID = member.UserID;

                // post-office box
                //POBox.POBox poBox = POBox.POBox.GetPOBox( store, domain.ID, info.UserID );

                //info.POBoxID = poBox.ID;
                //info.POBoxName = poBox.Name;

                //Member poMember = poBox.GetMemberByID( member.UserID );
                //info.MemberNodeName = poMember.Name;
                //info.MemberNodeID = poMember.ID;
                //info.MemberRights = poMember.Rights.ToString();
                info.MemberNodeName = member.Name;
                info.MemberNodeID   = member.ID;

                // Clients before this build do not understand "Secondary" rights so change that to ReadWrite. Also, Secondary rights
                // are relevant only for server and not for clients, so makes sense.
                Access.Rights rights   = (Access.Rights)member.Rights;                 // ( Access.Rights )Enum.Parse( typeof( Access.Rights ), member.Rights );
                Access.Rights NewRight = rights;
                if (rights == Access.Rights.Secondary)
                {
                    NewRight = Access.Rights.ReadWrite;
                }
                info.MemberRights = NewRight.ToString();
            }
            else
            {
                throw new SimiasException("User: "******" does not exist");
            }

            return(info);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the distinguished name from the member name.
        /// </summary>
        /// <param name="user">The user name.</param>
        /// <param name="distinguishedName">Receives the ldap distinguished name.</param>
        /// <param name="id">Receives the member's user ID.</param>
        /// <returns>True if the distinguished name was found.</returns>
        private bool GetUserDN(string user, out string distinguishedName, out string id)
        {
            bool   status = false;
            Member member = null;

            // Initialize the outputs.
            distinguishedName = String.Empty;
            id = String.Empty;

            if (domain != null)
            {
                member = domain.GetMemberByName(user);
                if (member != null)
                {
                    Property dn = member.Properties.GetSingleProperty("DN");
                    if (dn != null)
                    {
                        distinguishedName = dn.ToString();
                        id     = member.UserID;
                        status = true;
                    }
                }
                else
                {
                    // The specified user did not exist in the roster under
                    // the short or common name.
                    // Let's see if the user came in fully distinguished.
                    // ex. cn=user.o=context

                    string dn = user.ToLower();
                    if (dn.StartsWith("cn=") == true)
                    {
                        // NDAP name to LDAP name
                        dn = dn.Replace('.', ',');
                        ICSList dnList = domain.Search("DN", dn, SearchOp.Equal);
                        if (dnList != null && dnList.Count == 1)
                        {
                            IEnumerator dnEnum = dnList.GetEnumerator();
                            if (dnEnum.MoveNext() == true)
                            {
                                member = new Member(domain, dnEnum.Current as ShallowNode);
                                if (member != null)
                                {
                                    distinguishedName = dn;
                                    id     = member.UserID;
                                    status = true;
                                }
                            }
                        }
                    }
                }
            }

            return(status);
        }
Exemplo n.º 3
0
        /// <summary>
        /// commit the encrypted password as part of member object
        /// </summary>
        /// <returns>true if setting is successful</returns>
        private bool SetAdminPassword()
        {
            bool status = false;

            // Bootstrap the domain from the Simias.config file
            Simias.Configuration config = Store.Config;
            string adminName            = config.Get("EnterpriseDomain", "AdminName");
            string adminPassword        = config.Get("EnterpriseDomain", "AdminPassword");

            if (adminName != null && adminName != "" && adminPassword != null)
            {
                try
                {
                    Member member = domain.GetMemberByName(adminName);
                    if (member != null)
                    {
                        Property pwd =
                            member.Properties.GetSingleProperty(InternalUser.pwdProperty);
                        if (pwd == null || pwd.Value == null)
                        {
                            pwd = new Property(InternalUser.pwdProperty, HashPassword(adminPassword));
                            member.Properties.ModifyProperty(pwd);

                            // Marker so we know this member was created internally
                            // and not through an external identity sync.
                            domain.SetType(member as Node, InternalUser.memberMarker);
                            domain.Commit(member);
                            status = true;
                        }
                    }
                }
                catch (Exception ap)
                {
                    log.Error(ap.Message);
                    log.Error(ap.StackTrace);
                }
            }

            return(status);
        }
Exemplo n.º 4
0
        public Simias.Host.HostInfo GetHomeServer(string user)

        {
            Simias.Server.EnterpriseDomain enterpriseDomain =
                new Simias.Server.EnterpriseDomain(false);
            if (enterpriseDomain == null)
            {
                throw new SimiasException("Enterprise server domain does not exist.");
            }

            Store store = Store.GetStore();

            Simias.Storage.Domain domain = store.GetDomain(enterpriseDomain.ID);
            if (domain == null)
            {
                throw new SimiasException("Enterprise server domain does not exist.");
            }

            // find user
            Member   member = domain.GetMemberByName(user);
            HostNode hNode  = member.HomeServer;

            if (hNode == null)
            {
                if (HostNode.GetLocalHost().IsMasterHost)
                {
                    return(ProvisionService.ProvisionUser(user));
                }
                else
                {
                    return(null);
                    //need to get the home server from master.
                }
            }

            return(new Simias.Host.HostInfo(hNode));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get the host from name
        /// </summary>
        /// <param name="domainId">Domain ID where host is available</param>
        /// <param name="hostName">Name of the host</param>
        /// <returns>Returns the HostNode</returns>
        public static HostNode GetHostByName(string domainId, string hostName)
        {
            Domain domain = Store.GetStore().GetDomain(domainId);

            return(new HostNode(domain.GetMemberByName(hostName)));
        }
Exemplo n.º 6
0
        Authenticate(Simias.Storage.Domain Domain, HttpContext HttpCtx)
        {
            Simias.Authentication.Status authStatus;

            log.Debug("Authenticate called");

            try
            {
                // Check for an authorization header.
                string[] encodedCredentials = HttpCtx.Request.Headers.GetValues("Authorization");
                if ((encodedCredentials != null) && (encodedCredentials[0] != null))
                {
                    // Get the basic encoding type from the http header.
                    string[] encodingName = HttpCtx.Request.Headers.GetValues("Basic-Encoding");
                    if ((encodingName == null) || (encodingName[0] == null))
                    {
                        // Use the specified default encoding.
                        encodingName = new string[] { defaultBasicEncodingName };
                    }
                    // Get the credentials from the auth header.
                    SimiasCredentials creds = new SimiasCredentials();
                    if (creds.AuthorizationHeaderToCredentials(encodedCredentials[0], encodingName[0]))
                    {
                        // Valid credentials?
                        if ((creds.Username != null) && (creds.Password != null))
                        {
                            // Only support basic.
                            if (creds.AuthType == "basic")
                            {
                                Member member = Domain.GetMemberByName(creds.Username);
                                if (member == null)
                                {
                                    member = Domain.GetMemberByDN(creds.Username);
                                }
                                if (member == null)
                                {
                                    member = Domain.GetMemberByOldName(creds.Username);
                                    if (member != null)
                                    {
                                        creds.Username = member.Name;                                         // give new username for e-dir auth
                                    }
                                }

                                if (member != null)
                                {
                                    if (Domain.IsLoginDisabled(member.UserID) != true)
                                    {
                                        try
                                        {
                                            // Authenticate the user.
                                            authStatus = AuthenticateByName(Domain.ID, creds.Username, creds.Password);
                                            HostNode hNode = HostNode.GetLocalHost();
                                            if (hNode.IsMasterHost != true)
                                            {
                                                for (int i = 0; i < 10; i++)
                                                {
                                                    log.Debug("System Sync Status : " + Domain.SystemSyncStatus.ToString());
                                                    if ((Domain.SystemSyncStatus &
                                                         (ulong)CollectionSyncClient.StateMap.CatalogSyncOnce) ==
                                                        (ulong)CollectionSyncClient.StateMap.CatalogSyncOnce ||
                                                        (CollectionSyncClient.ServerSyncStatus &
                                                         CollectionSyncClient.StateMap.CatalogSyncOnce) ==
                                                        CollectionSyncClient.StateMap.CatalogSyncOnce)
                                                    {
                                                        break;
                                                    }
                                                    else
                                                    {
                                                        syncEvent.WaitOne(5000, false);
                                                    }

                                                    if (i == 9)
                                                    {
                                                        authStatus = new Simias.Authentication.Status(SCodes.InvalidCredentials);
                                                    }
                                                }
                                            }

                                            HostNode mNode = member.HomeServer;
                                            log.Debug("id.Auth : localhost userid  is :" + hNode.UserID);
                                            Http.UserMoved = 0;
                                            if (mNode != null)
                                            {
                                                log.Debug("id.Auth : member's home server userid is :" + mNode.UserID);
                                                if (hNode.UserID != mNode.UserID)
                                                {
                                                    log.Debug("id.Aith : sending useralreadymoved status back to client");
                                                    Http.UserMoved = 1;
                                                }
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            log.Error(e.Message);
                                            log.Error(e.StackTrace);
                                            authStatus = new Simias.Authentication.Status(SCodes.InternalException);
                                            authStatus.ExceptionMessage = e.Message;
                                        }
                                    }
                                    else
                                    {
                                        log.Debug("Login is disabled for user " + creds.Username);
                                        authStatus = new Simias.Authentication.Status(SCodes.SimiasLoginDisabled);
                                    }
                                }
                                else
                                {
                                    log.Debug(creds.Username + " is not member of simias");
                                    authStatus = new Simias.Authentication.Status(SCodes.InvalidCredentials);
                                }
                            }
                            else
                            {
                                authStatus = new Simias.Authentication.Status(SCodes.MethodNotSupported);
                            }
                        }
                        else
                        {
                            authStatus = new Simias.Authentication.Status(SCodes.InvalidCredentials);
                        }
                    }
                    else
                    {
                        authStatus = new Simias.Authentication.Status(SCodes.InvalidCredentials);
                    }
                }
                else
                {
                    authStatus = new Simias.Authentication.Status(SCodes.InvalidCredentials);
                }
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                log.Error(e.StackTrace);
                authStatus = new Simias.Authentication.Status(SCodes.InternalException);
                authStatus.ExceptionMessage = e.Message;
            }
            return(authStatus);
        }