use of com.runwaysdk.web.WebClientSession in project geoprism-registry by terraframe.
the class RegistrySessionController method loginWithLocales.
public ClientRequestIF loginWithLocales(ServletRequestIF req, String username, String password, Locale[] locales) {
try {
WebClientSession clientSession = WebClientSession.createUserSession(username, password, locales);
ClientRequestIF clientRequest = clientSession.getRequest();
req.getSession().setMaxInactiveInterval(CommonProperties.getSessionTime());
req.getSession().setAttribute(ClientConstants.CLIENTSESSION, clientSession);
req.setAttribute(ClientConstants.CLIENTREQUEST, clientRequest);
ClientConfigurationService.handleSessionEvent(new SessionEvent(EventType.LOGIN_SUCCESS, clientRequest, username));
return clientRequest;
} catch (RuntimeException e) {
ClientConfigurationService.handleSessionEvent(new SessionEvent(EventType.LOGIN_FAILURE, null, username));
throw e;
}
}
use of com.runwaysdk.web.WebClientSession in project geoprism-registry by terraframe.
the class RegistrySessionController method ologin.
@Endpoint(method = ServletMethod.GET, error = ErrorSerialization.JSON)
public ResponseIF ologin(ServletRequestIF req, @RequestParamter(name = "code", required = true) String code, @RequestParamter(name = "state", required = true) String state) throws MalformedURLException, JSONException {
final SessionController geoprism = new SessionController();
// URL url = new URL(req.getScheme(), req.getServerName(), req.getServerPort(), req.getContextPath());
//
// String redirect = url.toString();
JSONObject stateObject = new JSONObject(state);
String serverId = stateObject.getString(OauthServerIF.SERVER_ID);
Locale[] locales = geoprism.getLocales(req);
WebClientSession clientSession = WebClientSession.createAnonymousSession(locales);
try {
ClientRequestIF clientRequest = clientSession.getRequest();
String cgrSessionJsonString = RegistrySessionServiceDTO.ologin(clientRequest, serverId, code, LocaleSerializer.serialize(locales), null);
JsonObject cgrSessionJson = (JsonObject) JsonParser.parseString(cgrSessionJsonString);
final String sessionId = cgrSessionJson.get("sessionId").getAsString();
final String username = cgrSessionJson.get("username").getAsString();
geoprism.createSession(req, sessionId, locales);
clientRequest = (ClientRequestIF) req.getAttribute(ClientConstants.CLIENTREQUEST);
JsonArray roles = (JsonArray) JsonParser.parseString(RoleViewDTO.getCurrentRoles(clientRequest));
JsonArray roleDisplayLabels = (JsonArray) JsonParser.parseString(RoleViewDTO.getCurrentRoleDisplayLabels(clientRequest));
JsonObject cookieJson = new JsonObject();
cookieJson.addProperty("loggedIn", clientRequest.isLoggedIn());
cookieJson.add("roles", roles);
cookieJson.add("roleDisplayLabels", roleDisplayLabels);
cookieJson.addProperty("userName", username);
cookieJson.addProperty("version", ClientConfigurationService.getServerVersion());
// final Locale sessionLocale = Session.getCurrentLocale();
//
// JsonArray installedLocalesArr = new JsonArray();
// Set<SupportedLocaleIF> installedLocales = LocalizationFacade.getSupportedLocales();
// for (SupportedLocaleIF supportedLocale : installedLocales)
// {
// Locale locale = supportedLocale.getLocale();
//
// JsonObject locObj = new JsonObject();
// locObj.addProperty("language", locale.getDisplayLanguage(sessionLocale));
// locObj.addProperty("country", locale.getDisplayCountry(sessionLocale));
// locObj.addProperty("name", locale.getDisplayName(sessionLocale));
// locObj.addProperty("variant", locale.getDisplayVariant(sessionLocale));
//
// installedLocalesArr.add(locObj);
// }
JsonArray jaLocales = ServiceFactory.getRegistryService().getLocales(clientRequest.getSessionId());
cookieJson.add("installedLocales", jaLocales);
final String cookieValue = URLEncoder.encode(cookieJson.toString(), "UTF-8");
Cookie cookie = new Cookie("user", cookieValue);
cookie.setMaxAge(-1);
RedirectResponse response = new RedirectResponse("/");
response.addCookie(cookie);
return response;
} catch (Throwable t) {
Locale locale = CommonProperties.getDefaultLocale();
if (locales.length > 0) {
locale = locales[0];
}
String errorMessage = RunwayException.localizeThrowable(t, locale);
try {
errorMessage = URLEncoder.encode(errorMessage, StandardCharsets.UTF_8.name());
} catch (Throwable t2) {
throw new ProgrammingErrorException(t2);
}
RedirectResponse response = new RedirectResponse("/cgr/manage#/login/" + errorMessage);
return response;
} finally {
clientSession.logout();
}
}
use of com.runwaysdk.web.WebClientSession in project geoprism-registry by terraframe.
the class NotificationEndpoint method onOpen.
@OnOpen
public void onOpen(Session session, EndpointConfig config) throws IOException {
HttpSession s = (HttpSession) config.getUserProperties().get(HttpSession.class.getName());
WebClientSession clientSession = (WebClientSession) s.getAttribute(ClientConstants.CLIENTSESSION);
this.session = session;
if (!clientSession.getRequest().isPublicUser()) {
this.userId = clientSession.getRequest().getSessionUser().getOid();
}
if (this.userId != null) {
endpoints.add(this);
logger.debug("Connecting websocket for user [" + this.userId + "]");
}
}
Aggregations