Skip to content

Commit

Permalink
Add properties for permission prefixes on BC (#533)
Browse files Browse the repository at this point in the history
* Add properties for permission prefixes on BC

* Minor fix replace "" by String.Empty.
  • Loading branch information
claudiamurialdo authored Feb 1, 2022
1 parent 9af7c4c commit 1c2a57f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override Task Post()
{
try
{
if (!IsAuthenticated())
if (!IsAuthenticated(Worker.IntegratedSecurityLevel2, Worker.IntegratedSecurityEnabled2, Worker.ServiceInsertPermissionPrefix))
{
return Task.CompletedTask;
}
Expand Down Expand Up @@ -101,7 +101,7 @@ public override Task Get(object parameters)
{
try
{
if (!IsAuthenticated())
if (!IsAuthenticated(Worker.IntegratedSecurityLevel2, Worker.IntegratedSecurityEnabled2, Worker.ServiceExecutePermissionPrefix))
{
return Task.CompletedTask;
}
Expand Down Expand Up @@ -144,7 +144,7 @@ public override Task Delete(object parameters)
{
try
{
if (!IsAuthenticated())
if (!IsAuthenticated(Worker.IntegratedSecurityLevel2, Worker.IntegratedSecurityEnabled2, Worker.ServiceDeletePermissionPrefix))
{
return Task.CompletedTask;
}
Expand Down Expand Up @@ -182,7 +182,7 @@ public override Task Put(object parameters)
{
try
{
if (!IsAuthenticated())
if (!IsAuthenticated(Worker.IntegratedSecurityLevel2, Worker.IntegratedSecurityEnabled2, Worker.ServiceUpdatePermissionPrefix))
{
return Task.CompletedTask;
}
Expand Down
8 changes: 4 additions & 4 deletions dotnet/src/dotnetframework/GxClasses/Helpers/HttpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static HttpStatusCode MapStatusCode(string statusCode)
else
return HttpStatusCode.Unauthorized;
}
private static HttpStatusCode GamCodeToHttpStatus(string code)
private static HttpStatusCode GamCodeToHttpStatus(string code, HttpStatusCode defaultCode=HttpStatusCode.Unauthorized)
{
if (code == GAM_CODE_OTP_USER_ACCESS_CODE_SENT || code == GAM_CODE_TFA_USER_MUST_VALIDATE)
{
Expand All @@ -138,7 +138,7 @@ private static HttpStatusCode GamCodeToHttpStatus(string code)
{
return HttpStatusCode.Forbidden;
}
return HttpStatusCode.Unauthorized;
return defaultCode;
}
private static void SetJsonError(HttpContext httpContext, string statusCode, string statusDescription)
{
Expand All @@ -158,9 +158,9 @@ private static void SetJsonError(HttpContext httpContext, string statusCode, str
}
#endif
}
internal static void SetGamError(HttpContext httpContext, string code, string message)
internal static void SetGamError(HttpContext httpContext, string code, string message, HttpStatusCode defaultCode = HttpStatusCode.Unauthorized)
{
SetResponseStatus(httpContext, GamCodeToHttpStatus(code), message);
SetResponseStatus(httpContext, GamCodeToHttpStatus(code, defaultCode), message);
SetJsonError(httpContext, code, message);
}
internal static void TraceUnexpectedError(Exception ex)
Expand Down
7 changes: 6 additions & 1 deletion dotnet/src/dotnetframework/GxClasses/Model/GXBaseObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ public virtual void cleanup() { }
public bool IsSynchronizer2 { get { return IsSynchronizer; } }
public string ExecutePermissionPrefix2 { get { return ExecutePermissionPrefix; } }

public virtual string ServiceExecutePermissionPrefix { get { return string.Empty; } }
public virtual string ServiceDeletePermissionPrefix { get { return string.Empty; } }
public virtual string ServiceInsertPermissionPrefix { get { return string.Empty; } }
public virtual string ServiceUpdatePermissionPrefix { get { return string.Empty; } }

protected virtual bool IntegratedSecurityEnabled { get { return false; } }
protected virtual GAMSecurityLevel IntegratedSecurityLevel { get { return 0; } }
protected virtual bool IsSynchronizer { get { return false; } }
protected virtual string ExecutePermissionPrefix { get { return ""; } }
protected virtual string ExecutePermissionPrefix { get { return String.Empty; } }

public virtual void CallWebObject(string url)
{
Expand Down
14 changes: 3 additions & 11 deletions dotnet/src/dotnetframework/GxClasses/Services/GxRestWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public bool IsAuthenticated()
{
return IsAuthenticated(Worker.IntegratedSecurityLevel2, Worker.IntegratedSecurityEnabled2, Worker.ExecutePermissionPrefix2);
}
private bool IsAuthenticated(GAMSecurityLevel objIntegratedSecurityLevel, bool objIntegratedSecurityEnabled, string objPermissionPrefix)
protected bool IsAuthenticated(GAMSecurityLevel objIntegratedSecurityLevel, bool objIntegratedSecurityEnabled, string objPermissionPrefix)
{
if (!objIntegratedSecurityEnabled)
{
Expand Down Expand Up @@ -547,16 +547,8 @@ private bool IsAuthenticated(GAMSecurityLevel objIntegratedSecurityLevel, bool o
}
else
{
HttpHelper.SetGamError(_httpContext, result.Code, result.Description);
if (sessionOk)
{
SetStatusCode(HttpStatusCode.Forbidden);
}
else
{
AddHeader(HttpHeader.AUTHENTICATE_HEADER, HttpHelper.OatuhUnauthorizedHeader(_gxContext.GetServerName(), result.Code, result.Description));
SetStatusCode(HttpStatusCode.Unauthorized);
}
HttpStatusCode defaultStatusCode = sessionOk ? HttpStatusCode.Forbidden : HttpStatusCode.Unauthorized;
HttpHelper.SetGamError(_httpContext, result.Code, result.Description, defaultStatusCode);
return false;
}
}
Expand Down

0 comments on commit 1c2a57f

Please sign in to comment.