This commit is contained in:
sushilraje 2018-11-15 23:13:25 -08:00
Родитель 41c1d4065d 118d90469b
Коммит 65f06a3765
22 изменённых файлов: 5 добавлений и 50 удалений

Просмотреть файл

@ -60,9 +60,6 @@ namespace Services.Test
Assert.Equal(claims.FirstOrDefault(k => k.Type == NAME_KEY).Value, result.Name);
Assert.Equal(claims.FirstOrDefault(k => k.Type == ID_KEY).Value, result.Id);
Assert.NotEmpty(result.AllowedActions);
Assert.NotEmpty(result.Roles);
Assert.Contains(ADMIN_ROLE_KEY, result.Roles);
Assert.Contains(READONLY_ROLE_KEY, result.Roles);
foreach (var action in adminPolicy.AllowedActions)
{
Assert.Contains(action, result.AllowedActions);

Просмотреть файл

@ -10,6 +10,5 @@ namespace Microsoft.Azure.IoTSolutions.Auth.Services.Models
public string Name { get; set; }
public string Email { get; set; }
public List<string> AllowedActions { get; set; }
public List<string> Roles { get; set; }
}
}

Просмотреть файл

@ -16,7 +16,7 @@ namespace Microsoft.Azure.IoTSolutions.Auth.Services
public interface IUsers
{
User GetUserInfo(IEnumerable<Claim> claims);
List<string> GetAllowedActions(IEnumerable<string> roles);
IEnumerable<string> GetAllowedActions(IEnumerable<string> roles);
Task<AccessToken> GetToken(string audience);
}
@ -83,12 +83,11 @@ namespace Microsoft.Azure.IoTSolutions.Auth.Services
Id = id,
Name = name,
Email = email,
AllowedActions = allowedActions,
Roles = roles
AllowedActions = allowedActions.ToList()
};
}
public List<string> GetAllowedActions(IEnumerable<string> roles)
public IEnumerable<string> GetAllowedActions(IEnumerable<string> roles)
{
// ensure only unique values are added to the allowed actions list
// if duplicate actions are allowed in multiple roles

Просмотреть файл

@ -21,14 +21,13 @@
"CreateDeployments",
"DeleteDeployments",
"CreatePackages",
"DeletePackages",
"ReadAll"
"DeletePackages"
]
},
{
"Id": "e5bbd0f5-128e-4362-9dd1-8f253c6082d7",
"Role": "readOnly",
"AllowedActions": ["ReadAll"]
"AllowedActions": []
}
]
}

Просмотреть файл

@ -20,16 +20,12 @@ namespace Microsoft.Azure.IoTSolutions.Auth.WebService.v1.Models
[JsonProperty(PropertyName = "AllowedActions", Order = 40)]
public List<string> AllowedActions { get; set; }
[JsonProperty(PropertyName = "Roles", Order = 50)]
public List<string> Roles { get; set; }
public UserApiModel(User user)
{
this.Id = user.Id;
this.Email = user.Email;
this.Name = user.Name;
this.AllowedActions = user.AllowedActions;
this.Roles = user.Roles;
}
}
}

Просмотреть файл

@ -19,14 +19,12 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.WebService.v1.Controllers
}
[HttpGet]
[Authorize("ReadAll")]
public async Task<DeviceGroupListApiModel> GetAllAsync()
{
return new DeviceGroupListApiModel(await this.storage.GetAllDeviceGroupsAsync());
}
[HttpGet("{id}")]
[Authorize("ReadAll")]
public async Task<DeviceGroupApiModel> GetAsync(string id)
{
return new DeviceGroupApiModel(await this.storage.GetDeviceGroupAsync(id));

Просмотреть файл

@ -24,7 +24,6 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.WebService.v1.Controllers
}
[HttpGet]
[Authorize("ReadAll")]
public async Task<PackageListApiModel> GetAllAsync()
{
return new PackageListApiModel(await this.storage.GetPackagesAsync());
@ -42,7 +41,6 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.WebService.v1.Controllers
}
[HttpGet("{id}")]
[Authorize("ReadAll")]
public async Task<PackageApiModel> GetAsync(string id)
{
if (string.IsNullOrEmpty(id))

Просмотреть файл

@ -18,7 +18,6 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.WebService.v1.Controllers
}
[HttpPost]
[Authorize("ReadAll")]
public async Task PostAsync()
{
await this.seed.TrySeedAsync();

Просмотреть файл

@ -28,21 +28,18 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.WebService.v1.Controllers
}
[HttpGet("solution-settings/theme")]
[Authorize("ReadAll")]
public async Task<object> GetThemeAsync()
{
return await this.storage.GetThemeAsync();
}
[HttpPut("solution-settings/theme")]
[Authorize("ReadAll")]
public async Task<object> SetThemeAsync([FromBody] object theme)
{
return await this.storage.SetThemeAsync(theme);
}
[HttpGet("solution-settings/logo")]
[Authorize("ReadAll")]
public async Task GetLogoAsync()
{
var model = await this.storage.GetLogoAsync();
@ -50,7 +47,6 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.WebService.v1.Controllers
}
[HttpPut("solution-settings/logo")]
[Authorize("ReadAll")]
public async Task SetLogoAsync()
{
MemoryStream memoryStream = new MemoryStream();

Просмотреть файл

@ -17,7 +17,6 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.WebService.v1.Controllers
this.log = logger;
}
[Authorize("ReadAll")]
public StatusApiModel Get()
{
// TODO: calculate the actual service status

Просмотреть файл

@ -18,14 +18,12 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.WebService.v1.Controllers
}
[HttpGet("user-settings/{id}")]
[Authorize("ReadAll")]
public async Task<object> GetUserSettingAsync(string id)
{
return await this.storage.GetUserSetting(id);
}
[HttpPut("user-settings/{id}")]
[Authorize("ReadAll")]
public async Task<object> SetUserSettingAsync(string id, [FromBody] object setting)
{
return await this.storage.SetUserSetting(id, setting);

Просмотреть файл

@ -34,7 +34,6 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.WebService.v1.Controllers
}
[HttpGet]
[Authorize("ReadAll")]
public async Task<AlarmByRuleListApiModel> GetAsync(
[FromQuery] string from,
[FromQuery] string to,
@ -53,7 +52,6 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.WebService.v1.Controllers
}
[HttpPost]
[Authorize("ReadAll")]
public async Task<AlarmByRuleListApiModel> PostAsync([FromBody] QueryApiModel body)
{
string[] deviceIds = body.Devices == null
@ -70,7 +68,6 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.WebService.v1.Controllers
}
[HttpGet("{id}")]
[Authorize("ReadAll")]
public AlarmListByRuleApiModel Get(
[FromRoute] string id,
[FromQuery] string from,
@ -90,7 +87,6 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.WebService.v1.Controllers
}
[HttpPost("{id}")]
[Authorize("ReadAll")]
public AlarmListByRuleApiModel Post(
[FromRoute] string id,
[FromBody] QueryApiModel body)

Просмотреть файл

@ -34,7 +34,6 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.WebService.v1.Controllers
}
[HttpGet(Version.PATH + "/[controller]")]
[Authorize("ReadAll")]
public AlarmListApiModel List(
[FromQuery] string from,
[FromQuery] string to,
@ -53,7 +52,6 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.WebService.v1.Controllers
}
[HttpPost(Version.PATH + "/[controller]")]
[Authorize("ReadAll")]
public AlarmListApiModel Post([FromBody] QueryApiModel body)
{
string[] deviceIds = body.Devices == null
@ -70,7 +68,6 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.WebService.v1.Controllers
}
[HttpGet(Version.PATH + "/[controller]/{id}")]
[Authorize("ReadAll")]
public AlarmApiModel Get([FromRoute] string id)
{
Alarm alarm = this.alarmService.Get(id);

Просмотреть файл

@ -30,7 +30,6 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.WebService.v1.Controllers
}
[HttpGet]
[Authorize("ReadAll")]
public async Task<MessageListApiModel> GetAsync(
[FromQuery] string from,
[FromQuery] string to,
@ -49,7 +48,6 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.WebService.v1.Controllers
}
[HttpPost]
[Authorize("ReadAll")]
public async Task<MessageListApiModel> PostAsync([FromBody] QueryApiModel body)
{
string[] deviceIds = body.Devices == null

Просмотреть файл

@ -21,7 +21,6 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.WebService.v1.Controllers
}
[HttpGet("{id}")]
[Authorize("ReadAll")]
public async Task<RuleApiModel> GetAsync([FromRoute] string id)
{
Rule rule = await this.ruleService.GetAsync(id);
@ -29,7 +28,6 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.WebService.v1.Controllers
}
[HttpGet]
[Authorize("ReadAll")]
public async Task<RuleListApiModel> ListAsync(
[FromQuery] string order,
[FromQuery] int? skip,

Просмотреть файл

@ -44,7 +44,6 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.WebService.v1.Controllers
}
[HttpGet]
[Authorize("ReadAll")]
public async Task<StatusApiModel> Get()
{
var statusIsOk = true;

Просмотреть файл

@ -57,7 +57,6 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Controllers
}
[HttpGet]
[Authorize("ReadAll")]
public async Task<DeploymentListApiModel> GetAsync()
{
return new DeploymentListApiModel(await this.deployments.ListAsync());

Просмотреть файл

@ -19,7 +19,6 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Controllers
}
[HttpGet]
[Authorize("ReadAll")]
public async Task<DevicePropertiesApiModel> GetAsync()
{
return new DevicePropertiesApiModel(await this.deviceProperties.GetListAsync());

Просмотреть файл

@ -28,7 +28,6 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Controllers
/// <summary>Get a list of devices</summary>
/// <returns>List of devices</returns>
[HttpGet]
[Authorize("ReadAll")]
public async Task<DeviceListApiModel> GetDevicesAsync([FromQuery] string query)
{
string continuationToken = string.Empty;
@ -41,7 +40,6 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Controllers
}
[HttpPost("query")]
[Authorize("ReadAll")]
public async Task<DeviceListApiModel> QueryDevicesAsync([FromBody] string query)
{
string continuationToken = string.Empty;
@ -57,7 +55,6 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Controllers
/// <param name="id">Device Id</param>
/// <returns>Device information</returns>
[HttpGet("{id}")]
[Authorize("ReadAll")]
public async Task<DeviceRegistryApiModel> GetDeviceAsync(string id)
{
return new DeviceRegistryApiModel(await this.devices.GetAsync(id));

Просмотреть файл

@ -32,7 +32,6 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Controllers
/// <param name="to">Optional. The end time of interesting period</param>
/// <returns>The list of jobs</returns>
[HttpGet]
[Authorize("ReadAll")]
public async Task<IEnumerable<JobApiModel>> GetAsync(
[FromQuery] JobType? jobType,
[FromQuery] JobStatus? jobStatus,
@ -52,7 +51,6 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Controllers
/// <param name="deviceJobStatus">The interesting device job status. `null` means no restrict</param>
/// <returns>The job object</returns>
[HttpGet("{jobId}")]
[Authorize("ReadAll")]
public async Task<JobApiModel> GetJobAsync(
string jobId,
[FromQuery]bool? includeDeviceDetails,

Просмотреть файл

@ -25,7 +25,6 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Controllers
/// <param name="query">Where clause of IoTHub query</param>
/// <returns>List of module twins</returns>
[HttpGet]
[Authorize("ReadAll")]
public async Task<TwinPropertiesListApiModel> GetModuleTwinsAsync([FromQuery] string query)
{
string continuationToken = string.Empty;
@ -42,7 +41,6 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Controllers
/// <param name="query">Where clause of IoTHub query</param>
/// <returns>List of module twins</returns>
[HttpPost("query")]
[Authorize("ReadAll")]
public async Task<TwinPropertiesListApiModel> QueryModuleTwinsAsync([FromBody] string query)
{
return await this.GetModuleTwinsAsync(query);
@ -53,7 +51,6 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Controllers
/// <param name="moduleId">Module Id</param>
/// <returns>Device information</returns>
[HttpGet("{deviceId}/{moduleId}")]
[Authorize("ReadAll")]
public async Task<TwinPropertiesApiModel> GetModuleTwinAsync(string deviceId, string moduleId)
{
if (string.IsNullOrWhiteSpace(deviceId))

Просмотреть файл

@ -23,7 +23,6 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Controllers
/// <summary>Return the service status</summary>
/// <returns>Status object</returns>
[HttpGet]
[Authorize("ReadAll")]
public StatusApiModel Get()
{
return new StatusApiModel(true, "Alive and well");