use of com.genexus.ModelContext in project JavaClasses by genexuslabs.
the class GXWebObjectBase method CheckCmpSecurityAccess.
protected boolean CheckCmpSecurityAccess() {
boolean[] flag = new boolean[] { false };
boolean[] permissionFlag = new boolean[] { false };
String permissionPrefix = IntegratedSecurityPermissionPrefix();
com.genexus.internet.HttpRequest req = ((HttpContext) ModelContext.getModelContext().getHttpContext()).getHttpRequest();
if (req == null)
return false;
String reqUrl = req.getRequestURL();
ModelContext modelContext = ModelContext.getModelContext(getClass());
if (IntegratedSecurityLevel() == SECURITY_LOW || IntegratedSecurityLevel() == SECURITY_GXOBJECT) {
GXSecurityProvider.getInstance().checksession(-2, modelContext, reqUrl, permissionFlag);
}
if (IntegratedSecurityLevel() != SECURITY_LOW && IntegratedSecurityLevel() != SECURITY_GXOBJECT) {
GXSecurityProvider.getInstance().checksessionprm(-2, modelContext, reqUrl, permissionPrefix, flag, permissionFlag);
}
return permissionFlag[0];
}
use of com.genexus.ModelContext in project JavaClasses by genexuslabs.
the class GXWebObjectBase method init.
protected void init(HttpContext httpContext, Class contextClass) {
// @gusbro:06/06/05
// El JDK.15 mantiene un TimeZone default por cada Thread, por lo cual el hack que haciemos
// en la gxutil de setear el timeZone falla en motores de servlets
// Lo que hacemos es setear el default aqui, ademas para ser mas 'prolijos' volvemos al valor
// original al finalizar el request (esto ultimo ya no se hace, porque puede traer problemas)
timeZone = GXTimeZone.getDefaultOriginal();
this.context = new ModelContext(contextClass);
context.setHttpContext(httpContext);
new WebApplicationStartup().init(contextClass, httpContext);
ApplicationContext.getInstance().setPoolConnections(!Namespace.createNamespace(context).isRemoteGXDB());
ui = (UserInformation) GXObjectHelper.getUserInformation(context, -1);
ui.setAutoDisconnect(false);
remoteHandle = ui.getHandle();
initState(context, ui);
}
use of com.genexus.ModelContext in project JavaClasses by genexuslabs.
the class GXMultiCall method gxMultiCall.
@javax.ws.rs.POST
@jakarta.ws.rs.POST
@javax.ws.rs.Consumes({ javax.ws.rs.core.MediaType.APPLICATION_JSON })
@jakarta.ws.rs.Consumes({ jakarta.ws.rs.core.MediaType.APPLICATION_JSON })
@javax.ws.rs.Produces({ javax.ws.rs.core.MediaType.APPLICATION_JSON + ";charset=UTF-8" })
@jakarta.ws.rs.Produces({ jakarta.ws.rs.core.MediaType.APPLICATION_JSON + ";charset=UTF-8" })
public Object gxMultiCall(String jsonStr) throws Exception {
super.init("POST");
String procName = ((HttpContextWeb) context.getHttpContext()).GetNextPar().toLowerCase();
ModelContext modelContext = ModelContext.getModelContext(Application.gxCfg);
String appPackage = modelContext.getNAME_SPACE();
if (!appPackage.equals("")) {
appPackage = appPackage + ".";
}
String restProcName = procName + "_services_rest";
try {
Class myClassRest = Class.forName(appPackage + restProcName);
} catch (ClassNotFoundException cnf) {
builder = Response.notFound();
cleanup();
return builder.build();
}
Class myClass = Class.forName(appPackage + procName);
Method[] methods = myClass.getMethods();
Class[] parameters = null;
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equalsIgnoreCase(METHOD_EXECUTE)) {
parameters = method.getParameterTypes();
}
}
int parmCount;
JSONArray jsonArr = new JSONArray(jsonStr);
UserInformation ui = Application.getConnectionManager().createUserInformation(Namespace.getNamespace(modelContext.getNAME_SPACE()));
int remoteHandle = ui.getHandle();
for (int i = 0; i < jsonArr.length(); i++) {
JSONArray procParms = new JSONArray(jsonArr.getJSONArray(i).toString());
parmCount = procParms.length();
Object[] params = new Object[parmCount];
for (int j = 0; j < parmCount; j++) {
params[j] = GXutil.convertObjectTo(procParms.getString(j), parameters[j]);
}
com.genexus.db.DynamicExecute.dynamicExecute(modelContext, remoteHandle, modelContext.packageClass, appPackage + procName, params);
}
Application.cleanupConnection(remoteHandle);
builder = Response.okWrapped();
builder.type("application/json");
builder.entity("");
cleanup();
return builder.build();
}
use of com.genexus.ModelContext in project JavaClasses by genexuslabs.
the class GXOAuthAccessToken method doExecute.
protected void doExecute(HttpContext context) throws Exception {
new WebApplicationStartup().init(Application.gxCfg, context);
context.setStream();
try {
boolean isRefreshToken = false;
boolean isDevice = false;
boolean isExternalSDAuth = false;
String clientId = context.getHttpRequest().getVariable("client_id");
String clientSecret = context.getHttpRequest().getVariable("client_secret");
String grantType = context.getHttpRequest().getVariable("grant_type");
String nativeToken = context.getHttpRequest().getVariable("native_token");
String nativeVerifier = context.getHttpRequest().getVariable("native_verifier");
String avoid_redirect = context.getHttpRequest().getVariable("avoid_redirect");
String refreshToken = "";
String userName = "";
String userPassword = "";
String additional_parameters = "";
String scope = "";
if (grantType.equalsIgnoreCase("refresh_token")) {
refreshToken = context.getHttpRequest().getVariable("refresh_token");
isRefreshToken = true;
} else {
if (grantType.equalsIgnoreCase("device")) {
isDevice = true;
} else {
if (!nativeToken.equals("")) {
isExternalSDAuth = true;
additional_parameters = context.getHttpRequest().getVariable("additional_parameters");
} else {
userName = context.getHttpRequest().getVariable("username");
userPassword = context.getHttpRequest().getVariable("password");
scope = context.getHttpRequest().getVariable("scope");
additional_parameters = context.getHttpRequest().getVariable("additional_parameters");
}
}
}
OutData gamout = new OutData();
GXResult result;
String[] redirectURL = new String[] { "" };
boolean[] flag = new boolean[] { false };
String[] scopeInOut = new String[] { scope };
ModelContext modelContext = new ModelContext(Application.gxCfg);
modelContext.setHttpContext(context);
ModelContext.getModelContext().setHttpContext(context);
if (isRefreshToken) {
result = GXSecurityProvider.getInstance().refreshtoken(-2, modelContext, clientId, clientSecret, refreshToken, gamout, flag);
} else {
if (isDevice) {
result = GXSecurityProvider.getInstance().logindevice(-2, modelContext, clientId, clientSecret, gamout, flag);
} else {
if (isExternalSDAuth) {
result = GXSecurityProvider.getInstance().externalauthenticationfromsdusingtoken(-2, modelContext, grantType, nativeToken, nativeVerifier, clientId, clientSecret, scopeInOut, additional_parameters, gamout, flag);
} else {
if (additional_parameters.equals("")) {
result = GXSecurityProvider.getInstance().oauthauthentication(-2, modelContext, grantType, userName, userPassword, clientId, clientSecret, scope, gamout, redirectURL, flag);
} else {
result = GXSecurityProvider.getInstance().oauthauthentication(-2, modelContext, grantType, userName, userPassword, clientId, clientSecret, scope, additional_parameters, gamout, redirectURL, flag);
}
}
}
}
if (!flag[0]) {
context.getResponse().setContentType("application/json");
String gamError = result.getCode();
if (gamError.equals("400") || gamError.equals("410")) {
context.getResponse().setStatus(202);
} else {
context.getResponse().setStatus(401);
}
String messagePermission = result.getDescription();
String messagePermissionEncoded = messagePermission;
if (PrivateUtilities.containsNoAsciiCharacter(messagePermission)) {
messagePermissionEncoded = PrivateUtilities.encodeURL(messagePermission);
messagePermissionEncoded = "Encoded:" + messagePermissionEncoded;
}
String OauthRealm = "OAuth realm=\"" + context.getRequest().getServerName() + "\"" + ",error_code=\"" + gamError + "\"" + ",error_description=\"" + messagePermissionEncoded + "\"";
context.getResponse().addHeader("WWW-Authenticate", OauthRealm);
SetError(gamError, messagePermission);
context.writeText(errorJson.toString());
context.getResponse().flushBuffer();
return;
} else {
if (!isDevice && !isRefreshToken && ((String) gamout.get("gxTpr_Access_token")).equals("")) {
context.getResponse().setContentType("application/json");
if (avoid_redirect != null && !avoid_redirect.equals(""))
context.getResponse().setStatus(200);
else
context.getResponse().setStatus(303);
context.getResponse().addHeader("location", redirectURL[0]);
JSONObject jObj = new JSONObject();
jObj.put("Location", redirectURL[0]);
context.writeText(jObj.toString());
context.getResponse().flushBuffer();
return;
} else {
context.getResponse().setContentType("application/json");
context.getResponse().setStatus(200);
context.writeText((String) gamout.getjsonString());
context.getResponse().flushBuffer();
return;
}
}
} catch (Throwable e) {
e.printStackTrace();
context.sendResponseStatus(404, e.getMessage());
}
}
use of com.genexus.ModelContext in project JavaClasses by genexuslabs.
the class WebWrapper method setSource.
public void setSource(GXWebPanel panel) {
this.panel = panel;
ModelContext context = panel.getModelContext();
HttpRequest httpReq = ((HttpContext) context.getHttpContext()).getHttpRequest();
IHttpServletRequest httpSerReq = ((HttpContext) context.getHttpContext()).getRequest();
context.setHttpContext(new HttpContextNull());
((HttpContext) context.getHttpContext()).setHttpRequest(httpReq);
((HttpContext) context.getHttpContext()).setRequest(httpSerReq);
((HttpContext) context.getHttpContext()).setContext(context);
panel.setHttpContext(((HttpContext) context.getHttpContext()));
panel.getHttpContext().setCompression(false);
panel.getHttpContext().setBuffered(false);
panel.getHttpContext().useUtf8 = true;
panel.getHttpContext().setOutputStream(new java.io.ByteArrayOutputStream());
}
Aggregations