Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions dotnet/src/dotnetcore/GxClasses.Web/Middleware/HandlerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,6 @@ public class HandlerFactory
{"gxoauthuserinfo",typeof(GXOAuthUserInfo)},
{"gxoauthaccesstoken",typeof(GXOAuthAccessToken)},
{"gxmulticall",typeof(GXMultiCall)}};
static Dictionary<string, string> _aspxRewrite = new Dictionary<string, string>(){
{"oauth/access_token","gxoauthaccesstoken.aspx"},
{"oauth/logout","gxoauthlogout.aspx"},
{"oauth/userinfo","gxoauthuserinfo.aspx"},
{"oauth/gam/signin","agamextauthinput.aspx"},
{"oauth/gam/callback","agamextauthinput.aspx"},
{"oauth/gam/access_token","agamoauth20getaccesstoken.aspx"},
{"oauth/gam/userinfo","agamoauth20getuserinfo.aspx"},
{"oauth/gam/signout","agamextauthinput.aspx"},
{"saml/gam/signin","Saml2/SignIn"},
{"saml/gam/callback","gamexternalauthenticationinputsaml20_ws.aspx"},
{"saml/gam/signout","Saml2/Logout"},
{"oauth/requesttokenservice","agamstsauthappgetaccesstoken.aspx"},
{"oauth/queryaccesstoken","agamstsauthappvalidaccesstoken.aspx"},
{"oauth/gam/v2.0/access_token","agamoauth20getaccesstoken_v20.aspx"},
{"oauth/gam/v2.0/userinfo","agamoauth20getuserinfo_v20.aspx"},
{"oauth/gam/v2.0/requesttokenanduserinfo","aGAMSSORestRequestTokenAndUserInfo_v20.aspx"}};
private const string QUERYVIEWER_NAMESPACE = "QueryViewer.Services";
private const string GXFLOW_NSPACE = "GXflow.Programs";
private static List<string> GxNamespaces;

public HandlerFactory()
Expand Down Expand Up @@ -122,9 +103,9 @@ private static string ObjectUrl(string requestPath, string basePath)
}
lastSegment = CleanUploadUrlSuffix(lastSegment.TrimStart('/').ToLower());
GXLogging.Debug(log, "ObjectUrl:", lastSegment);
if (_aspxRewrite.ContainsKey(lastSegment))
if (HttpHelper.GAMServices.ContainsKey(lastSegment))
{
return _aspxRewrite[lastSegment];
return HttpHelper.GAMServices[lastSegment];
}
return lastSegment;
}
Expand Down Expand Up @@ -167,11 +148,15 @@ public IHttpHandler GetHandler(HttpContext context, string requestType, string u
string className;
if (cname.StartsWith("agxpl_", StringComparison.OrdinalIgnoreCase) || cname.Equals("gxqueryviewerforsd", StringComparison.OrdinalIgnoreCase))
{
className = $"{QUERYVIEWER_NAMESPACE}.{cname}";
className = $"{HttpHelper.QUERYVIEWER_NAMESPACE}.{cname}";
}
else if (Preferences.GxpmEnabled && (cname.StartsWith("awf", StringComparison.OrdinalIgnoreCase) || cname.StartsWith("wf", StringComparison.OrdinalIgnoreCase) || cname.StartsWith("apwf", StringComparison.OrdinalIgnoreCase)))
{
className = $"{GXFLOW_NSPACE}.{cname}";
className = $"{HttpHelper.GXFLOW_NSPACE}.{cname}";
}
else if (HttpHelper.GamServicesInternalName.Contains(cname))
{
className = $"{HttpHelper.GAM_NSPACE}.{cname}";
}
else
{
Expand Down
25 changes: 24 additions & 1 deletion dotnet/src/dotnetframework/GxClasses/Helpers/HttpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using Microsoft.Net.Http.Headers;
using System.Net.Http;
using System.Globalization;
using System.Linq;

namespace GeneXus.Http
{
Expand Down Expand Up @@ -72,10 +73,32 @@ public class WrappedJsonError
[DataMember(Name = "error")]
public HttpJsonError Error;
}

public class HttpHelper
{
static readonly IGXLogger log = GXLoggerFactory.GetLogger<HttpHelper>();

internal static Dictionary<string, string> GAMServices = new Dictionary<string, string>(){
{"oauth/access_token","gxoauthaccesstoken.aspx"},
{"oauth/logout","gxoauthlogout.aspx"},
{"oauth/userinfo","gxoauthuserinfo.aspx"},
{"oauth/gam/signin","agamextauthinput.aspx"},
{"oauth/gam/callback","agamextauthinput.aspx"},
{"oauth/gam/access_token","agamoauth20getaccesstoken.aspx"},
{"oauth/gam/userinfo","agamoauth20getuserinfo.aspx"},
{"oauth/gam/signout","agamextauthinput.aspx"},
{"saml/gam/signin","Saml2/SignIn"},
{"saml/gam/callback","gamexternalauthenticationinputsaml20_ws.aspx"},
{"saml/gam/signout","Saml2/Logout"},
{"oauth/requesttokenservice","agamstsauthappgetaccesstoken.aspx"},
{"oauth/queryaccesstoken","agamstsauthappvalidaccesstoken.aspx"},
{"oauth/gam/v2.0/access_token","agamoauth20getaccesstoken_v20.aspx"},
{"oauth/gam/v2.0/userinfo","agamoauth20getuserinfo_v20.aspx"},
{"oauth/gam/v2.0/requesttokenanduserinfo","agamssorequesttokenanduserinfo_v20.aspx"}};
internal static HashSet<string> GamServicesInternalName = new HashSet<string>(GAMServices.Values.Select(value => value.Replace(ASPX, string.Empty)));
internal const string QUERYVIEWER_NAMESPACE = "QueryViewer.Services";
internal const string GXFLOW_NSPACE = "GXflow.Programs";
internal const string GAM_NSPACE = "GeneXus.Security.API";

/*
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
* Specifying no-cache or max-age=0 indicates that
Expand Down
119 changes: 60 additions & 59 deletions dotnet/src/dotnetframework/GxClasses/Middleware/HandlerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,88 +67,89 @@ public IHttpHandler GetHandler(HttpContext context, string requestType, string u

string relativeURL = context.Request.AppRelativeCurrentExecutionFilePath;
string fname = relativeURL.Substring(relativeURL.LastIndexOf('~') + 2);
String cname1 = (fname.Contains(".")) ? fname.Substring(0, fname.LastIndexOf('.')) : fname;
string cname1 = (fname.Contains(".")) ? fname.Substring(0, fname.LastIndexOf('.')) : fname;
string cname0 = cname1.ToLower();
string actualPath = "";

string mainNamespace;
string assemblyName, cname;
string actualPath;
if (cname0 == "gxoauthlogout")
{
return new GeneXus.Http.GXOAuthLogout();
return new GXOAuthLogout();
}
else if (cname0 == "gxoauthuserinfo")
{
return new GeneXus.Http.GXOAuthUserInfo();
return new GXOAuthUserInfo();
}
else if (cname0 == "gxoauthaccesstoken")
{
return new GeneXus.Http.GXOAuthAccessToken();
return new GXOAuthAccessToken();
}
else if (cname0 == "gxmulticall")
{
return new GeneXus.Http.GXMultiCall();
return new GXMultiCall();
}
string assemblyName, cname;
if (GXAPIModule.serviceInPath(pathTranslated, actualPath: out actualPath))
else if (HttpHelper.GamServicesInternalName.Contains(cname0))
{
mainNamespace = HttpHelper.GAM_NSPACE;
}
else
{
string nspace;
Config.GetValueOf("AppMainNamespace", out nspace);
String objClass = GXAPIModule.servicesBase[actualPath];
//
String objectName = GetObjFromPath(cname0, actualPath);
String objectNameUp = GetObjFromPath(cname1, actualPath);
//
Dictionary<string, object> routeParms;
if (GXAPIModule.servicesMapData.ContainsKey(actualPath))
if (!Config.GetValueOf("AppMainNamespace", out mainNamespace))
mainNamespace = "GeneXus.Programs.";

if (GXAPIModule.serviceInPath(pathTranslated, actualPath: out actualPath))
{
bool IsServiceCall = GetSMap(actualPath, objectName, objectNameUp, requestType, out string mapName, out string mapRegExp, out routeParms);
if (IsServiceCall)
string nspace;
Config.GetValueOf("AppMainNamespace", out nspace);
string objClass = GXAPIModule.servicesBase[actualPath];
//
string objectName = GetObjFromPath(cname0, actualPath);
string objectNameUp = GetObjFromPath(cname1, actualPath);
//
Dictionary<string, object> routeParms;
if (GXAPIModule.servicesMapData.ContainsKey(actualPath))
{
if (!String.IsNullOrEmpty(mapName) && GXAPIModule.servicesMap[actualPath].TryGetValue(mapName, out SingleMap value))
bool IsServiceCall = GetSMap(actualPath, objectName, objectNameUp, requestType, out string mapName, out string mapRegExp, out routeParms);
if (IsServiceCall)
{
String tmpController = objClass;
String asssemblycontroller = tmpController;
if (objClass.Contains("\\"))
if (!string.IsNullOrEmpty(mapName) && GXAPIModule.servicesMap[actualPath].TryGetValue(mapName, out SingleMap value))
{
tmpController = objClass.Substring(objClass.LastIndexOf("\\") + 1);
String addNspace = objClass.Substring(0, objClass.LastIndexOf("\\")).Replace("\\", ".");
asssemblycontroller = addNspace + "." + tmpController;
nspace += "." + addNspace;
string tmpController = objClass;
string asssemblycontroller = tmpController;
if (objClass.Contains("\\"))
{
tmpController = objClass.Substring(objClass.LastIndexOf("\\") + 1);
string addNspace = objClass.Substring(0, objClass.LastIndexOf("\\")).Replace("\\", ".");
asssemblycontroller = addNspace + "." + tmpController;
nspace += "." + addNspace;
}
GxContext gxContext = GxContext.CreateDefaultInstance();
object handler = ClassLoader.FindInstance(asssemblycontroller, nspace, tmpController, new Object[] { gxContext }, null);

gxContext.HttpContext = context;
GxRestWrapper restWrapper = new Application.GxRestWrapper(handler as GXBaseObject, context, gxContext, value.ServiceMethod, value.VariableAlias, routeParms);
return restWrapper;
}
GxContext gxContext = GxContext.CreateDefaultInstance();
object handler = ClassLoader.FindInstance(asssemblycontroller, nspace, tmpController, new Object[] { gxContext }, null);

gxContext.HttpContext = context;
GxRestWrapper restWrapper = new Application.GxRestWrapper(handler as GXBaseObject, context, gxContext, value.ServiceMethod, value.VariableAlias, routeParms);
return restWrapper;
}
}
else
{
if (requestType.Equals(HttpMethod.Options.Method) && !String.IsNullOrEmpty(actualPath) && GXAPIModule.servicesMapData.ContainsKey(actualPath))
else
{
return new OptionsApiObjectRequestHandler(actualPath, objectName, mapRegExp);
if (requestType.Equals(HttpMethod.Options.Method) && !string.IsNullOrEmpty(actualPath) && GXAPIModule.servicesMapData.ContainsKey(actualPath))
{
return new OptionsApiObjectRequestHandler(actualPath, objectName, mapRegExp);
}
}
}
}
return null;
}
return null;
}
else
assemblyName = cname0;
cname = cname0;
if (cname.EndsWith("_bc_ws"))
{
{
assemblyName = cname0;
cname = cname0;
}
if (cname.EndsWith("_bc_ws"))
{
cname = cname.Substring(0, cname.Length - 3);
assemblyName = cname;
}
cname = cname.Substring(0, cname.Length - 3);
assemblyName = cname;
}
string mainNamespace, className;
if (Config.GetValueOf("AppMainNamespace", out mainNamespace))
className = mainNamespace + "." + cname;
else
className = "GeneXus.Programs." + cname;
string className = mainNamespace + "." + cname;

Type objType = GetHandlerType(assemblyName, className);
if (objType == null)
Expand Down Expand Up @@ -190,7 +191,7 @@ public IHttpHandler GetHandler(HttpContext context, string requestType, string u
}
else
{
handlerToReturn = (IHttpHandler)System.Web.UI.PageParser.GetCompiledPageInstance(url, pathTranslated, context);
handlerToReturn = System.Web.UI.PageParser.GetCompiledPageInstance(url, pathTranslated, context);
}
return handlerToReturn;
}
Expand All @@ -199,7 +200,7 @@ public string GetObjFromPath(string cname, string apath)
{
if (cname.LastIndexOf("/") == (cname.Length - 1))
cname = cname.Substring(0, cname.Length - 1);
String objectName = cname.Remove(0, apath.Length);
string objectName = cname.Remove(0, apath.Length);
return objectName;
}

Expand Down Expand Up @@ -302,7 +303,7 @@ internal static Type GetHandlerType(string assemblyName, string className)
try
{

objType = GeneXus.Metadata.ClassLoader.FindType(assemblyName, className, null);
objType = ClassLoader.FindType(assemblyName, className, null);
if (objType == null)
objType = Assembly.Load(assemblyName).GetType(className);
}
Expand Down