Esempio n. 1
0
        /// <summary>
        /// Start the PO Box manager.
        /// </summary>
        public void Start()
        {
            try
            {
                lock (this)
                {
                    log.Debug("Starting PO Service: {0}", ServiceUrl);

                    // Get a list of all POBoxes.
                    ICSList poBoxList = store.GetCollectionsByType(NodeTypes.POBoxType);
                    foreach (ShallowNode sn in poBoxList)
                    {
                        // Get the domain for this POBox.
                        POBox poBox = new POBox(store, sn);
                        Simias.Storage.Domain domain = store.GetDomain(poBox.Domain);
                        //if (domain.Role == SyncRoles.Slave)
                        //{
                        // start collection managers
                        AddPOBoxManager(poBox.ID);
                        //}
                    }
                }
            }
            catch (Exception e)
            {
                log.Error(e, "Unable to start PO manager.");

                throw e;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes an instance of this object.
        /// </summary>
        public User()
        {
            store = Store.GetStore();
            if (store.DefaultDomain == null)
            {
                throw new SimiasException(User.missingDomainMessage);
            }

            // Is the default domain always the correct domain?
            domain = store.GetDomain(store.DefaultDomain);
            if (domain == null)
            {
                throw new SimiasException(User.missingDomainMessage);
            }

            if (domain.IsType("Enterprise") == false)
            {
                throw new SimiasException(User.missingDomainMessage);
            }

            ldapSettings = LdapSettings.Get(Store.StorePath);


            // Make sure the password is set on the admin
            SetAdminPassword();
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes an instance of this object.
        /// </summary>
        public InternalUser()
        {
            store = Store.GetStore();
            if (store.DefaultDomain == null)
            {
                throw new SimiasException(InternalUser.missingDomainMessage);
            }

            domain = store.GetDomain(store.DefaultDomain);
            if (domain == null)
            {
                throw new SimiasException(InternalUser.missingDomainMessage);
            }

            if (domain.IsType("Enterprise") == false)
            {
                throw new SimiasException(InternalUser.missingDomainMessage);
            }

            utf8Encoding = new UTF8Encoding();
            md5Service   = new MD5CryptoServiceProvider();

            // Make sure the password is set on the admin
            SetAdminPassword();
        }
Esempio n. 4
0
/*
 *              public iFolderUser(Simias.Storage.Member member)
 *              {
 *                      this.Name = member.Name;
 *                      this.UserID = member.UserID;
 *                      this.Rights = member.Rights.ToString();
 *                      this.ID = member.ID;
 *                      this.State = "Member";
 *                      this.IsOwner = member.IsOwner;
 *              }
 */

        /// <summary>
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="member"></param>
        public iFolderUser(Simias.Storage.Domain domain, Simias.Storage.Member member)
        {
            this.Name    = member.Name;
            this.UserID  = member.UserID;
            this.ID      = member.ID;
            this.State   = "Member";
            this.IsOwner = member.IsOwner;
            this.Rights  = member.Rights.ToString();

            if (member.Given != null)
            {
                this.Surname   = member.Family;
                this.FirstName = member.Given;
                this.FN        = member.FN;
            }
            else
            {
                if (domain != null)
                {
                    Simias.Storage.Member dMember = domain.GetMemberByID(member.UserID);
                    if (dMember != null)
                    {
                        this.Surname   = dMember.Family;
                        this.FirstName = dMember.Given;
                        this.FN        = dMember.FN;
                    }
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Constructor for creating/initializing an
 /// enterprise server domain
 /// </summary>
 internal EnterpriseDomain(bool Create)
 {
     store  = Store.GetStore();
     domain = this.GetServerDomain(Create);
     if (domain == null)
     {
         throw new SimiasException("Enterprise domain could not created or initialized");
     }
 }
Esempio n. 6
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);
        }
Esempio n. 7
0
/*
 *              public iFolderUser(Simias.Storage.Member member,
 *                                                      Novell.AddressBook.Contact contact)
 *              {
 *                      if(contact != null)
 *                      {
 *                              Novell.AddressBook.Name name;
 *
 *                              name = contact.GetPreferredName();
 *                              if(name != null)
 *                              {
 *                                      this.Surname = name.Family;
 *                                      this.FirstName = name.Given;
 *                              }
 *                              this.FN = contact.FN;
 *                      }
 *
 *                      this.Name = member.Name;
 *                      this.UserID = member.UserID;
 *                      this.ID = member.ID;
 *                      this.State = "Member";
 *                      this.IsOwner = member.IsOwner;
 *                      this.Rights = member.Rights.ToString();
 *              }
 */
        /// <summary>
        /// </summary>
        /// <param name="sub"></param>
        public iFolderUser(Simias.POBox.Subscription sub)
        {
            this.Name   = sub.ToName;
            this.UserID = sub.ToIdentity;

            // Need to get the member for first and last name
            Simias.Storage.Domain domain = Store.GetStore().GetDomain(sub.DomainID);
            if (domain != null)
            {
                Simias.Storage.Member simMem = domain.GetMemberByID(sub.ToIdentity);
                if (simMem != null)
                {
                    this.Surname   = simMem.Family;
                    this.FirstName = simMem.Given;
                    this.FN        = simMem.FN;
                }
            }

            this.Rights    = sub.SubscriptionRights.ToString();
            this.ID        = sub.ID;
            this.iFolderID = sub.SubscriptionCollectionID;
            this.State     = "Invited";
            this.IsOwner   = false;

            if (sub.SubscriptionState ==
                Simias.POBox.SubscriptionStates.Invited)
            {
                this.State = "WaitSync";
            }
            else if (sub.SubscriptionState ==
                     Simias.POBox.SubscriptionStates.Posted)
            {
                this.State = "Invited";
            }
            else if (sub.SubscriptionState ==
                     Simias.POBox.SubscriptionStates.Pending)
            {
                this.State = "AccessRequest";
            }
            else if (sub.SubscriptionState ==
                     Simias.POBox.SubscriptionStates.Responded)
            {
                if (sub.SubscriptionDisposition ==
                    Simias.POBox.SubscriptionDispositions.Declined)
                {
                    this.State = "Declined";
                }
                else
                {
                    this.State = "Unknown";
                }
            }
            else
            {
                this.State = "Unknown";
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Method to change a user's password
        /// </summary>
        /// <param name="Username" mandatory="true">Username to set the password on.</param>
        /// <param name="OldPassword" mandatory="true">Old password.</param>
        /// <param name="NewPassword" mandatory="true">New password.</param>
        /// <returns>int status for different status results</returns>
        static public int ChangePassword(string UserID, string OldPassword, string NewPassword)
        {
            int   status = 2;            //2 is for Failed to reset password.
            Store store  = null;

            Simias.Storage.Domain domain = null;
            Member   member   = null;
            Property DNprop   = null;
            string   MemberDN = null;

            if (User.provider != null && OldPassword != null && NewPassword != null)
            {
                store  = Store.GetStore();
                domain = store.GetDomain(store.DefaultDomain);
                member = domain.GetMemberByID(UserID);
                if (member != null)
                {
                    DNprop =
                        member.Properties.GetSingleProperty("DN");
                    if (DNprop != null && DNprop.Value != null)
                    {
                        MemberDN = (string)DNprop.Value as string;
                        if (Simias.Service.Manager.LdapServiceEnabled == false)
                        {
                            status = User.provider.ResetPassword(MemberDN, OldPassword, NewPassword);
                        }
                        else
                        {
                            Simias.Server.IUserProvider userProvider = null;
                            Simias.Configuration        config       = Store.Config;
                            string assemblyName = String.Empty;
                            assemblyName = config.Get("Identity", "Assembly");
                            string userClass = config.Get("Identity", "Class");
                            if (assemblyName != null && userClass != null)
                            {
                                Assembly idAssembly = Assembly.LoadWithPartialName(assemblyName);
                                if (idAssembly != null)
                                {
                                    Type type = idAssembly.GetType(userClass);
                                    if (type != null)
                                    {
                                        userProvider = Activator.CreateInstance(type) as IUserProvider;
                                        if (userProvider != null)
                                        {
                                            status = userProvider.ResetPassword(MemberDN, OldPassword, NewPassword);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(status);
        }
Esempio n. 9
0
        GetPublicKey()
        {
            Simias.Storage.Domain    domain = store.GetDomain(store.LocalDomain);
            RSACryptoServiceProvider pubKey = domain.Owner.PublicKey;

            log.Debug("Public Key: " + pubKey.ToString());
            log.Debug("Public Key (XML): " + pubKey.ToXmlString(false));

            return(pubKey.ToXmlString(false));
        }
Esempio n. 10
0
        public DomainInfo GetDomainInfo(string userID)
        {
            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.");
            }

            DomainInfo info = new DomainInfo();

            info.ID          = domain.ID;
            info.Name        = domain.Name;
            info.Description = domain.Description;

            // member info
            Member member = domain.GetMemberByID(userID);

            if (member != null)
            {
                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);
        }
Esempio n. 11
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));
        }
Esempio n. 12
0
        public void RemoveServerCollections(string DomainID, string UserID)
        {
            Store store = Store.GetStore();

            if (DomainID == null)
            {
                throw new SimiasException("Null Domain ID");
            }

            // This method can only target the simple server
            Simias.Storage.Domain domain = store.GetDomain(DomainID);
            if (domain == null)
            {
                throw new SimiasException("Specified server domain does not exist.");
            }

            /*
             * if ( domainID != domain.ID )
             * {
             *      throw new SimiasException("Only the Simias Server domain can be used.");
             * }
             */

            // Make sure that the caller is the current owner.
            string existingUserID = Thread.CurrentPrincipal.Identity.Name;
            Member existingMember = domain.GetMemberByID(existingUserID);

            if (existingMember == null)
            {
                throw new SimiasException(String.Format("Impersonating user: {0} is not a member of the domain.", Thread.CurrentPrincipal.Identity.Name));
            }

            // Make sure the creator and the owner are the same ID.
            if (existingUserID != UserID)
            {
                throw new SimiasException(String.Format("Creator ID {0} is not the same as the caller ID {1}.", existingUserID, UserID));
            }

            // Get all of the collections that this user is member of.
            ICSList cList = store.GetCollectionsByUser(UserID);

            foreach (ShallowNode sn in cList)
            {
                // Remove the user as a member of this collection.
                Collection c = new Collection(store, sn);

                // Only look for collections from the specified domain and
                // don't allow this user's membership from being removed from the domain.
                if ((c.Domain == DomainID) &&
                    !((Node)c).IsBaseType(Simias.Client.NodeTypes.DomainType))
                {
                    Member member = c.GetMemberByID(UserID);
                    if (member != null)
                    {
                        if (member.IsOwner)
                        {
                            // Don't remove an orphaned collection.
                            if ((member.UserID != domain.Owner.UserID) || (c.PreviousOwner == null))
                            {
                                // The user is the owner, delete this collection.
                                c.Commit(c.Delete());
                            }
                        }
                        else
                        {
                            // Not the owner, just remove the membership.
                            c.Commit(c.Delete(member));
                        }
                    }
                }
            }
        }
Esempio n. 13
0
        public string CreateMaster(string collectionID, string collectionName, string rootDirID, string rootDirName, string userID, string memberName, string memberID, string memberRights)
        {
            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.");
            }

            ArrayList  nodeList = new ArrayList();
            Collection c        = new Collection(store, collectionName, collectionID, domain.ID);

            c.Proxy = true;
            nodeList.Add(c);

            string existingUserID = Thread.CurrentPrincipal.Identity.Name;
            Member existingMember = domain.GetMemberByID(existingUserID);

            if (existingMember == null)
            {
                throw new SimiasException(String.Format("Impersonating user: {0} is not a member of the domain.", Thread.CurrentPrincipal.Identity.Name));
            }

            // Make sure the creator and the owner are the same ID.
            if (existingUserID != userID)
            {
                throw new SimiasException(String.Format("Creator ID {0} is not the same as the caller ID {1}.", existingUserID, userID));
            }

            // member node.
            Access.Rights rights = (Access.Rights)Enum.Parse(typeof(Access.Rights), memberRights);
            Member        member = new Member(memberName, memberID, userID, rights, null);

            member.IsOwner = true;
            member.Proxy   = true;
            nodeList.Add(member);

            // check for a root dir node
            if (((rootDirID != null) && (rootDirID.Length > 0)) &&
                (rootDirName != null) && (rootDirName.Length > 0))
            {
                // Get the collections Unmanaged Path
                string path = c.UnmanagedPath;
                path = Path.Combine(path, rootDirName);

                // create root directory node
                DirNode dn = new DirNode(c, path, rootDirID);

                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                dn.Proxy = true;
                nodeList.Add(dn);
            }

            // Create the collection.
            c.Commit(nodeList.ToArray(typeof(Node)) as Node[]);

            // get the collection master url
            Uri        request = Context.Request.Url;
            UriBuilder uri     =
                new UriBuilder(request.Scheme, request.Host, request.Port, Context.Request.ApplicationPath.TrimStart(new char[] { '/' }));

            return(uri.ToString());
        }
Esempio n. 14
0
 private void Init()
 {
     hostAddress = MyDns.GetHostName();
        Store store = Store.GetStore();
        try
        {
     Uri localUri = Manager.LocalServiceUrl;
     Simias.Storage.Domain rDomain = store.GetDomain( ID );
     if (rDomain == null)
     {
      rDomain =
       new Simias.Storage.Domain(
        store,
        this.domainName,
        Simias.Gaim.GaimDomain.ID,
        this.description,
        Simias.Sync.SyncRoles.Master,
        Simias.Storage.Domain.ConfigurationType.Workgroup );
      rDomain.SetType( rDomain, "Workgroup" );
      string storedUserID = GetGaimUserID();
      if (storedUserID != null)
      {
       log.Debug("Creating the Gaim Domain with a saved UserID");
       userID = storedUserID;
      }
      else
      {
       log.Debug("Creating the Gaim Domain with a NEW UserID");
       userID = Guid.NewGuid().ToString();
      }
      Member member =
       new Member(
        userName,
        userID,
        Access.Rights.Admin );
      member.IsOwner = true;
      if (localUri == null)
      {
       localUri = Manager.LocalServiceUrl;
       if (localUri != null)
       {
        Simias.Storage.Property p = new Property("Gaim:SimiasURL", localUri.ToString());
        p.LocalProperty = true;
        member.Properties.AddProperty(p);
       }
       else
       {
        log.Debug("Manager.LocalServiceUrl returned NULL!");
       }
      }
      if (aliasName != null && aliasName.Length > 0)
      {
       Simias.Storage.Property p = new Property("Gaim:Alias", aliasName);
       p.LocalProperty = true;
       member.FN = string.Format("{0} ({1})", aliasName, hostName);
      }
      rDomain.Commit( new Node[] { rDomain, member } );
      store.AddDomainIdentity( rDomain.ID, member.UserID );
      GaimService.RegisterDomainProvider();
     }
     Member pMember;
     Simias.POBox.POBox poBox = null;
     string poBoxName = "POBox:" + Simias.Gaim.GaimDomain.ID + ":" + userID;
     try
     {
      poBox = Simias.POBox.POBox.FindPOBox( store, Simias.Gaim.GaimDomain.ID, userID );
     }
     catch{}
     if (poBox == null)
     {
      poBox = new Simias.POBox.POBox( store, poBoxName, ID );
      pMember =
       new Member( userName, userID, Access.Rights.ReadWrite );
      pMember.IsOwner = true;
      poBox.Commit(new Node[] { poBox, pMember });
     }
     else
     {
      pMember = poBox.GetMemberByID( userID );
      if (pMember == null)
      {
       pMember =
        new Member( userName, userID, Access.Rights.ReadWrite );
       pMember.IsOwner = true;
       poBox.Commit(new Node[] { pMember });
      }
     }
     poBoxID = poBox.ID;
        }
        catch( Exception e1 )
        {
     log.Error(e1.Message);
     log.Error(e1.StackTrace);
     throw e1;
        }
 }
Esempio n. 15
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);
        }
Esempio n. 16
0
        /// <summary>
        /// Summary description for Http
        /// </summary>
        /// <param name="domainID"></param>
        /// <param name="ctx"></param>
        static public Simias.Storage.Member GetMember(string domainID, HttpContext ctx)
        {
            Simias.Authentication.Session simiasSession;
            Simias.Authentication.Status  status;
            Simias.Storage.Domain         domain = null;
            Simias.Storage.Member         member = null;
            Store store = Store.GetStore();

            ctx.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            //
            // Look for the special domain ID header in the request.  If the
            // header doesn't exist use the default domain
            //

            if ((domainID != null) && (domainID != String.Empty))
            {
                domain = store.GetDomain(domainID);
            }

            if (domain == null)
            {
                ctx.Response.StatusCode        = 500;
                ctx.Response.StatusDescription = "Invalid Domain";
                ctx.ApplicationInstance.CompleteRequest();
                return(null);
            }

            if (ctx.Session != null)
            {
                simiasSession = ctx.Session[sessionTag] as Simias.Authentication.Session;
                if (simiasSession != null)
                {
                    ctx.User = simiasSession.User;
                }

                if (ctx.User.Identity.IsAuthenticated == false)
                {
                    status = DomainProvider.Authenticate(domain, ctx);
                    if (status.statusCode != StatusCodes.Success &&
                        status.statusCode != StatusCodes.SuccessInGrace)
                    {
                        Simias.Authentication.Http.SetResponseHeaders(ctx, status);
                        if (ctx.Response.StatusCode == 401)
                        {
                            ctx.Response.AddHeader(
                                "WWW-Authenticate",
                                String.Concat("Basic realm=\"", domain.Name, "\""));
                        }

                        ctx.ApplicationInstance.CompleteRequest();
                        return(null);
                    }

                    // Authentication modules are required to set the member's
                    // userID on successful authentication - let's make sure
                    if (status.UserID == null || status.UserID == "")
                    {
                        ctx.Response.StatusCode        = 500;
                        ctx.Response.StatusDescription = "Unknown UserID";
                        ctx.ApplicationInstance.CompleteRequest();
                        return(null);
                    }

                    member = domain.GetMemberByID(status.UserID);
                    if (member == null)
                    {
                        ctx.Response.StatusCode        = 500;
                        ctx.Response.StatusDescription = "Unknown Member in Domain";
                        ctx.ApplicationInstance.CompleteRequest();
                        return(null);
                    }

                    if (status.statusCode == StatusCodes.SuccessInGrace ||
                        status.statusCode == StatusCodes.Success)
                    {
                        Simias.Authentication.Http.SetResponseHeaders(ctx, status);
                    }

                    simiasSession          = new Simias.Authentication.Session();
                    simiasSession.MemberID = member.UserID;
                    simiasSession.Requests++;
                    ctx.Session[sessionTag] = simiasSession;

                    // Setup a principal
                    simiasSession.User =
                        new GenericPrincipal(
                            new GenericIdentity(
                                member.UserID,
                                "Basic authentication"),
                            rolesArray);

                    ctx.User = simiasSession.User;
                    Thread.CurrentPrincipal = ctx.User;

                    // Set the last login time for the user.
                    SetLastLoginTime(domain, member);
                }
                else
                {
                    simiasSession.Requests++;
                    Thread.CurrentPrincipal = ctx.User;
                    member = domain.GetMemberByID(simiasSession.MemberID);
                }
            }
            else
            {
                // No session exists so "authenticate" every request
                status = DomainProvider.Authenticate(domain, ctx);
                if (status.statusCode != StatusCodes.Success &&
                    status.statusCode != StatusCodes.SuccessInGrace)
                {
                    Simias.Authentication.Http.SetResponseHeaders(ctx, status);
                    if (ctx.Response.StatusCode == 401)
                    {
                        ctx.Response.AddHeader(
                            "WWW-Authenticate",
                            String.Concat("Basic realm=\"", domain.Name, "\""));
                    }

                    ctx.ApplicationInstance.CompleteRequest();
                    return(null);
                }

                // Authentication modules are required to set the member's
                // userID on successful authentication - let's make sure
                if (status.UserID == null || status.UserID == "")
                {
                    ctx.Response.StatusCode        = 500;
                    ctx.Response.StatusDescription = "Unknown UserID-2";
                    ctx.ApplicationInstance.CompleteRequest();
                    return(null);
                }

                member = domain.GetMemberByID(status.UserID);
                if (member == null)
                {
                    ctx.Response.StatusCode        = 500;
                    ctx.Response.StatusDescription = "Unknown Member in Domain-2";
                    ctx.ApplicationInstance.CompleteRequest();
                    return(null);
                }

                // Setup a principal
                ctx.User =
                    new GenericPrincipal(
                        new GenericIdentity(
                            member.UserID,
                            "Basic authentication"),
                        rolesArray);

                Thread.CurrentPrincipal = ctx.User;

                // Set the last login time for the user.
                SetLastLoginTime(domain, member);
            }

            return(member);
        }
Esempio n. 17
0
        /// <summary>
        /// Used by server to validate the signature using PPK.
        /// </summary>
        /// <param name="domainId"></param>
        /// <param name="memberId"></param>
        /// <param name="signed"></param>
        /// <param name="ctx"></param>
        static public void VerifyWithPPK(string domainId, string memberId, byte[] signed, HttpContext ctx)
        {
            Simias.Authentication.Session simiasSession;
            Simias.Storage.Domain         domain = null;
            Simias.Storage.Member         member = null;
            Store store = Store.GetStore();

            ctx.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            domain = store.GetDomain(domainId);
            if (domain == null)
            {
                ctx.Response.StatusCode        = 500;
                ctx.Response.StatusDescription = "Invalid Domain";
                ctx.ApplicationInstance.CompleteRequest();
                return;
            }

            member = domain.GetMemberByID(memberId);
            if (member == null)
            {
                ctx.Response.StatusCode        = 500;
                ctx.Response.StatusDescription = "Invalid Member";
                ctx.ApplicationInstance.CompleteRequest();
                return;
            }

            if (ctx.Session == null)
            {
                // Must have a session.
                ctx.Response.StatusCode = 401;
                ctx.Response.AddHeader(
                    "WWW-Authenticate",
                    String.Concat("Basic realm=\"", domain.Name, "\""));

                ctx.ApplicationInstance.CompleteRequest();
                return;
            }

            simiasSession = ctx.Session[sessionTag] as Simias.Authentication.Session;
            if (simiasSession != null)
            {
                ctx.User = simiasSession.User;
            }

            if (ctx.User.Identity.IsAuthenticated == false)
            {
                // Validate signature.
                string nonce      = (string)ctx.Session[NonceKey];
                byte[] nonceBytes = Nonce.GetBytes(nonce);
                if (member.PublicKey.VerifyData(nonceBytes, new SHA1CryptoServiceProvider(), signed))
                {
                    simiasSession          = new Simias.Authentication.Session();
                    simiasSession.MemberID = member.UserID;
                    simiasSession.Requests++;
                    ctx.Session[sessionTag] = simiasSession;

                    // Setup a principal
                    simiasSession.User =
                        new GenericPrincipal(
                            new GenericIdentity(
                                member.UserID,
                                PpkType),
                            hostRoles);

                    ctx.User = simiasSession.User;
                    Thread.CurrentPrincipal = ctx.User;

                    // Set the last login time for the user.
                    SetLastLoginTime(domain, member);
                }
                else
                {
                    // Failed
                    ctx.Response.StatusCode = 401;
                    ctx.Response.AddHeader(
                        "WWW-Authenticate",
                        String.Concat("Basic realm=\"", domain.Name, "\""));
                    ctx.ApplicationInstance.CompleteRequest();
                    return;
                }
            }
            else
            {
                simiasSession.Requests++;
                Thread.CurrentPrincipal = ctx.User;
                member = domain.GetMemberByID(simiasSession.MemberID);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Method to get the Simias Enterprise server domain
        /// If the the domain does not exist and the create flag is true
        /// the domain will be created.  If create == false, ownerName is ignored
        /// </summary>
        internal Simias.Storage.Domain GetServerDomain(bool Create)
        {
            //  Check if the Server domain exists in the store
            Simias.Storage.Domain enterpriseDomain = null;
            bool master = true;

            try
            {
                Collection collection = store.GetSingleCollectionByType("Enterprise");
                if (collection != null)
                {
                    enterpriseDomain = store.GetDomain(collection.ID);
                    if (enterpriseDomain != null)
                    {
                        this.domainName = enterpriseDomain.Name;
                        this.id         = enterpriseDomain.ID;

                        // For backwards compatibility, if the report collection does not
                        // exist because the store was created with a previous version of
                        // simias, check and create it here.
                        // Don't create this directory on a slave server.

                        //TODO : Check with migration !!
                        Report.CreateReportCollection(store, enterpriseDomain);
                    }
                }

                if (enterpriseDomain == null && Create == true)
                {
                    // Bootstrap the domain from the Simias.config file
                    Simias.Configuration config = Store.Config;
                    string cfgValue             = config.Get("EnterpriseDomain", "SystemName");
                    if (cfgValue != null && cfgValue != String.Empty)
                    {
                        this.domainName = cfgValue;
                    }

                    cfgValue = config.Get("EnterpriseDomain", "Description");
                    if (cfgValue != null && cfgValue != String.Empty)
                    {
                        this.description = cfgValue;
                    }

                    cfgValue = config.Get("EnterpriseDomain", "AdminName");
                    if (cfgValue != null && cfgValue != String.Empty)
                    {
                        this.admin = cfgValue;
                    }

                    cfgValue = config.Get("Server", "MasterAddress");
                    if (cfgValue != null && cfgValue != String.Empty)
                    {
                        master = false;
                    }

                    /*
                     * cfgValue = config.Get( "EnterpriseDomain", "AdminPassword" );
                     * if ( cfgValue != null && cfgValue != "" )
                     * {
                     *      this.adminPassword = cfgValue;
                     * }
                     */

                    if (master == true)
                    {
                        cfgValue = config.Get("EnterpriseDomain", "DomainID");
                        if (cfgValue != null && cfgValue != String.Empty)
                        {
                            this.id = cfgValue;
                        }
                        else
                        {
                            this.id = Guid.NewGuid().ToString();
                        }

                        // Create the enterprise server domain.
                        enterpriseDomain =
                            new Simias.Storage.Domain(
                                store,
                                this.domainName,
                                this.id,
                                this.description,
                                Simias.Sync.SyncRoles.Master,
                                Simias.Storage.Domain.ConfigurationType.ClientServer);

                        // This needs to be added to allow the enterprise location provider
                        // to be able to resolve this domain.
                        enterpriseDomain.SetType(enterpriseDomain, "Enterprise");

                        // Create the owner member for the domain.
                        string provider = null;
                        cfgValue = config.Get("Identity", "Assembly");
                        if (cfgValue != null && cfgValue != String.Empty)
                        {
                            provider = cfgValue;
                        }

                        this.admin = ParseUserName(this.admin, provider);

                        Member member =
                            new Member(this.admin, Guid.NewGuid().ToString(), Access.Rights.Admin);

                        member.IsOwner = true;
                        enterpriseDomain.SetType(member as Node, "User");

                        // Marker so we know this member was created internally
                        // and not through an external identity sync.
                        enterpriseDomain.SetType(member as Node, "Internal");

                        enterpriseDomain.Commit(new Node[] { enterpriseDomain, member });

                        // Set the domain default
                        store.DefaultDomain = enterpriseDomain.ID;

                        // Create the name mapping.
                        store.AddDomainIdentity(enterpriseDomain.ID, member.UserID);
                    }
                    else
                    {
                        // Slave host so create the proxy domain and owner.
                        enterpriseDomain      = Simias.Host.SlaveSetup.GetDomain(Store.StorePath);
                        store.DefaultDomain   = enterpriseDomain.ID;
                        enterpriseDomain.Role = Simias.Sync.SyncRoles.Slave;
                        Member owner = Simias.Host.SlaveSetup.GetOwner(Store.StorePath);
                        enterpriseDomain.SetType(enterpriseDomain, "Enterprise");
                        enterpriseDomain.Proxy = true;
                        owner.Proxy            = true;
                        enterpriseDomain.Commit(new Node[] { enterpriseDomain, owner });
                    }

                    Report.CreateReportCollection(store, enterpriseDomain);
                }
            }
            catch (Exception gssd)
            {
                log.Error(gssd.Message);
                log.Error(gssd.StackTrace);
            }

            return(enterpriseDomain);
        }