use of org.olat.core.util.UserSession in project openolat by klemens.
the class AuthHelper method doHeadlessLogin.
/**
* @param identity
* @param authProvider
* @param ureq
* @param Is login via REST API?
* @return
*/
public static int doHeadlessLogin(Identity identity, String authProvider, UserRequest ureq, boolean rest) {
int initializeStatus = initializeLogin(identity, authProvider, ureq, rest);
if (initializeStatus != LOGIN_OK) {
// login not successful
return initializeStatus;
}
// Set session info to reflect the REST headless login
UserSession usess = ureq.getUserSession();
usess.getSessionInfo().setREST(true);
usess.getIdentityEnvironment().getAttributes().put(ATTRIBUTE_IS_REST, "true");
//
ThreadLocalUserActivityLogger.log(OlatLoggingAction.OLAT_LOGIN, AuthHelper.class, LoggingResourceable.wrap(identity));
return LOGIN_OK;
}
use of org.olat.core.util.UserSession in project openolat by klemens.
the class NewControllerFactory method launch.
/**
* Launch a controller in a tab or site in the given window from a user
* request url
*
* @param ureq
* @param wControl
*/
public boolean launch(UserRequest ureq, WindowControl wControl) {
BusinessControl bc = wControl.getBusinessControl();
ContextEntry mainCe = bc.popLauncherContextEntry();
if (mainCe == null) {
// nothing to launch
return false;
}
OLATResourceable ores = mainCe.getOLATResourceable();
// Check for RepositoryEntry resource
RepositoryEntry re = null;
if (ores.getResourceableTypeName().equals(OresHelper.calculateTypeName(RepositoryEntry.class))) {
if (ores instanceof RepositoryEntry) {
re = (RepositoryEntry) ores;
ores = re.getOlatResource();
} else {
// It is a repository-entry => get OLATResourceable from RepositoryEntry
RepositoryManager repom = RepositoryManager.getInstance();
re = repom.lookupRepositoryEntry(ores.getResourceableId());
if (re != null) {
ores = re.getOlatResource();
mainCe.upgradeOLATResourceable(re);
}
}
}
// was brasato:: DTabs dts = wControl.getDTabs();
UserSession usess = ureq.getUserSession();
Window window = Windows.getWindows(usess).getWindow(ureq);
if (window == null) {
log.debug("Found no window for jumpin => take WindowBackOffice", null);
window = wControl.getWindowBackOffice().getWindow();
}
DTabs dts = window.getDTabs();
String firstType = mainCe.getOLATResourceable().getResourceableTypeName();
// String firstTypeId = ClassToId.getInstance().lookup() BusinessGroup
ContextEntryControllerCreator typeHandler = getContextEntryControllerCreator(firstType);
if (typeHandler == null) {
log.warn("Cannot found an handler for context entry: " + mainCe, null);
// simply return and don't throw a red screen
return false;
}
if (!typeHandler.validateContextEntryAndShowError(mainCe, ureq, wControl)) {
// simply return and don't throw a red screen
return false;
}
List<ContextEntry> entries = new ArrayList<ContextEntry>(5);
while (bc.hasContextEntry()) {
entries.add(bc.popLauncherContextEntry());
}
List<ContextEntry> ces = new ArrayList<ContextEntry>(entries.size() + 1);
ces.add(mainCe);
if (entries.size() > 0) {
ces.addAll(entries);
}
TabContext context = typeHandler.getTabContext(ureq, ores, mainCe, entries);
String siteClassName = typeHandler.getSiteClassName(ces, ureq);
// open in existing site
boolean launched = false;
boolean assessmentMode = usess.isInAssessmentModeProcess();
if (siteClassName != null) {
if (!assessmentMode) {
dts.activateStatic(ureq, siteClassName, context.getContext());
launched = true;
}
} else if (!assessmentMode || usess.matchLockResource(ores)) {
// get current tab or create new tab
DTab dt = dts.getDTab(ores);
if (dt == null) {
WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, dts.getWindowControl());
usess.addToHistory(ureq, bc);
Controller launchC = typeHandler.createController(ces, ureq, bwControl);
if (launchC != null) {
dt = dts.createDTab(context.getTabResource(), re, launchC, context.getName());
if (dt == null) {
launched = false;
} else if (dts.addDTab(ureq, dt)) {
dts.activate(ureq, dt, context.getContext());
launched = true;
}
}
} else {
dts.activate(ureq, dt, context.getContext());
launched = true;
}
}
return launched;
}
use of org.olat.core.util.UserSession in project openolat by klemens.
the class SessionStatsManager method getActiveSessions.
public long getActiveSessions(int numOfSeconds) {
long diff = numOfSeconds * 1000;
Collection<UserSession> authUserSessions = sessionManager.getAuthenticatedUserSessions();
long now = System.currentTimeMillis();
long counter = 0;
for (UserSession usess : authUserSessions) {
long lastklick = usess.getSessionInfo() == null ? -1 : usess.getSessionInfo().getLastClickTime();
if ((now - lastklick) <= diff) {
counter++;
}
}
return counter;
}
use of org.olat.core.util.UserSession in project openolat by klemens.
the class UserSessionController method reset.
/**
* Re-initialize this controller. Fetches sessions again.
*/
public void reset() {
Collection<UserSession> authUserSessions = sessionManager.getAuthenticatedUserSessions();
List<UserSessionView> authUserSessionViews = new ArrayList<UserSessionView>(authUserSessions.size());
for (UserSession authUserSession : authUserSessions) {
authUserSessionViews.add(new UserSessionView(authUserSession));
}
usessTableModel = new UserSessionTableModel(authUserSessionViews, getIdentity().getKey());
tableCtr.setTableDataModel(usessTableModel);
}
use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.
the class FolderRunController method enableDisableQuota.
private void enableDisableQuota(UserRequest ureq) {
// prevent a timing condition if the user logout while a thumbnail is generated
UserSession usess = ureq.getUserSession();
if (usess == null || usess.getRoles() == null) {
return;
}
Boolean newEditQuota = Boolean.FALSE;
if (usess.getRoles().isOLATAdmin() || usess.getRoles().isInstitutionalResourceManager()) {
// Only sys admins or institutonal resource managers can have the quota button
Quota q = VFSManager.isTopLevelQuotaContainer(folderComponent.getCurrentContainer());
newEditQuota = (q == null) ? Boolean.FALSE : Boolean.TRUE;
}
Boolean currentEditQuota = (Boolean) folderContainer.contextGet("editQuota");
// not make the component dirty after asynchronous thumbnail loading
if (currentEditQuota == null || !currentEditQuota.equals(newEditQuota)) {
folderContainer.contextPut("editQuota", newEditQuota);
}
}
Aggregations