Skip to content

Commit 2bedf0e

Browse files
authored
Changes into SecurityProvider interface and Logout middleware (#660)
* Changes into SecurityProvider interface and Logout middleware to support SLO in angular. * Keep old signature to avoid breaking interface.
1 parent e1d92dc commit 2bedf0e

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

common/src/main/java/com/genexus/security/NoSecurityProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,10 @@ public void oauthgetuser(int remoteHandle, ModelContext context, String[] userJs
7070
public void oauthlogout(int remoteHandle, ModelContext context)
7171
{
7272
}
73+
74+
public void oauthlogout(int remoteHandle, ModelContext context, String[] URL, short[] statusCode)
75+
{
76+
URL[0] = "";
77+
statusCode[0] = -1;
78+
}
7379
}

common/src/main/java/com/genexus/security/SecurityProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ public interface SecurityProvider
1616
GXResult oauthauthentication(int remoteHandle, ModelContext context, String grantType, String userName, String userPassword, String clientId, String clientSecret, String scope, String additional_parameters, OutData outData, String[] redirectURL, boolean[] flag);
1717
void oauthgetuser(int remoteHandle, ModelContext context, String[] userJson, boolean[] isOK);
1818
void oauthlogout(int remoteHandle, ModelContext context);
19+
void oauthlogout(int remoteHandle, ModelContext context, String[] URL, short[] statusCode);
1920
}

java/src/main/java/com/genexus/webpanels/GXOAuthLogout.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.genexus.ModelContext;
55
import com.genexus.internet.HttpContext;
66
import com.genexus.security.GXSecurityProvider;
7+
import json.org.json.JSONObject;
78

89
public class GXOAuthLogout extends GXWebObjectStub
910
{
@@ -14,15 +15,32 @@ protected void doExecute(HttpContext context) throws Exception
1415
context.setStream();
1516
try
1617
{
18+
String genexus_agent = context.getHeader("Genexus-Agent");
19+
1720
ModelContext modelContext = new ModelContext(Application.gxCfg);
1821
modelContext.setHttpContext(context);
19-
ModelContext.getModelContext().setHttpContext(context);
20-
21-
GXSecurityProvider.getInstance().oauthlogout(-2, modelContext);
22-
22+
ModelContext.getModelContext().setHttpContext(context);
23+
String[] URL = new String[] {""};
24+
short[] statusCode = new short[]{0};
25+
GXSecurityProvider.getInstance().oauthlogout(-2, modelContext, URL, statusCode);
26+
27+
if (statusCode[0] == 303)
28+
context.getResponse().setStatus(200);
29+
else
30+
context.getResponse().setStatus(statusCode[0]);
31+
2332
context.getResponse().setContentType("application/json");
24-
context.getResponse().setStatus(200);
25-
context.writeText("{}");
33+
JSONObject jObj = new JSONObject();
34+
if (genexus_agent.equals("WebFrontend Application") && URL[0].length() > 0)
35+
{
36+
context.getResponse().addHeader("GXLocation", URL[0]);
37+
jObj.put("GXLocation", URL[0]);
38+
}
39+
else
40+
{
41+
jObj.put("code", statusCode[0]);
42+
}
43+
context.writeText(jObj.toString());
2644
context.getResponse().flushBuffer();
2745
return;
2846
}

0 commit comments

Comments
 (0)