/// <summary> /// Get taxa that belongs to authority. /// </summary> /// <param name="context">Web service request context.</param> /// <param name="authority">Check access right in this authority.</param> /// <returns>Taxa that belongs to authority.</returns> private TaxonList GetTaxa(WebServiceContext context, WebAuthority authority) { String authorityTaxaCacheKey; TaxonList taxa; // Get cached information. authorityTaxaCacheKey = Settings.Default.AuthorityTaxaCacheKey + WebService.Settings.Default.CacheKeyDelimiter + authority.Id; taxa = (TaxonList)(context.GetCachedObject(authorityTaxaCacheKey)); // Data not in cache - store it in the cache. if (taxa.IsNull()) { taxa = GetChildTaxa(authority.TaxonGUIDs, TaxonInformationType.Basic); // Add information to cache. context.AddCachedObject(authorityTaxaCacheKey, taxa, DateTime.Now + new TimeSpan(0, 1, 0, 0), CacheItemPriority.BelowNormal); } return(taxa); }
public void Constructor() { WebAuthority authority; authority = new WebAuthority(); Assert.IsNotNull(authority); }
/// <summary> /// Check the data in current object /// </summary> /// <param name='authority'>The authority.</param> public static void CheckData(this WebAuthority authority) { if (!authority.IsDataChecked) { authority.CheckStrings(); authority.IsDataChecked = true; } }
private WebAuthority GetAuthority(Boolean refresh) { if (_authority.IsNull() || refresh) { _authority = new WebAuthority(); } return(_authority); }
/// <summary> /// Get WebAuthority from Authority. /// </summary> /// <param name="userContext">User context.</param> /// <param name="authority">Authority.</param> /// <returns>WebAuthority.</returns> public WebAuthority GetAuthority(IUserContext userContext, IAuthority authority) { WebAuthority webAuthority; webAuthority = new WebAuthority(); webAuthority.ActionGUIDs = authority.ActionGUIDs; webAuthority.FactorGUIDs = authority.FactorGUIDs; webAuthority.LocalityGUIDs = authority.LocalityGUIDs; webAuthority.ProjectGUIDs = authority.ProjectGUIDs; webAuthority.RegionGUIDs = authority.RegionGUIDs; webAuthority.TaxonGUIDs = authority.TaxonGUIDs; webAuthority.ReadPermission = authority.ReadPermission; webAuthority.CreatePermission = authority.CreatePermission; webAuthority.UpdatePermission = authority.UpdatePermission; webAuthority.DeletePermission = authority.DeletePermission; webAuthority.MaxProtectionLevel = authority.MaxProtectionLevel; webAuthority.ShowNonPublicData = authority.ReadNonPublicPermission; webAuthority.RoleId = authority.RoleId; if (authority.AdministrationRoleId.HasValue) { webAuthority.AdministrationRoleId = authority.AdministrationRoleId.Value; } webAuthority.Identifier = authority.Identifier; webAuthority.CreatedBy = authority.UpdateInformation.CreatedBy; webAuthority.CreatedDate = authority.UpdateInformation.CreatedDate; webAuthority.Description = authority.Description; webAuthority.GUID = authority.GUID; webAuthority.Id = authority.Id; webAuthority.IsAdministrationRoleIdSpecified = authority.AdministrationRoleId.HasValue; webAuthority.ModifiedBy = authority.UpdateInformation.ModifiedBy; webAuthority.ModifiedDate = authority.UpdateInformation.ModifiedDate; webAuthority.Name = authority.Name; webAuthority.Obligation = authority.Obligation; webAuthority.ValidFromDate = authority.ValidFromDate; webAuthority.ValidToDate = authority.ValidToDate; webAuthority.AuthorityType = authority.AuthorityType; // If authority is of type data type the id and identifier must be set, // otherwise the autority is associated with an application. // if(authority.AuthorityType.Equals(AuthorityType.DataType)) if (authority.AuthorityDataType.IsNotNull()) { WebAuthorityDataType webAuthorityDataType = new WebAuthorityDataType(); webAuthorityDataType.Id = authority.AuthorityDataType.Id; webAuthorityDataType.Identifier = authority.AuthorityDataType.Identifier; webAuthority.AuthorityDataType = webAuthorityDataType; } else { webAuthority.ApplicationId = authority.ApplicationId; } return(webAuthority); }
/// <summary> /// Check if user has access right to this species observation. /// </summary> /// <param name="context">Web service request context.</param> /// <param name="authority">Check access right in this authority.</param> /// <returns>True if user has access right to this observation.</returns> private Boolean CheckAccessRights(WebServiceContext context, WebAuthority authority) { Dictionary <Int32, WebTaxon> taxa; List <WebRegionGeography> regionsGeography; WebPoint point; // Test if authority is related to species observations. if (authority.Identifier != AuthorityIdentifier.Sighting.ToString()) { return(false); } // Test if authority has enough protection level. if (authority.MaxProtectionLevel < ProtectionLevel) { return(false); } // Test if species observation is inside regions. if (authority.RegionGUIDs.IsNotEmpty()) { point = new WebPoint(CoordinateX, CoordinateY); regionsGeography = WebServiceData.RegionManager.GetRegionsGeographyByGuids(context, authority.RegionGUIDs, WebServiceData.SpeciesObservationManager.SpeciesObservationCoordinateSystem); if (!regionsGeography.IsPointInsideGeometry(context, WebServiceData.SpeciesObservationManager.SpeciesObservationCoordinateSystem, point)) { return(false); } } // Test if species observation belongs to specified taxa. if (authority.TaxonGUIDs.IsNotEmpty()) { taxa = WebServiceData.TaxonManager.GetTaxaByAuthority(context, authority); if (!taxa.ContainsKey(DyntaxaTaxonId)) { return(false); } } // Species observation has passed all tests. // User has access right to this species observation. return(true); }
public void Authorities() { Assert.IsNull(GetRole().Authorities); List <WebAuthority> authorities = new List <WebAuthority>(); for (int i = 1; i <= 5; i++) { WebAuthority authority = new WebAuthority(); authority.Id = i; authority.Identifier = "TestIdentity"; authorities.Add(authority); } GetRole(true).Authorities = authorities; Assert.AreEqual(authorities, GetRole().Authorities); }
/// <summary> /// Load data into the WebAuthority instance. /// </summary> /// <param name='authority'>The authority.</param> /// <param name='dataReader'>An open data reader.</param> public static void LoadData(this WebAuthority authority, DataReader dataReader) { // Authority authority.Id = dataReader.GetInt32(AuthorityData.ID); authority.GUID = dataReader.GetString(AuthorityData.GUID); authority.Name = dataReader.GetString(AuthorityData.NAME); authority.RoleId = dataReader.GetInt32(AuthorityData.ROLE_ID); if (dataReader.IsNotDbNull(AuthorityData.APPLICATION_ID)) { authority.ApplicationId = dataReader.GetInt32(AuthorityData.APPLICATION_ID); } authority.Identifier = dataReader.GetString(AuthorityData.AUTHORITY_IDENTITY); //Set type of authority based on application or authority data type/dataType. if (dataReader.IsNotDbNull(AuthorityData.AUTHORITY_DATA_TYPE_ID)) { authority.AuthorityDataType = new WebAuthorityDataType(); authority.AuthorityDataType.Id = dataReader.GetInt32(AuthorityDataType.AUTHORITYDATATYPE_ID); authority.AuthorityDataType.Identifier = dataReader.GetString(AuthorityDataType.AUTHORITY_DATA_TYPE_IDENTITY); authority.AuthorityType = AuthorityType.DataType; } else { authority.AuthorityType = AuthorityType.Application; } authority.ShowNonPublicData = dataReader.GetBoolean(AuthorityData.SHOW_NON_PUBLIC_DATA); authority.MaxProtectionLevel = dataReader.GetInt32(AuthorityData.MAX_PROTECTION_LEVEL); authority.ReadPermission = dataReader.GetBoolean(AuthorityData.READ_PERMISSION); authority.CreatePermission = dataReader.GetBoolean(AuthorityData.CREATE_PERMISSION); authority.UpdatePermission = dataReader.GetBoolean(AuthorityData.UPDATE_PERMISSION); authority.DeletePermission = dataReader.GetBoolean(AuthorityData.DELETE_PERMISSION); authority.Description = dataReader.GetString(AuthorityData.DESCRIPTION); authority.Obligation = dataReader.GetString(AuthorityData.OBLIGATION); authority.IsAdministrationRoleIdSpecified = dataReader.IsNotDbNull(PersonData.ADMINISTRATION_ROLE_ID); if (authority.IsAdministrationRoleIdSpecified) { authority.AdministrationRoleId = dataReader.GetInt32(PersonData.ADMINISTRATION_ROLE_ID); } authority.CreatedDate = dataReader.GetDateTime(AuthorityData.CREATED_DATE); authority.CreatedBy = dataReader.GetInt32(AuthorityData.CREATED_BY, 0); authority.ModifiedDate = dataReader.GetDateTime(AuthorityData.MODIFIED_DATE); authority.ModifiedBy = dataReader.GetInt32(AuthorityData.MODIFIED_BY, 0); authority.ValidFromDate = dataReader.GetDateTime(AuthorityData.VALID_FROM_DATE); authority.ValidToDate = dataReader.GetDateTime(AuthorityData.VALID_TO_DATE); }
/// <summary> /// Test if access rights to species observations are /// easy or complex to handle. /// </summary> /// <param name="authority">Authority to test.</param> /// <returns>True, if access rights to species observations are easy to handle.</returns> private static Boolean IsSimpleSpeciesObservationAccessRights(WebAuthority authority) { if (authority.Identifier != AuthorityIdentifier.Sighting.ToString()) { // Authority is not related to species observations. return(true); } if (authority.RegionGUIDs.IsNotEmpty() || authority.TaxonGUIDs.IsNotEmpty()) { // Complex species observation access rights found. return(false); } // No complex species observation access rights found. return(true); }
public WebAuthorityTest() { _authority = null; }