Skip to content

Commit 1c2a57f

Browse files
Add properties for permission prefixes on BC (#533)
* Add properties for permission prefixes on BC * Minor fix replace "" by String.Empty.
1 parent 9af7c4c commit 1c2a57f

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXBCRestService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public override Task Post()
2929
{
3030
try
3131
{
32-
if (!IsAuthenticated())
32+
if (!IsAuthenticated(Worker.IntegratedSecurityLevel2, Worker.IntegratedSecurityEnabled2, Worker.ServiceInsertPermissionPrefix))
3333
{
3434
return Task.CompletedTask;
3535
}
@@ -101,7 +101,7 @@ public override Task Get(object parameters)
101101
{
102102
try
103103
{
104-
if (!IsAuthenticated())
104+
if (!IsAuthenticated(Worker.IntegratedSecurityLevel2, Worker.IntegratedSecurityEnabled2, Worker.ServiceExecutePermissionPrefix))
105105
{
106106
return Task.CompletedTask;
107107
}
@@ -144,7 +144,7 @@ public override Task Delete(object parameters)
144144
{
145145
try
146146
{
147-
if (!IsAuthenticated())
147+
if (!IsAuthenticated(Worker.IntegratedSecurityLevel2, Worker.IntegratedSecurityEnabled2, Worker.ServiceDeletePermissionPrefix))
148148
{
149149
return Task.CompletedTask;
150150
}
@@ -182,7 +182,7 @@ public override Task Put(object parameters)
182182
{
183183
try
184184
{
185-
if (!IsAuthenticated())
185+
if (!IsAuthenticated(Worker.IntegratedSecurityLevel2, Worker.IntegratedSecurityEnabled2, Worker.ServiceUpdatePermissionPrefix))
186186
{
187187
return Task.CompletedTask;
188188
}

dotnet/src/dotnetframework/GxClasses/Helpers/HttpHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private static HttpStatusCode MapStatusCode(string statusCode)
128128
else
129129
return HttpStatusCode.Unauthorized;
130130
}
131-
private static HttpStatusCode GamCodeToHttpStatus(string code)
131+
private static HttpStatusCode GamCodeToHttpStatus(string code, HttpStatusCode defaultCode=HttpStatusCode.Unauthorized)
132132
{
133133
if (code == GAM_CODE_OTP_USER_ACCESS_CODE_SENT || code == GAM_CODE_TFA_USER_MUST_VALIDATE)
134134
{
@@ -138,7 +138,7 @@ private static HttpStatusCode GamCodeToHttpStatus(string code)
138138
{
139139
return HttpStatusCode.Forbidden;
140140
}
141-
return HttpStatusCode.Unauthorized;
141+
return defaultCode;
142142
}
143143
private static void SetJsonError(HttpContext httpContext, string statusCode, string statusDescription)
144144
{
@@ -158,9 +158,9 @@ private static void SetJsonError(HttpContext httpContext, string statusCode, str
158158
}
159159
#endif
160160
}
161-
internal static void SetGamError(HttpContext httpContext, string code, string message)
161+
internal static void SetGamError(HttpContext httpContext, string code, string message, HttpStatusCode defaultCode = HttpStatusCode.Unauthorized)
162162
{
163-
SetResponseStatus(httpContext, GamCodeToHttpStatus(code), message);
163+
SetResponseStatus(httpContext, GamCodeToHttpStatus(code, defaultCode), message);
164164
SetJsonError(httpContext, code, message);
165165
}
166166
internal static void TraceUnexpectedError(Exception ex)

dotnet/src/dotnetframework/GxClasses/Model/GXBaseObject.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@ public virtual void cleanup() { }
4141
public bool IsSynchronizer2 { get { return IsSynchronizer; } }
4242
public string ExecutePermissionPrefix2 { get { return ExecutePermissionPrefix; } }
4343

44+
public virtual string ServiceExecutePermissionPrefix { get { return string.Empty; } }
45+
public virtual string ServiceDeletePermissionPrefix { get { return string.Empty; } }
46+
public virtual string ServiceInsertPermissionPrefix { get { return string.Empty; } }
47+
public virtual string ServiceUpdatePermissionPrefix { get { return string.Empty; } }
48+
4449
protected virtual bool IntegratedSecurityEnabled { get { return false; } }
4550
protected virtual GAMSecurityLevel IntegratedSecurityLevel { get { return 0; } }
4651
protected virtual bool IsSynchronizer { get { return false; } }
47-
protected virtual string ExecutePermissionPrefix { get { return ""; } }
52+
protected virtual string ExecutePermissionPrefix { get { return String.Empty; } }
4853

4954
public virtual void CallWebObject(string url)
5055
{

dotnet/src/dotnetframework/GxClasses/Services/GxRestWrapper.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ public bool IsAuthenticated()
509509
{
510510
return IsAuthenticated(Worker.IntegratedSecurityLevel2, Worker.IntegratedSecurityEnabled2, Worker.ExecutePermissionPrefix2);
511511
}
512-
private bool IsAuthenticated(GAMSecurityLevel objIntegratedSecurityLevel, bool objIntegratedSecurityEnabled, string objPermissionPrefix)
512+
protected bool IsAuthenticated(GAMSecurityLevel objIntegratedSecurityLevel, bool objIntegratedSecurityEnabled, string objPermissionPrefix)
513513
{
514514
if (!objIntegratedSecurityEnabled)
515515
{
@@ -547,16 +547,8 @@ private bool IsAuthenticated(GAMSecurityLevel objIntegratedSecurityLevel, bool o
547547
}
548548
else
549549
{
550-
HttpHelper.SetGamError(_httpContext, result.Code, result.Description);
551-
if (sessionOk)
552-
{
553-
SetStatusCode(HttpStatusCode.Forbidden);
554-
}
555-
else
556-
{
557-
AddHeader(HttpHeader.AUTHENTICATE_HEADER, HttpHelper.OatuhUnauthorizedHeader(_gxContext.GetServerName(), result.Code, result.Description));
558-
SetStatusCode(HttpStatusCode.Unauthorized);
559-
}
550+
HttpStatusCode defaultStatusCode = sessionOk ? HttpStatusCode.Forbidden : HttpStatusCode.Unauthorized;
551+
HttpHelper.SetGamError(_httpContext, result.Code, result.Description, defaultStatusCode);
560552
return false;
561553
}
562554
}

0 commit comments

Comments
 (0)