use of org.olat.core.util.UserSession in project openolat by klemens.
the class StudentListController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
// add the table
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
if (isAdministrativeUser) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Columns.name, "select"));
}
int colIndex = UserListController.USER_PROPS_OFFSET;
for (int i = 0; i < userPropertyHandlers.size(); i++) {
UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
boolean visible = userManager.isMandatoryUserProperty(UserListController.usageIdentifyer, userPropertyHandler);
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colIndex++, "select", true, userPropertyHandler.i18nColumnDescriptorLabelKey()));
}
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Columns.countCourse));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Columns.initialLaunch, new LightIconRenderer()));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Columns.countPassed, new ProgressRenderer(false, getTranslator())));
model = new StudentsTableDataModel(columnsModel);
tableEl = uifactory.addTableElement(getWindowControl(), "table", model, 20, false, getTranslator(), formLayout);
tableEl.setExportEnabled(true);
tableEl.setEmtpyTableMessageKey("error.no.found");
tableEl.setAndLoadPersistedPreferences(ureq, "fStudentListController");
UserSession usess = ureq.getUserSession();
boolean autoCompleteAllowed = securityModule.isUserAllowedAutoComplete(usess.getRoles());
if (autoCompleteAllowed) {
tableEl.setSearchEnabled(new StudentListProvider(model, userManager), usess);
}
}
use of org.olat.core.util.UserSession in project openolat by klemens.
the class DocumentPoolSiteSecurityCallback method isAllowedToLaunchSite.
/**
* @see com.frentix.olat.coursesite.SiteSecurityCallback#isAllowedToLaunchSite(org.olat.core.gui.UserRequest)
*/
@Override
public boolean isAllowedToLaunchSite(UserRequest ureq) {
UserSession usess = ureq == null ? null : ureq.getUserSession();
if (usess == null)
return false;
Roles roles = usess.getRoles();
if (roles == null || roles.isInvitee() || roles.isGuestOnly()) {
return false;
}
if (roles.isOLATAdmin()) {
return true;
}
String taxonomyKey = docPoolModule.getTaxonomyTreeKey();
if (StringHelper.isLong(taxonomyKey)) {
TaxonomyRef taxonomy = new TaxonomyRefImpl(new Long(taxonomyKey));
return taxonomyService.hasTaxonomyCompetences(taxonomy, ureq.getIdentity(), ureq.getRequestTimestamp());
}
return false;
}
use of org.olat.core.util.UserSession in project openolat by klemens.
the class BaseFullWebappController method initializeBase.
private void initializeBase(UserRequest ureq, WindowManager winman, ComponentCollection mainPanel) {
// component-id of mainPanel for the window id
mainVc.contextPut("o_winid", mainPanel.getDispatchID());
BaseSecurityModule securityModule = CoreSpringFactory.getImpl(BaseSecurityModule.class);
mainVc.contextPut("enforceTopFrame", securityModule.isForceTopFrame());
// add optional css classes
mainVc.contextPut("bodyCssClasses", bodyCssClasses);
Window w = wbo.getWindow();
mainVc.put("jsCssRawHtmlHeader", w.getJsCssRawHtmlHeader());
// control part for ajax-communication. returns an empty panel if ajax
// is not enabled, so that ajax can be turned on on the fly for
// development mode
jsServerC = wbo.createAJAXController(ureq);
mainVc.put("jsServer", jsServerC.getInitialComponent());
// init with no bookmark (=empty bc)
mainVc.contextPut("o_bc", "");
mainVc.contextPut("o_serverUri", Settings.createServerURI());
// the current language; used e.g. by screenreaders
mainVc.contextPut("lang", ureq.getLocale().toString());
// some user properties
if (ureq.getUserSession().isAuthenticated()) {
Identity ident = ureq.getIdentity();
StringBuilder sb = new StringBuilder();
sb.append("{ identity : ").append(ident.getKey());
User user = ident.getUser();
List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(USER_PROPS_ID, ureq.getUserSession().getRoles().isOLATAdmin());
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
String escapedValue = StringHelper.escapeJavaScript(userPropertyHandler.getUserProperty(user, getLocale()));
sb.append(", ").append(userPropertyHandler.getName()).append(" : \"").append(escapedValue).append("\"");
}
sb.append("}");
mainVc.contextPut("userJSON", sb);
}
// the current GUI theme and the global settings that contains the
// font-size. both are pushed as objects so that window.dirty always reads
// out the correct value
mainVc.contextPut("theme", w.getGuiTheme());
mainVc.contextPut("globalSettings", winman.getGlobalSettings());
// also add the optional theme javascript
addThemeJS();
// Add JS analytics code, e.g. for google analytics
if (analyticsModule.isAnalyticsEnabled()) {
AnalyticsSPI analyticsSPI = analyticsModule.getAnalyticsProvider();
mainVc.contextPut("analytics", analyticsSPI.analyticsInitPageJavaScript());
}
// content panel
contentPanel = new Panel("olatContentPanel");
mainVc.put("olatContentPanel", contentPanel);
mainVc.contextPut("o_winid", w.getDispatchID());
mainVc.contextPut("buildversion", Settings.getVersion());
if (wbo.isDebuging()) {
debugC = wbo.createDebugDispatcherController(ureq, getWindowControl());
mainVc.put("guidebug", debugC.getInitialComponent());
}
// Inline translation interceptor. when the translation tool is enabled it
// will start the translation tool in translation mode, if the overlay
// feature is enabled it will start in customizing mode
// fxdiff: allow user-managers to use the inline translation also.
UserSession usess = ureq.getUserSession();
if (usess.isAuthenticated() && (usess.getRoles().isOLATAdmin() || usess.getRoles().isUserManager()) && (i18nModule.isTransToolEnabled() || i18nModule.isOverlayEnabled())) {
inlineTranslationC = wbo.createInlineTranslationDispatcherController(ureq, getWindowControl());
Preferences guiPrefs = usess.getGuiPreferences();
Boolean isInlineTranslationEnabled = (Boolean) guiPrefs.get(I18nModule.class, I18nModule.GUI_PREFS_INLINE_TRANSLATION_ENABLED, Boolean.FALSE);
i18nManager.setMarkLocalizedStringsEnabled(usess, isInlineTranslationEnabled);
mainVc.put("inlineTranslation", inlineTranslationC.getInitialComponent());
}
// debug info if debugging
if (wbo.isDebuging()) {
developmentC = wbo.createDevelopmentController(ureq, getWindowControl());
mainVc.put("development", developmentC.getInitialComponent());
}
// put the global js translator mapper path into the main window
mainVc.contextPut("jsTranslationMapperPath", BaseChiefController.jsTranslationMapperPath);
// master window
// w.addListener(this); // to be able to report "browser reload" to the user
w.setContentPane(mainPanel);
}
use of org.olat.core.util.UserSession in project openolat by klemens.
the class Tracing method assembleThrowableMessage.
private static String assembleThrowableMessage(String category, char prefix, long refNum, Class<?> callingClass, String logMsg, Throwable cause) {
HttpServletRequest ureq = null;
if (tld != null) {
// thread local data is not initialized so far if Tracing is called from
// e.g. a worker thread like in Search or UpdateEfficiency worker
// TODO:pb:check if this was also a problem with IM threads.
ureq = tld.getHttpServletRequest();
}
UserSession usess = null;
Identity identity = null;
String remoteIp = null;
String userAgent = null;
String referer = null;
if (ureq != null) {
usess = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSession(ureq);
identity = usess.getIdentity();
remoteIp = ureq.getRemoteAddr();
userAgent = ureq.getHeader("User-Agent");
referer = ureq.getHeader("Referer");
}
StringBuilder sb = new StringBuilder(2048);
if (!Settings.isDebuging()) {
sb.append(PREFIX);
sb.append(category);
sb.append(SEPARATOR);
try {
// Node-Id + Error number e.g. N1-E17
sb.append("N");
// FIXME:gs remove access to coordinator: gs accessing coordinator here loads the corespring factory. This means we cannot do unit testing without olat
// as the first log call will start the whole OLAT stuff.
sb.append(nodeId);
sb.append("-");
} catch (Throwable th) {
// ok
sb.append(N_A);
}
sb.append(prefix);
sb.append(refNum);
sb.append(SEPARATOR);
sb.append(callingClass == null ? N_A : callingClass.getPackage().getName());
sb.append(SEPARATOR);
sb.append(identity == null ? N_A : identity.getName());
sb.append(SEPARATOR);
sb.append(remoteIp == null ? N_A : remoteIp);
sb.append(SEPARATOR);
sb.append(referer == null ? N_A : referer);
sb.append(SEPARATOR);
sb.append(userAgent == null ? N_A : userAgent);
sb.append(SEPARATOR);
// olat:::::
// for effiency reasons, do not recompile the pattern each time. see javadoc:
// public String replaceAll(String regex, String replacement) {
// return Pattern.compile(regex).matcher(this).replaceAll(replacement);
// }
}
sb.append(logMsg == null ? N_A : logMsg.replaceAll("[\\r\\f]", "").replaceAll("[/^]M", "").replaceAll("[\\r\\n]", ""));
sb.append(SEPARATOR);
if (cause == null) {
sb.append(CAUSE_N_A);
} else {
Throwable ca = cause;
int i = 1;
while (ca != null && i < 10) {
sb.append(STACK_OF);
sb.append(i);
sb.append(CAUSE);
sb.append(ca.getClass().getName());
sb.append(DOUBLEPOINT);
sb.append(ca.getMessage());
sb.append(REFERS_TO);
sb.append(getStackTrace(ca));
i++;
ca = ca.getCause();
}
}
return sb.toString();
}
use of org.olat.core.util.UserSession in project openolat by klemens.
the class Tracing method assembleMsg.
private static String assembleMsg(String category, char prefix, long refNum, Class<?> callingClass, String userObj, String logMsg) {
HttpServletRequest ureq = null;
if (tld != null) {
// thread local data is not initialized so far if Tracing is called from
// e.g. a worker thread like in Search or UpdateEfficiency worker
// TODO:pb:check if this was also a problem with IM threads.
ureq = tld.getHttpServletRequest();
}
UserSession usess = null;
Identity identity = null;
String remoteIp = null;
String userAgent = null;
String referer = null;
if (ureq != null) {
usess = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSessionIfAlreadySet(ureq);
if (usess != null) {
identity = usess.getIdentity();
remoteIp = ureq.getRemoteAddr();
userAgent = ureq.getHeader("User-Agent");
referer = ureq.getHeader("Referer");
}
}
StringBuilder sb = new StringBuilder(256);
if (Settings.isDebuging()) {
// Short version for console output during debugging
if (userObj != null) {
sb.append(userObj).append(" ");
}
} else {
sb.append(PREFIX);
sb.append(category);
sb.append(SEPARATOR);
try {
// Node-Id + Error number e.g. N1-E17
sb.append("N");
sb.append(WebappHelper.getNodeId());
sb.append("-");
} catch (Throwable th) {
// ok
sb.append(N_A);
}
sb.append(prefix);
sb.append(refNum);
sb.append(SEPARATOR);
sb.append(callingClass == null ? N_A : callingClass.getPackage().getName());
sb.append(SEPARATOR);
sb.append(identity == null ? N_A : identity.getName());
sb.append(SEPARATOR);
sb.append(remoteIp == null ? N_A : remoteIp);
sb.append(SEPARATOR);
sb.append(referer == null ? N_A : referer);
sb.append(SEPARATOR);
sb.append(userAgent == null ? N_A : userAgent);
sb.append(SEPARATOR);
sb.append(userObj == null ? N_A : userObj);
sb.append(SEPARATOR);
}
sb.append(logMsg == null ? N_A : logMsg.replaceAll("[\\r\\f]", "").replaceAll("[/^]M", "").replaceAll("[\\r\\n]", ""));
return sb.toString();
}
Aggregations