Search in sources :

Example 16 with UserSession

use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.

the class PoolPrivateMembersSecurityCallback method isAllowedToLaunchSite.

/**
 * @see com.frentix.olat.coursesite.SiteSecurityCallback#isAllowedToLaunchSite(org.olat.core.gui.UserRequest)
 */
@Override
public boolean isAllowedToLaunchSite(UserRequest ureq) {
    if (!questionPoolModule.isEnabled() || ureq == null || ureq.getIdentity() == null) {
        return false;
    }
    UserSession usess = ureq.getUserSession();
    if (usess == null) {
        return false;
    }
    Roles roles = usess.getRoles();
    if (roles == null || roles.isInvitee() || roles.isGuestOnly()) {
        return false;
    }
    if (roles.isOLATAdmin() || roles.isPoolAdmin()) {
        return true;
    }
    return qPoolService.isMemberOfPrivatePools(ureq.getIdentity());
}
Also used : UserSession(org.olat.core.util.UserSession) Roles(org.olat.core.id.Roles)

Example 17 with UserSession

use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.

the class UserPrefsResetForm method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (resetElements.isAtLeastSelected(1)) {
        // Log out user first if logged in
        boolean logout = false;
        Set<UserSession> sessions = sessionManager.getAuthenticatedUserSessions();
        for (UserSession session : sessions) {
            Identity ident = session.getIdentity();
            if (ident != null && tobeChangedIdentity.equalsByPersistableKey(ident)) {
                sessionManager.signOffAndClear(session);
                logout = true;
                break;
            }
        }
        // Delete gui prefs
        if (resetElements.isSelected(0)) {
            PropertyManager pm = PropertyManager.getInstance();
            pm.deleteProperties(tobeChangedIdentity, null, null, null, "v2guipreferences");
        }
        // Reset preferences
        if (resetElements.isSelected(1)) {
            UserManager um = UserManager.getInstance();
            User user = um.loadUserByKey(tobeChangedIdentity.getUser().getKey());
            org.olat.core.id.Preferences preferences = user.getPreferences();
            preferences.setFontsize(null);
            preferences.setNotificationInterval(null);
            preferences.setPresenceMessagesPublic(false);
            preferences.setReceiveRealMail(null);
            um.updateUser(user);
            PropertyManager pm = PropertyManager.getInstance();
            pm.deleteProperties(tobeChangedIdentity, null, null, null, "charset");
        }
        // Reset history
        if (resetElements.isSelected(2)) {
            HistoryManager.getInstance().deleteHistory(tobeChangedIdentity);
        }
        // reset form buttons
        resetElements.uncheckAll();
        if (logout) {
            // if logout, need a redirect to the login page
            String lang = i18nModule.getLocaleKey(ureq.getLocale());
            ureq.getDispatchResult().setResultingMediaResource(new RedirectMediaResource(WebappHelper.getServletContextPath() + "/dmz/?lang=" + lang + "&logout=true"));
        }
    }
}
Also used : User(org.olat.core.id.User) PropertyManager(org.olat.properties.PropertyManager) UserSession(org.olat.core.util.UserSession) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) Identity(org.olat.core.id.Identity)

Example 18 with UserSession

use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.

the class NewBGController method event.

/* (non-Javadoc)
	 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
	 */
@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == groupCreateController) {
        if (event == Event.DONE_EVENT) {
            String bgDesc = groupCreateController.getGroupDescription();
            Integer bgMax = groupCreateController.getGroupMax();
            Integer bgMin = groupCreateController.getGroupMin();
            boolean enableWaitingList = groupCreateController.isWaitingListEnabled();
            boolean enableAutoCloseRanks = groupCreateController.isAutoCloseRanksEnabled();
            UserSession usess = ureq.getUserSession();
            Object wildcard = usess.removeEntry("wild_card_new");
            newGroups = new ArrayList<BusinessGroup>();
            if (bulkMode) {
                for (String bgName : groupCreateController.getGroupNames()) {
                    BusinessGroup group = businessGroupService.createBusinessGroup(getIdentity(), bgName, bgDesc, bgMin, bgMax, enableWaitingList, enableAutoCloseRanks, re);
                    newGroups.add(group);
                }
            } else {
                String bgName = groupCreateController.getGroupName();
                BusinessGroup group = businessGroupService.createBusinessGroup(getIdentity(), bgName, bgDesc, bgMin, bgMax, enableWaitingList, enableAutoCloseRanks, re);
                newGroups.add(group);
                if (wildcard != null && Boolean.TRUE.equals(wildcard)) {
                    usess.putEntry("wild_card_" + group.getKey(), Boolean.TRUE);
                }
            }
            if (newGroups != null) {
                for (BusinessGroup bg : newGroups) {
                    LoggingResourceable resourceInfo = LoggingResourceable.wrap(bg);
                    ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_CREATED, getClass(), resourceInfo);
                }
                // workflow successfully finished
                // so far no events on the systembus to inform about new groups in BGContext
                fireEvent(ureq, Event.DONE_EVENT);
            }
        } else if (event == Event.CANCELLED_EVENT) {
            // workflow cancelled
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) UserSession(org.olat.core.util.UserSession) LoggingResourceable(org.olat.util.logging.activity.LoggingResourceable)

Example 19 with UserSession

use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.

the class WebDAVManagerTest method handleBasicAuthentication.

@Test
public void handleBasicAuthentication() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("dav-user-" + UUID.randomUUID().toString());
    String credentialsClearText = id.getName() + ":" + JunitTestHelper.PWD;
    String credentials = StringHelper.encodeBase64(credentialsClearText);
    HttpServletRequest request = new MockHttpServletRequest();
    UserSession usess = webDAVManager.handleBasicAuthentication(credentials, request);
    Assert.assertNotNull(usess);
    dbInstance.commit();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UserSession(org.olat.core.util.UserSession) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 20 with UserSession

use of org.olat.core.util.UserSession in project openolat by klemens.

the class AuthHelper method doLogout.

/**
 * This is a convenience method to log out. IMPORTANT: This method initiates a
 * redirect and RETURN. Make sure you return the call hierarchy gracefully.
 * Most of all, don't touch HttpServletRequest or the Session after you call
 * this method.
 *
 * @param ureq
 */
public static void doLogout(UserRequest ureq) {
    if (ureq == null)
        return;
    boolean wasGuest = false;
    UserSession usess = ureq.getUserSession();
    if (usess != null && usess.getRoles() != null) {
        wasGuest = usess.getRoles().isGuestOnly();
    }
    String lang = CoreSpringFactory.getImpl(I18nModule.class).getLocaleKey(ureq.getLocale());
    HttpSession session = ureq.getHttpReq().getSession(false);
    // stuff on logout
    if (session != null) {
        try {
            session.invalidate();
            deleteShibsessionCookie(ureq);
        } catch (IllegalStateException ise) {
        // thrown when session already invalidated. fine. ignore.
        }
    }
    // redirect to logout page in dmz realm, set info that DMZ is shown because of logout
    // if it was a guest user, do not set logout=true. The parameter must be evaluated
    // by the implementation of the AuthenticationProvider.
    String setWarning = wasGuest ? "" : "&logout=true";
    ureq.getDispatchResult().setResultingMediaResource(new RedirectMediaResource(WebappHelper.getServletContextPath() + "/dmz/?lang=" + lang + setWarning));
}
Also used : I18nModule(org.olat.core.util.i18n.I18nModule) HttpSession(javax.servlet.http.HttpSession) UserSession(org.olat.core.util.UserSession) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource)

Aggregations

UserSession (org.olat.core.util.UserSession)146 UserSessionManager (org.olat.core.util.session.UserSessionManager)26 Identity (org.olat.core.id.Identity)22 Roles (org.olat.core.id.Roles)20 SessionInfo (org.olat.core.util.SessionInfo)20 HttpSession (javax.servlet.http.HttpSession)18 UserRequest (org.olat.core.gui.UserRequest)18 Test (org.junit.Test)16 MapperKey (org.olat.core.dispatcher.mapper.manager.MapperKey)16 UserRequestImpl (org.olat.core.gui.UserRequestImpl)16 ContextEntry (org.olat.core.id.context.ContextEntry)14 IOException (java.io.IOException)12 AssertException (org.olat.core.logging.AssertException)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 Window (org.olat.core.gui.components.Window)10 UnknownHostException (java.net.UnknownHostException)8 ArrayList (java.util.ArrayList)8 ChiefController (org.olat.core.gui.control.ChiefController)8 Preferences (org.olat.core.util.prefs.Preferences)8 InetAddress (java.net.InetAddress)6