Merge branch 'master' into feature_rene_18_ai - kein kommentar...
# Conflicts: # BeWo/BeWo.csproj # BeWo/BeWoApp.xaml.cs # BeWo/ServiceProxy/GeneratedAiEnhancedService.cs # BeWo/Services/BeWoControlFactory.cs # BeWo/Services/BeWoWindowFactory.cs # BeWo/Services/BeWoWindowService.cs # BeWo/Services/IControlFactory.cs # BeWo/Services/IWindowFactory.cs # BeWo/Services/IWindowService.cs # BeWo/View/BeWoFileView.xaml # BeWo/View/Detail/Report/AbwesenheitsView.xaml # BeWo/View/Windows/AnimatedBeWoWindow.xaml.cs # BeWo/app.config # BeWoAllReports.sln # BeWoPlanerMobil.sln # BeWoPlanerMobil/.vs/BeWoPlanerMobil.csproj.dtbcache.json # BeWoTests.sln # Dakota/DakotaUtils.cs # Dakota/Logic/DakotaInfoCreator.cs # Dakota/Models/DakotaFile.cs # Data/Access/GenericDAO.cs # Data/Access/SearchDAO.cs # Data/Data.csproj # Host/Web.config # Server/Components/ServerUtils/ApiFacade/WebClientFacade.cs # Service/BeWoServiceEnums.cs # Service/Core/ServiceHelper.cs # Service/Core/ServiceValidator.cs # Service/Extensions/ServiceEnumExtension.cs # Service/Service.csproj # Service/ServiceContracts/Enhanced/IAiEnhancedService.cs # Service/ServiceContracts/Enhanced/IOperationsEnhancedService.cs # Service/ServiceImplementations/EmployeeServiceImp.cs # Service/ServiceImplementations/Enhanced/AiEnhancedServiceImp.cs # Service/ServiceImplementations/Enhanced/OperationsEnhancedServiceImp.cs # Service/ServiceProxy/OpenWebUIFacade.cs # Service/ServiceProxy/ServiceFacade.cs # Service/ServiceUtils/DistanceCalculator/GoogleDistanceMatrixAPI.cs # Shared/BeWoEntityEnums.cs # Shared/Core/AppError.cs # Shared/Core/Facade/WebClientFacade.cs # Shared/Core/WebClientFacade.cs # Shared/Shared.csproj
This commit is contained in:
@@ -1,21 +1,20 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Dispatcher;
|
||||
using System.Xml;
|
||||
|
||||
using BeWo.Data;
|
||||
using BeWo.Data.Access;
|
||||
using BeWo.Data.Entities;
|
||||
using BeWo.Service.Attributes;
|
||||
using BeWo.Service.Core;
|
||||
using BeWo.Service.ServiceContracts;
|
||||
using BS.Shared.Attributes;
|
||||
using BS.Shared.DataContracts;
|
||||
using BS.Shared.Extensions;
|
||||
using NHibernate.Hql.Ast.ANTLR.Tree;
|
||||
using DevExpress.Charts.Native;
|
||||
|
||||
namespace BeWo.Service.Security
|
||||
{
|
||||
@@ -66,54 +65,34 @@ namespace BeWo.Service.Security
|
||||
{
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
||||
|
||||
var lTemp = pMessage.Headers.Action.Split("/");
|
||||
string lMethodName = lTemp[lTemp.Count - 1];
|
||||
string lServiceInterface = lTemp[lTemp.Count - 2];
|
||||
var (lServiceInterface, lMethodName) = ServiceHelper.GetInterfaceAndMethodWCF(pMessage, pChannel);
|
||||
|
||||
// TODO Hier kann man jetzt etwas bauen wer sich für welchen service autorisieren muss...
|
||||
if (ALLOW_ALWAYS.Contains(lMethodName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Vergessen neue Methode einzutragen?
|
||||
}
|
||||
|
||||
string lUserName = null, lPassword = null;
|
||||
|
||||
int lSecurityHeaderIndex = pMessage.Headers.FindHeader("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
|
||||
if (lSecurityHeaderIndex < 0)
|
||||
throw new SecurityException("Nicht autorisiert");
|
||||
|
||||
if (lSecurityHeaderIndex > -1)
|
||||
{
|
||||
XmlReader lReader = pMessage.Headers.GetReaderAtHeader(lSecurityHeaderIndex);
|
||||
XmlReader lReader = pMessage.Headers.GetReaderAtHeader(lSecurityHeaderIndex);
|
||||
|
||||
if (lReader.ReadToFollowing("Username"))
|
||||
{
|
||||
lUserName = lReader.ReadString();
|
||||
}
|
||||
string lUserName = null, lPassword = null;
|
||||
if (lReader.ReadToFollowing("Username"))
|
||||
lUserName = lReader.ReadString();
|
||||
if (lReader.ReadToFollowing("Password"))
|
||||
lPassword = lReader.ReadString();
|
||||
|
||||
if (lReader.ReadToFollowing("Password"))
|
||||
{
|
||||
lPassword = lReader.ReadString();
|
||||
}
|
||||
ApplicationUser lUser = DAOFactory.UserDAO.FindUserByLoginName(lUserName);
|
||||
|
||||
ApplicationUser lUser = DAOFactory.UserDAO.FindUserByLoginName(lUserName);
|
||||
if (lUser == null || !DAOFactory.UserDAO.CheckPassword(lUser, lPassword))
|
||||
throw new SecurityException("Nicht autorisiert");
|
||||
|
||||
if (lUser != null && DAOFactory.UserDAO.CheckPassword(lUser, lPassword))
|
||||
{
|
||||
if (!HasMethodAuthorization(lUser, lMethodName, pMessage))
|
||||
{
|
||||
throw new SecurityException("Methode nicht autorisiert: " + lMethodName);
|
||||
}
|
||||
if (!HasMethodAuthorization(lUser, lServiceInterface, lMethodName))
|
||||
throw new SecurityException("Methode nicht autorisiert: " + lMethodName);
|
||||
|
||||
var lExt = new LoggedInUserOperationContextExt { User = lUser, LoginName = lUserName, UnhashedPassword = lPassword };
|
||||
OperationContext.Current.Extensions.Add(lExt);
|
||||
return lExt;
|
||||
}
|
||||
}
|
||||
|
||||
throw new SecurityException("Nicht autorisiert");
|
||||
var lExt = new LoggedInUserOperationContextExt { User = lUser, LoginName = lUserName, UnhashedPassword = lPassword };
|
||||
OperationContext.Current.Extensions.Add(lExt);
|
||||
return lExt;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -121,39 +100,19 @@ namespace BeWo.Service.Security
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasMethodAuthorization(ApplicationUser pUser, string methodName, Message pMessage)
|
||||
private bool HasMethodAuthorization(ApplicationUser pUser, string pServiceInterface, string pMethodName)
|
||||
{
|
||||
if (ALLOW_ONLY_WITH_LOGIN.Contains(methodName))
|
||||
{
|
||||
if (ALLOW_ONLY_WITH_LOGIN.Contains(pMethodName))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Vergessen neue Methode einzutragen?
|
||||
}
|
||||
|
||||
var rights = Utils.GetGrantedRights(pUser);
|
||||
|
||||
// Finde Action
|
||||
var lTemp = pMessage.Headers.Action?.Split("/");
|
||||
|
||||
if (lTemp is null)
|
||||
lTemp = pMessage.Headers.To.Segments.ToList();
|
||||
|
||||
if (lTemp is null)
|
||||
throw new ArgumentException("Kann Action nicht finden");
|
||||
|
||||
// Extrahiere MethodeName + ServiceInterface
|
||||
string lMethodName = lTemp[lTemp.Count - 1].Trim('/');
|
||||
string lServiceInterface = lTemp[lTemp.Count - 2].Trim('/');
|
||||
|
||||
try
|
||||
{
|
||||
var attribute = ServiceHelper.GetCustomAttribute<RequirePermissionAttribute>(lServiceInterface, lMethodName);
|
||||
if (attribute != null)
|
||||
{
|
||||
return attribute.HasPermission(rights);
|
||||
}
|
||||
var attribute = ServiceHelper.GetCustomAttribute<RequireWcfAuthorizationAttribute>(pServiceInterface, pMethodName);
|
||||
if (attribute is null)
|
||||
return true;
|
||||
|
||||
var rights = Utils.GetGrantedRights(pUser);
|
||||
return attribute.HasPermission(rights);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -162,6 +121,5 @@ namespace BeWo.Service.Security
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user