/// <summary>
 /// Compares two identities by protocol, authority and identifier.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool CompareByIdentifier(GraywulfIdentity other)
 {
     return
         (StringComparer.InvariantCultureIgnoreCase.Compare(this.protocol, other.protocol) == 0 &&
          StringComparer.InvariantCultureIgnoreCase.Compare(this.authorityUri, other.authorityUri) == 0 &&
          StringComparer.InvariantCultureIgnoreCase.Compare(this.identifier, other.identifier) == 0);
 }
 private void CopyMembers(GraywulfIdentity old)
 {
     this.protocol      = old.protocol;
     this.authorityName = old.authorityName;
     this.authorityUri  = old.authorityUri;
     this.identifier    = old.identifier;
     this.userProperty  = new EntityProperty <User>(old.userProperty);
 }
        /// <summary>
        /// Creates a graywulf principal based on the guid stored in the
        /// forms authentication token.
        /// </summary>
        /// <param name="identity"></param>
        /// <returns></returns>
        public static GraywulfPrincipal Create(System.Web.Security.FormsIdentity formsIdentity)
        {
            var identity = new GraywulfIdentity()
            {
                Protocol        = Constants.ProtocolNameForms,
                Identifier      = formsIdentity.Name,
                IsAuthenticated = true,
            };

            identity.UserProperty.Name = formsIdentity.Name;
            return(new GraywulfPrincipal(identity));
        }
        /// <summary>
        /// Creates a graywulf principal based on the guid stored in the
        /// forms authentication token.
        /// </summary>
        /// <param name="identity"></param>
        /// <returns></returns>
        public static GraywulfPrincipal Create(System.Web.Security.FormsIdentity formsIdentity)
        {
            var identity = new GraywulfIdentity()
            {
                Protocol = Constants.ProtocolNameForms,
                Identifier = formsIdentity.Name,
                IsAuthenticated = true,
            };

            identity.UserProperty.Name = formsIdentity.Name;
            return new GraywulfPrincipal(identity);
        }
Exemple #5
0
        protected override void OnUserSignedIn(GraywulfIdentity identity)
        {
            // Check if user's myDB exists, if not, create
            using (var context = CreateRegistryContext())
            {
                var mydb = context.Federation.MyDBDatabaseVersion.GetUserDatabaseInstance(identity.User);

                if (mydb == null)
                {
                    var udii = new UserDatabaseInstanceInstaller(identity.User);
                    var udi = udii.GenerateUserDatabaseInstance(context.Federation.MyDBDatabaseVersion);

                    mydb = udi.DatabaseInstance;
                    mydb.Deploy();
                }
            }
        }
        /// <summary>
        /// Creates a Graywulf principal from the authentication response.
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        /// <remarks>
        /// The function also creates and initializer a registry user object by
        /// filling in the available information. The user is not save to the
        /// registry.
        /// </remarks>
        private GraywulfPrincipal CreatePrincipal(IAuthenticationResponse response)
        {
            var identity = new GraywulfIdentity()
            {
                Protocol        = this.Protocol,
                AuthorityName   = this.AuthorityName,
                AuthorityUri    = response.Provider.Uri.ToString(),
                Identifier      = response.ClaimedIdentifier,
                IsAuthenticated = false,
                User            = new User()
            };

            var fetch = response.GetExtension <FetchResponse>();

            if (fetch.Attributes.Contains(WellKnownAttributes.Contact.Email))
            {
                identity.User.Name = Util.EmailFormatter.ToUsername(fetch.Attributes[WellKnownAttributes.Contact.Email].Values[0]);
            }

            identity.User.Title      = fetch.Attributes.Contains(WellKnownAttributes.Name.Prefix) ? fetch.Attributes[WellKnownAttributes.Name.Prefix].Values[0] : "";
            identity.User.FirstName  = fetch.Attributes.Contains(WellKnownAttributes.Name.First) ? fetch.Attributes[WellKnownAttributes.Name.First].Values[0] : "";
            identity.User.MiddleName = fetch.Attributes.Contains(WellKnownAttributes.Name.Middle) ? fetch.Attributes[WellKnownAttributes.Name.Middle].Values[0] : "";
            identity.User.LastName   = fetch.Attributes.Contains(WellKnownAttributes.Name.Last) ? fetch.Attributes[WellKnownAttributes.Name.Last].Values[0] : "";
            // TODO identity.User.Gender = fetch.Attributes.Contains(WellKnownAttributes.Person.Gender) ?fetch.Attributes[WellKnownAttributes.Person.Gender].Values[0];
            identity.User.Email       = fetch.Attributes.Contains(WellKnownAttributes.Contact.Email) ? fetch.Attributes[WellKnownAttributes.Contact.Email].Values[0] : "";
            identity.User.DateOfBirth = fetch.Attributes.Contains(WellKnownAttributes.BirthDate.WholeBirthDate) ? DateTime.Parse(fetch.Attributes[WellKnownAttributes.BirthDate.WholeBirthDate].Values[0]) : new DateTime(1950, 1, 1);
            identity.User.Company     = fetch.Attributes.Contains(WellKnownAttributes.Company.CompanyName) ? fetch.Attributes[WellKnownAttributes.Company.CompanyName].Values[0] : "";
            identity.User.JobTitle    = fetch.Attributes.Contains(WellKnownAttributes.Company.JobTitle) ? fetch.Attributes[WellKnownAttributes.Company.JobTitle].Values[0] : "";
            identity.User.Address     = fetch.Attributes.Contains(WellKnownAttributes.Contact.WorkAddress.StreetAddressLine1) ? fetch.Attributes[WellKnownAttributes.Contact.WorkAddress.StreetAddressLine1].Values[0] : "";
            identity.User.Address2    = fetch.Attributes.Contains(WellKnownAttributes.Contact.WorkAddress.StreetAddressLine2) ? fetch.Attributes[WellKnownAttributes.Contact.WorkAddress.StreetAddressLine2].Values[0] : "";
            identity.User.State       = fetch.Attributes.Contains(WellKnownAttributes.Contact.WorkAddress.State) ? fetch.Attributes[WellKnownAttributes.Contact.WorkAddress.State].Values[0] : "";
            identity.User.City        = fetch.Attributes.Contains(WellKnownAttributes.Contact.WorkAddress.City) ? fetch.Attributes[WellKnownAttributes.Contact.WorkAddress.City].Values[0] : "";
            identity.User.Country     = fetch.Attributes.Contains(WellKnownAttributes.Contact.WorkAddress.Country) ? fetch.Attributes[WellKnownAttributes.Contact.WorkAddress.Country].Values[0] : "";
            identity.User.ZipCode     = fetch.Attributes.Contains(WellKnownAttributes.Contact.WorkAddress.PostalCode) ? fetch.Attributes[WellKnownAttributes.Contact.WorkAddress.PostalCode].Values[0] : "";
            identity.User.WorkPhone   = fetch.Attributes.Contains(WellKnownAttributes.Contact.Phone.Work) ? fetch.Attributes[WellKnownAttributes.Contact.Phone.Work].Values[0] : "";
            identity.User.HomePhone   = fetch.Attributes.Contains(WellKnownAttributes.Contact.Phone.Home) ? fetch.Attributes[WellKnownAttributes.Contact.Phone.Home].Values[0] : "";
            identity.User.CellPhone   = fetch.Attributes.Contains(WellKnownAttributes.Contact.Phone.Mobile) ? fetch.Attributes[WellKnownAttributes.Contact.Phone.Mobile].Values[0] : "";

            return(new GraywulfPrincipal(identity));
        }
        /// <summary>
        /// Creates a Graywulf principal from the authentication response.
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        /// <remarks>
        /// The function also creates and initializer a registry user object by
        /// filling in the available information. The user is not save to the
        /// registry.
        /// </remarks>
        private GraywulfPrincipal CreatePrincipal(IAuthenticationResponse response)
        {
            var identity = new GraywulfIdentity()
            {
                Protocol = this.Protocol,
                AuthorityName = this.AuthorityName,
                AuthorityUri = response.Provider.Uri.ToString(),
                Identifier = response.ClaimedIdentifier,
                IsAuthenticated = false,
                User = new User()
            };

            var fetch = response.GetExtension<FetchResponse>();

            if (fetch.Attributes.Contains(WellKnownAttributes.Contact.Email))
            {
                identity.User.Name = Util.EmailFormatter.ToUsername(fetch.Attributes[WellKnownAttributes.Contact.Email].Values[0]);
            }

            identity.User.Title = fetch.Attributes.Contains(WellKnownAttributes.Name.Prefix) ? fetch.Attributes[WellKnownAttributes.Name.Prefix].Values[0] : "";
            identity.User.FirstName = fetch.Attributes.Contains(WellKnownAttributes.Name.First) ? fetch.Attributes[WellKnownAttributes.Name.First].Values[0] : "";
            identity.User.MiddleName = fetch.Attributes.Contains(WellKnownAttributes.Name.Middle) ? fetch.Attributes[WellKnownAttributes.Name.Middle].Values[0] : "";
            identity.User.LastName = fetch.Attributes.Contains(WellKnownAttributes.Name.Last) ? fetch.Attributes[WellKnownAttributes.Name.Last].Values[0] : "";
            // TODO identity.User.Gender = fetch.Attributes.Contains(WellKnownAttributes.Person.Gender) ?fetch.Attributes[WellKnownAttributes.Person.Gender].Values[0];
            identity.User.Email = fetch.Attributes.Contains(WellKnownAttributes.Contact.Email) ? fetch.Attributes[WellKnownAttributes.Contact.Email].Values[0] : "";
            identity.User.DateOfBirth = fetch.Attributes.Contains(WellKnownAttributes.BirthDate.WholeBirthDate) ? DateTime.Parse(fetch.Attributes[WellKnownAttributes.BirthDate.WholeBirthDate].Values[0]) : new DateTime(1950, 1, 1);
            identity.User.Company = fetch.Attributes.Contains(WellKnownAttributes.Company.CompanyName) ? fetch.Attributes[WellKnownAttributes.Company.CompanyName].Values[0] : "";
            identity.User.JobTitle = fetch.Attributes.Contains(WellKnownAttributes.Company.JobTitle) ? fetch.Attributes[WellKnownAttributes.Company.JobTitle].Values[0] : "";
            identity.User.Address = fetch.Attributes.Contains(WellKnownAttributes.Contact.WorkAddress.StreetAddressLine1) ? fetch.Attributes[WellKnownAttributes.Contact.WorkAddress.StreetAddressLine1].Values[0] : "";
            identity.User.Address2 = fetch.Attributes.Contains(WellKnownAttributes.Contact.WorkAddress.StreetAddressLine2) ? fetch.Attributes[WellKnownAttributes.Contact.WorkAddress.StreetAddressLine2].Values[0] : "";
            identity.User.State = fetch.Attributes.Contains(WellKnownAttributes.Contact.WorkAddress.State) ? fetch.Attributes[WellKnownAttributes.Contact.WorkAddress.State].Values[0] : "";
            identity.User.City = fetch.Attributes.Contains(WellKnownAttributes.Contact.WorkAddress.City) ? fetch.Attributes[WellKnownAttributes.Contact.WorkAddress.City].Values[0] : "";
            identity.User.Country = fetch.Attributes.Contains(WellKnownAttributes.Contact.WorkAddress.Country) ? fetch.Attributes[WellKnownAttributes.Contact.WorkAddress.Country].Values[0] : "";
            identity.User.ZipCode = fetch.Attributes.Contains(WellKnownAttributes.Contact.WorkAddress.PostalCode) ? fetch.Attributes[WellKnownAttributes.Contact.WorkAddress.PostalCode].Values[0] : "";
            identity.User.WorkPhone = fetch.Attributes.Contains(WellKnownAttributes.Contact.Phone.Work) ? fetch.Attributes[WellKnownAttributes.Contact.Phone.Work].Values[0] : "";
            identity.User.HomePhone = fetch.Attributes.Contains(WellKnownAttributes.Contact.Phone.Home) ? fetch.Attributes[WellKnownAttributes.Contact.Phone.Home].Values[0] : "";
            identity.User.CellPhone = fetch.Attributes.Contains(WellKnownAttributes.Contact.Phone.Mobile) ? fetch.Attributes[WellKnownAttributes.Contact.Phone.Mobile].Values[0] : "";

            return new GraywulfPrincipal(identity);
        }
Exemple #8
0
 protected override void OnUserSignedIn(GraywulfIdentity identity)
 {
 }
 public GraywulfIdentity(GraywulfIdentity old)
 {
     CopyMembers(old);
 }
Exemple #10
0
 private void CopyMembers(GraywulfIdentity old)
 {
     this.protocol = old.protocol;
     this.authorityName = old.authorityName;
     this.authorityUri = old.authorityUri;
     this.identifier = old.identifier;
     this.userProperty = new EntityProperty<User>(old.userProperty);
 }
Exemple #11
0
 /// <summary>
 /// Compares two identities by protocol, authority and identifier.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool CompareByIdentifier(GraywulfIdentity other)
 {
     return
         StringComparer.InvariantCultureIgnoreCase.Compare(this.protocol, other.protocol) == 0 &&
         StringComparer.InvariantCultureIgnoreCase.Compare(this.authorityUri, other.authorityUri) == 0 &&
         StringComparer.InvariantCultureIgnoreCase.Compare(this.identifier, other.identifier) == 0;
 }
 public GraywulfIdentity(GraywulfIdentity old)
 {
     CopyMembers(old);
 }
Exemple #13
0
 protected override void OnUserSignedIn(GraywulfIdentity identity)
 {
     Session[Constants.SessionClusterGuid] = RegistryUser.Domain.Cluster.Guid;
     Session[Constants.SessionDomainGuid] = RegistryUser.Domain.Guid;
 }
 internal GraywulfPrincipal(GraywulfIdentity identity)
 {
     this.identity = identity;
 }
 internal GraywulfPrincipal(GraywulfIdentity identity)
 {
     this.identity = identity;
 }
Exemple #16
0
 /// <summary>
 /// Called when a user signs in
 /// </summary>
 protected abstract void OnUserSignedIn(GraywulfIdentity identity);