* Fixed webapi auth
* WIP signalauth * Fist commit server config
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
|
||||
namespace Step.Config
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public enum ACTIONS
|
||||
{
|
||||
READ,
|
||||
WRITE
|
||||
}
|
||||
|
||||
public static string ROLE_LEVEL_KEY = "roleLevel";
|
||||
public static string USERNAME_KEY = "username";
|
||||
public static string ID_KEY = "id";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Le informazioni generali relative a un assembly sono controllate dal seguente
|
||||
// set di attributi. Modificare i valori di questi attributi per modificare le informazioni
|
||||
// associate a un assembly.
|
||||
[assembly: AssemblyTitle("Step.Config")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Step.Config")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Se si imposta ComVisible su false, i tipi in questo assembly non saranno visibili
|
||||
// ai componenti COM. Se è necessario accedere a un tipo in questo assembly da
|
||||
// COM, impostare su true l'attributo ComVisible per tale tipo.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Se il progetto viene esposto a COM, il GUID seguente verrà utilizzato come ID della libreria dei tipi
|
||||
[assembly: Guid("3f5c2483-fc87-43ef-92a8-66ff7d0e440f")]
|
||||
|
||||
// Le informazioni sulla versione di un assembly sono costituite dai seguenti quattro valori:
|
||||
//
|
||||
// Versione principale
|
||||
// Versione secondaria
|
||||
// Numero di build
|
||||
// Revisione
|
||||
//
|
||||
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
|
||||
// usando l'asterisco '*' come illustrato di seguito:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Step.Model.ConfigModels;
|
||||
|
||||
namespace Step.Config
|
||||
{
|
||||
public static class StartupConfig
|
||||
{
|
||||
public static GenericConfigModel genericConfig;
|
||||
|
||||
public static AreasConfigModel productionConfig;
|
||||
public static AreasConfigModel toolingConfig;
|
||||
public static AreasConfigModel reportConfig;
|
||||
public static AreasConfigModel alarmsConfig;
|
||||
public static AreasConfigModel maintenanceConfig;
|
||||
public static AreasConfigModel utilitiesConfig;
|
||||
public static AreasConfigModel scadaConfig;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using System.Xml;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Xml.Schema;
|
||||
using System.Xml.Linq;
|
||||
using System.Linq;
|
||||
using static Step.Config.StartupConfig;
|
||||
using Step.Model.ConfigModels;
|
||||
|
||||
namespace Step.Config
|
||||
{
|
||||
public class StartupConfigController
|
||||
{
|
||||
public static void ReadStartUpConfig()
|
||||
{
|
||||
// Read validation file
|
||||
XmlSchemaSet readerSettings = new XmlSchemaSet();
|
||||
// Add Schema
|
||||
readerSettings.Add(null, "startupValidator.xsd");
|
||||
// Open file reader
|
||||
XDocument xmlConfigFile = XDocument.Load("startupConfig.xml");
|
||||
// Validate file
|
||||
xmlConfigFile.Validate(readerSettings, ValidationHandler);
|
||||
|
||||
// Read generic config with LINQ
|
||||
genericConfig = xmlConfigFile
|
||||
.Descendants("generalConfig")
|
||||
.Select(x => new GenericConfigModel()
|
||||
{
|
||||
Language = x.Element("language").Value,
|
||||
ServerPort = Convert.ToInt32(x.Element("serverPort").Value),
|
||||
NcVendor = Convert.ToInt32(x.Element("NcVendor").Value),
|
||||
NcIpAddress = x.Element("NcIpAddress").Value,
|
||||
NcPort = Convert.ToInt32(x.Element("NcPort").Value)
|
||||
}).FirstOrDefault();
|
||||
|
||||
xmlConfigFile
|
||||
.Descendants("areasConfig")
|
||||
.Elements()
|
||||
.ToList()
|
||||
.ForEach(x => addKeyValue(x));
|
||||
}
|
||||
|
||||
private static void addKeyValue(XElement element)
|
||||
{
|
||||
switch (element.Name.ToString())
|
||||
{
|
||||
case "production":
|
||||
SetAreasConfigValue(ref productionConfig, element);
|
||||
break;
|
||||
case "tooling":
|
||||
SetAreasConfigValue(ref toolingConfig, element);
|
||||
break;
|
||||
case "report":
|
||||
SetAreasConfigValue(ref reportConfig, element);
|
||||
break;
|
||||
case "alarms":
|
||||
SetAreasConfigValue(ref alarmsConfig, element);
|
||||
break;
|
||||
case "maintenance":
|
||||
SetAreasConfigValue(ref maintenanceConfig, element);
|
||||
break;
|
||||
case "utilities":
|
||||
SetAreasConfigValue(ref utilitiesConfig, element);
|
||||
break;
|
||||
case "scada":
|
||||
SetAreasConfigValue(ref scadaConfig, element);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetAreasConfigValue (ref AreasConfigModel areasConfig, XElement element)
|
||||
{
|
||||
areasConfig = new AreasConfigModel()
|
||||
{
|
||||
name = element.Name.ToString(),
|
||||
enabled = Convert.ToBoolean(element.Element("enabled").Value),
|
||||
allowExternalBrowser = Convert.ToBoolean(element.Element("allowExternalBrowser").Value)
|
||||
};
|
||||
}
|
||||
|
||||
private static void ValidationHandler(object sender, ValidationEventArgs e)
|
||||
{
|
||||
if (e.Severity == XmlSeverityType.Warning)
|
||||
{
|
||||
Console.Write("WARNING: ");
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
else if (e.Severity == XmlSeverityType.Error)
|
||||
{
|
||||
Console.Write("ERROR: ");
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{3F5C2483-FC87-43EF-92A8-66FF7D0E440F}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Step.Config</RootNamespace>
|
||||
<AssemblyName>Step.Config</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="StartupConfig.cs" />
|
||||
<Compile Include="StartupConfigController.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="startupValidator.xsd">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Step.Model\Step.Model.csproj">
|
||||
<Project>{631375dd-06d3-49bb-8130-d9ddb34c429d}</Project>
|
||||
<Name>Step.Model</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:element name="root">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="generalConfig">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="serverPort" type="xs:int" minOccurs='1' maxOccurs='1'/>
|
||||
<xs:element name="language" type="xs:language" minOccurs='1' maxOccurs='1'/>
|
||||
<xs:element name="NcVendor" type="NcType" minOccurs='1' maxOccurs='1'/>
|
||||
<xs:element name="NcIpAddress" minOccurs='1' maxOccurs='1'/>
|
||||
<xs:element name="NcPort" type="xs:int" minOccurs='1' maxOccurs='1'/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="areasConfig">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
|
||||
<xs:element name="production">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="enabled" type="xs:boolean"/>
|
||||
<xs:element name="allowExternalBrowser" fixed="false"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="tooling">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="enabled" type="xs:boolean"/>
|
||||
<xs:element name="allowExternalBrowser" fixed="false"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="report">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="enabled" type="xs:boolean"/>
|
||||
<xs:element name="allowExternalBrowser" type="xs:boolean"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="alarms">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="enabled" type="xs:boolean"/>
|
||||
<xs:element name="allowExternalBrowser" type="xs:boolean"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="maintenance">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="enabled" type="xs:boolean"/>
|
||||
<xs:element name="allowExternalBrowser" fixed="false"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="utilities">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="enabled" type="xs:boolean"/>
|
||||
<xs:element name="allowExternalBrowser" fixed="false"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="scada">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="enabled" type="xs:boolean"/>
|
||||
<xs:element name="allowExternalBrowser" type="xs:boolean"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:simpleType name="NcType" final="restriction" >
|
||||
<xs:restriction base="xs:integer">
|
||||
<xs:enumeration value="1" />
|
||||
<xs:enumeration value="2" />
|
||||
<xs:enumeration value="3" />
|
||||
<xs:enumeration value="4" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:schema>
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
</configSections>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
|
||||
<parameters>
|
||||
@@ -12,12 +12,18 @@
|
||||
</defaultConnectionFactory>
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.10.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
|
||||
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.10.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
|
||||
</providers>
|
||||
</entityFramework>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /></startup><system.data>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
|
||||
</startup>
|
||||
<system.data>
|
||||
<DbProviderFactories>
|
||||
<remove invariant="MySql.Data.MySqlClient" />
|
||||
<add description=".Net Framework Data Provider for MySQL" invariant="MySql.Data.MySqlClient" name="MySQL Data Provider" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.10.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
|
||||
|
||||
|
||||
</DbProviderFactories>
|
||||
</system.data>
|
||||
<runtime>
|
||||
@@ -28,4 +34,4 @@
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
</configuration>
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Step.Model;
|
||||
using static Step.Config.Constants;
|
||||
|
||||
namespace Step.Database.Controllers
|
||||
{
|
||||
public class AccessCategoriesController : IDisposable
|
||||
{
|
||||
private DatabaseContext dbCtx;
|
||||
|
||||
public AccessCategoriesController()
|
||||
{
|
||||
// Initialize database context
|
||||
dbCtx = new DatabaseContext();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database context
|
||||
dbCtx.Dispose();
|
||||
}
|
||||
|
||||
public int FindCategoryLevelByAction(string categoryName, ACTIONS action)
|
||||
{
|
||||
AccessCategoryModel accessCategories = dbCtx.AccessCategories.Where(ac => ac.Name == categoryName).FirstOrDefault();
|
||||
if (accessCategories != null)
|
||||
{
|
||||
if (ACTIONS.READ == action)
|
||||
return accessCategories.ReadLevelMin;
|
||||
else
|
||||
return accessCategories.WriteLevelMin;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,15 @@ using MySql.Data.Entity;
|
||||
|
||||
namespace Step.Database
|
||||
{
|
||||
|
||||
[DbConfigurationType(typeof(MySqlEFConfiguration))]
|
||||
public class DatabaseContext : DbContext
|
||||
{
|
||||
public DbSet<UserModel> Users { get; set; }
|
||||
public DbSet<RoleModel> Roles { get; set; }
|
||||
public DbSet<AccessCategoryModel> AccessCategories { get; set; }
|
||||
|
||||
public DatabaseContext()
|
||||
: base("databaseConnection")
|
||||
: base("mySQLDatabaseConnection")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -64,6 +66,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controllers\AccessCategoriesController.cs" />
|
||||
<Compile Include="Controllers\UsersController.cs" />
|
||||
<Compile Include="DatabaseContext.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
@@ -73,6 +76,10 @@
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Step.Config\Step.Config.csproj">
|
||||
<Project>{3f5c2483-fc87-43ef-92a8-66ff7d0e440f}</Project>
|
||||
<Name>Step.Config</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Step.Model\Step.Model.csproj">
|
||||
<Project>{631375dd-06d3-49bb-8130-d9ddb34c429d}</Project>
|
||||
<Name>Step.Model</Name>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Step.Model
|
||||
{
|
||||
[Table("access_category")]
|
||||
public class AccessCategoryModel
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
public int RoleId { get; set; }
|
||||
|
||||
[Column("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column("write_level_min")]
|
||||
public int WriteLevelMin { get; set; }
|
||||
|
||||
[Column("read_level_min")]
|
||||
public int ReadLevelMin { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Step.Model.ConfigModels
|
||||
{
|
||||
public class AreasConfigModel
|
||||
{
|
||||
public string name { get; set; }
|
||||
public bool enabled { get; set; }
|
||||
public bool allowExternalBrowser { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Step.Model.ConfigModels
|
||||
{
|
||||
public class GenericConfigModel
|
||||
{
|
||||
public string Language { get; set; }
|
||||
public int ServerPort { get; set; }
|
||||
public int NcVendor { get; set; }
|
||||
public int NcPort { get; set; }
|
||||
public string NcIpAddress { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,9 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AccessCategoryModel.cs" />
|
||||
<Compile Include="ConfigModels\AreasConfigModel.cs" />
|
||||
<Compile Include="ConfigModels\GenericConfigModel.cs" />
|
||||
<Compile Include="RoleModel.cs">
|
||||
<Generator>DtsGenerator</Generator>
|
||||
<LastGenOutput>RoleModel.cs.d.ts</LastGenOutput>
|
||||
@@ -79,6 +82,7 @@
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>XCOPY $(ProjectDir)*.d.ts $(SolutionDir)Step\wwwroot\src\@types /C /Y /O</PostBuildEvent>
|
||||
|
||||
@@ -4,12 +4,20 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
VisualStudioVersion = 15.0.27004.2009
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Step", "Step\Step.csproj", "{AFED34E1-77DB-4D81-830A-A8D0A190573D}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{3F5C2483-FC87-43EF-92A8-66FF7D0E440F} = {3F5C2483-FC87-43EF-92A8-66FF7D0E440F}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Step.Model", "Step.Model\Step.Model.csproj", "{631375DD-06D3-49BB-8130-D9DDB34C429D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Step.UI", "Step.UI\Step.UI.csproj", "{20FC0937-E7CA-4693-95F9-7A948EFD173B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Step.Database", "Step.Database\Step.Database.csproj", "{357D5EE1-FFC8-489B-9232-22CF474D9A6F}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{3F5C2483-FC87-43EF-92A8-66FF7D0E440F} = {3F5C2483-FC87-43EF-92A8-66FF7D0E440F}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Step.Config", "Step.Config\Step.Config.csproj", "{3F5C2483-FC87-43EF-92A8-66FF7D0E440F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -33,6 +41,10 @@ Global
|
||||
{357D5EE1-FFC8-489B-9232-22CF474D9A6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{357D5EE1-FFC8-489B-9232-22CF474D9A6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{357D5EE1-FFC8-489B-9232-22CF474D9A6F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3F5C2483-FC87-43EF-92A8-66FF7D0E440F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3F5C2483-FC87-43EF-92A8-66FF7D0E440F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3F5C2483-FC87-43EF-92A8-66FF7D0E440F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3F5C2483-FC87-43EF-92A8-66FF7D0E440F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<connectionStrings>
|
||||
<add name="databaseConnection" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;Database=test;Uid=root;Pwd=root;" />
|
||||
<add name="mySQLDatabaseConnection" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;Database=test;Uid=root;Pwd=root;" />
|
||||
</connectionStrings>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
|
||||
|
||||
@@ -9,6 +9,7 @@ using Microsoft.Owin.FileSystems;
|
||||
using System.Configuration;
|
||||
using Microsoft.Owin.Security.OAuth;
|
||||
using Step.Provider;
|
||||
using Step.Config;
|
||||
|
||||
[assembly: OwinStartup(typeof(Step.App_Start.Startup))]
|
||||
|
||||
@@ -18,6 +19,8 @@ namespace Step.App_Start
|
||||
{
|
||||
public void Configuration(IAppBuilder app)
|
||||
{
|
||||
StartupConfigController.ReadStartUpConfig();
|
||||
|
||||
// Configure HTTP
|
||||
HttpConfiguration config = new HttpConfiguration();
|
||||
|
||||
@@ -30,11 +33,10 @@ namespace Step.App_Start
|
||||
// Configure authentication
|
||||
ConfigureOAuth(app);
|
||||
|
||||
// Register SignalR
|
||||
app.MapSignalR();
|
||||
|
||||
app.UseWebApi(config);
|
||||
|
||||
// Register SignalR
|
||||
app.MapSignalR();
|
||||
var directoryBrowsing = ConfigurationManager.AppSettings["enableDirectoryBrowsing"] == "true";
|
||||
|
||||
string rootDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "wwwroot");
|
||||
|
||||
@@ -1,19 +1,50 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Principal;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using Step.Database.Controllers;
|
||||
using static Step.Config.Constants;
|
||||
|
||||
namespace Step
|
||||
{
|
||||
class CmsAuthorizationAttribute : AuthorizeAttribute
|
||||
{
|
||||
public string Category;
|
||||
public string Action;
|
||||
public ACTIONS Action;
|
||||
protected override bool IsAuthorized(HttpActionContext actionContext)
|
||||
{
|
||||
if (!base.IsAuthorized(actionContext))
|
||||
return false;
|
||||
|
||||
// Get user level stored in the bearer token
|
||||
ClaimsPrincipal principal = actionContext.RequestContext.Principal as ClaimsPrincipal;
|
||||
var customClaimValue = principal.Claims.Where(c => c.Type == "role").Single().Value;
|
||||
int userLevel = Convert.ToInt32(principal.Claims.Where(c => c.Type == ROLE_LEVEL_KEY).Single().Value);
|
||||
|
||||
if (!CheckAuthorization(userLevel))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.IsAuthorized(actionContext);
|
||||
}
|
||||
|
||||
private bool CheckAuthorization(int userLevel)
|
||||
{
|
||||
using (AccessCategoriesController acController = new AccessCategoriesController())
|
||||
{
|
||||
// Read from db category levels
|
||||
int categoryLevel = acController.FindCategoryLevelByAction(Category, Action);
|
||||
|
||||
if (categoryLevel > userLevel)
|
||||
{
|
||||
// Not authorized
|
||||
return false;
|
||||
}
|
||||
// Authorized
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Step.Model;
|
||||
using System.Web.Http;
|
||||
using Step.Database.Controllers;
|
||||
using static Step.Config.Constants;
|
||||
|
||||
namespace Step.Controllers
|
||||
{
|
||||
@@ -11,15 +12,11 @@ namespace Step.Controllers
|
||||
[Route(), HttpPost]
|
||||
public IHttpActionResult DoLogin(UserModel model)
|
||||
{
|
||||
UsersController usersController = new UsersController();
|
||||
|
||||
usersController.Create(model.Username, "passwor", "nome","cognome", 1);
|
||||
|
||||
if (model.Username == "utente" && model.Password == "finto") return Ok();
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
[CmsAuthorization(Category = "test", Action = "Write")]
|
||||
[CmsAuthorization(Category = "test", Action = ACTIONS.WRITE)]
|
||||
[Route("test"), HttpGet]
|
||||
public IHttpActionResult Test()
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ using Microsoft.Owin.Security.OAuth;
|
||||
using Step.Database.Controllers;
|
||||
using Step.Model;
|
||||
using System.Security.Claims;
|
||||
using static Step.Config.Constants;
|
||||
|
||||
namespace Step.Provider
|
||||
{
|
||||
@@ -33,10 +34,13 @@ namespace Step.Provider
|
||||
}
|
||||
// Create a new Identity and insert custom claims
|
||||
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
|
||||
identity.AddClaim(new Claim("username", user.Username));
|
||||
identity.AddClaim(new Claim("role", user.Role.Level.ToString()));
|
||||
identity.AddClaim(new Claim(USERNAME_KEY, user.Username));
|
||||
identity.AddClaim(new Claim(ROLE_LEVEL_KEY, user.Role.Level.ToString()));
|
||||
// Create Token with identity data
|
||||
context.Validated(identity);
|
||||
|
||||
await base.GrantResourceOwnerCredentials(context);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Groupadoo.Web.Providers
|
||||
|
||||
public override Task RequestToken(OAuthRequestTokenContext context)
|
||||
{
|
||||
var token = context.OwinContext.Request.Query["bearer_token"];
|
||||
var token = context.OwinContext.Request.Query["connectionToken"];
|
||||
if (!string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
var result = JsonConvert.DeserializeObject<TokenValue>(token);
|
||||
|
||||
@@ -145,11 +145,13 @@
|
||||
<Compile Include="App_Start\Startup.cs" />
|
||||
<Compile Include="App_Start\SwaggerConfig.cs" />
|
||||
<Compile Include="App_Start\WebApiConfig.cs" />
|
||||
<Compile Include="CmsAuthorizationAttribute.cs" />
|
||||
<Compile Include="Controllers\DataHub.cs" />
|
||||
<Compile Include="Controllers\LoginController.cs" />
|
||||
<Compile Include="program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Provider\ApplicationOAuthProvider.cs" />
|
||||
<Compile Include="Provider\SignalROAuthBearerProvider.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="App.config" />
|
||||
@@ -275,6 +277,10 @@
|
||||
<Content Include="wwwroot\Scripts\jquery-3.2.1.slim.min.map" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Step.Config\Step.Config.csproj">
|
||||
<Project>{3f5c2483-fc87-43ef-92a8-66ff7d0e440f}</Project>
|
||||
<Name>Step.Config</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Step.Database\Step.Database.csproj">
|
||||
<Project>{357d5ee1-ffc8-489b-9232-22cf474d9a6f}</Project>
|
||||
<Name>Step.Database</Name>
|
||||
|
||||
Reference in New Issue
Block a user