Search in sources :

Example 36 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class OpenOLATStatisticsWebService method getUserStatisticsVO.

private UserStatisticsVO getUserStatisticsVO() {
    UserStatisticsVO stats = new UserStatisticsVO();
    BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    // activeUserCount="88" // registered and activated identities, same as in GUI
    long countActiveUsers = securityManager.countIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, null, null, Constants.USERSTATUS_ACTIVE);
    stats.setActiveUserCount(countActiveUsers);
    // active last day
    Calendar lastDay = Calendar.getInstance();
    lastDay.add(Calendar.DATE, -1);
    long activeUserCountDay = securityManager.countUniqueUserLoginsSince(lastDay.getTime());
    stats.setActiveUserCountLastDay(activeUserCountDay);
    // active last week
    Calendar lastWeek = Calendar.getInstance();
    lastWeek.add(Calendar.DATE, -7);
    long activeUserCountWeek = securityManager.countUniqueUserLoginsSince(lastWeek.getTime());
    stats.setActiveUserCountLastWeek(activeUserCountWeek);
    // active last month
    Calendar lastMonth = Calendar.getInstance();
    lastMonth.add(Calendar.MONTH, -1);
    long activeUserCountMonth = securityManager.countUniqueUserLoginsSince(lastMonth.getTime());
    stats.setActiveUserCountLastMonth(activeUserCountMonth);
    // active last 6 month
    Calendar last6Month = Calendar.getInstance();
    last6Month.add(Calendar.MONTH, -6);
    long activeUserCount6Month = securityManager.countUniqueUserLoginsSince(last6Month.getTime());
    stats.setActiveUserCountLast6Month(activeUserCount6Month);
    // externalUserCount="12" // EP invite identities, later maybe also used in courses for MOOCS, external experts etc)
    long invitationsCount = CoreSpringFactory.getImpl(InvitationDAO.class).countInvitations();
    stats.setExternalUserCount(invitationsCount);
    // blockedUserCount="0" // identities in login blocked state
    long blockedUserCount = securityManager.countIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, Identity.STATUS_LOGIN_DENIED);
    stats.setBlockedUserCount(blockedUserCount);
    // deletedUserCount="943" // deleted identities
    long deletedUserCount = securityManager.countIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, Identity.STATUS_DELETED);
    stats.setDeletedUserCount(deletedUserCount);
    // totalUserCount="1043" // Sum of all above
    long countUsers = securityManager.countIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, null, null, null);
    stats.setTotalUserCount(countUsers);
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    long countGroups = bgs.countBusinessGroups(null, null);
    stats.setTotalGroupCount(countGroups);
    return stats;
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) Calendar(java.util.Calendar) InvitationDAO(org.olat.portfolio.manager.InvitationDAO) UserStatisticsVO(org.olat.restapi.system.vo.UserStatisticsVO) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 37 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class IdentityIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    int counter = 0;
    BaseSecurity secMgr = BaseSecurityManager.getInstance();
    List<Long> identityKeys = secMgr.loadVisibleIdentityKeys();
    if (isLogDebugEnabled())
        logDebug("Found " + identityKeys.size() + " active identities to index");
    DBFactory.getInstance().commitAndCloseSession();
    for (Long identityKey : identityKeys) {
        try {
            // reload the identity here before indexing it to make sure it has not been deleted in the meantime
            Identity identity = secMgr.loadIdentityByKey(identityKey);
            if (identity == null || (identity.getStatus() >= Identity.STATUS_VISIBLE_LIMIT)) {
                logInfo("doIndex: identity was deleted while we were indexing. The deleted identity was: " + identity);
                continue;
            }
            if (isLogDebugEnabled())
                logDebug("Indexing identity::" + identity.getName() + " and counter::" + counter);
            // Create a search context for this identity. The search context will open the users visiting card in a new tab
            SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
            searchResourceContext.setBusinessControlFor(OresHelper.createOLATResourceableInstance(Identity.class, identity.getKey()));
            searchResourceContext.setParentContextType(TYPE);
            // delegate indexing work to all configured indexers
            for (Indexer indexer : getChildIndexers()) {
                indexer.doIndex(searchResourceContext, identity, indexWriter);
            }
            counter++;
        } catch (Exception ex) {
            logWarn("Exception while indexing identity::" + identityKey + ". Skipping this user, try next one.", ex);
            DBFactory.getInstance().rollbackAndCloseSession();
        }
        DBFactory.getInstance().commitAndCloseSession();
    }
    if (isLogDebugEnabled())
        logDebug("IdentityIndexer finished with counter::" + counter);
}
Also used : OlatFullIndexer(org.olat.search.service.indexer.OlatFullIndexer) Indexer(org.olat.search.service.indexer.Indexer) AbstractHierarchicalIndexer(org.olat.search.service.indexer.AbstractHierarchicalIndexer) SearchResourceContext(org.olat.search.service.SearchResourceContext) Identity(org.olat.core.id.Identity) IOException(java.io.IOException) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 38 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class PreferencesFormController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("title.prefs");
    setFormContextHelp("Configuration#_einstellungen");
    // load preferences
    Preferences prefs = tobeChangedIdentity.getUser().getPreferences();
    // Username
    StaticTextElement username = uifactory.addStaticTextElement("form.username", tobeChangedIdentity.getName(), formLayout);
    username.setElementCssClass("o_sel_home_settings_username");
    username.setEnabled(false);
    // Roles
    final String[] roleKeys = new String[] { Constants.GROUP_USERMANAGERS, Constants.GROUP_GROUPMANAGERS, Constants.GROUP_POOL_MANAGER, Constants.GROUP_AUTHORS, Constants.GROUP_INST_ORES_MANAGER, Constants.GROUP_ADMIN };
    String iname = getIdentity().getUser().getProperty("institutionalName", null);
    String ilabel = iname != null ? translate("rightsForm.isInstitutionalResourceManager.institution", iname) : translate("rightsForm.isInstitutionalResourceManager");
    final String[] roleValues = new String[] { translate("rightsForm.isUsermanager"), translate("rightsForm.isGroupmanager"), translate("rightsForm.isPoolmanager"), translate("rightsForm.isAuthor"), ilabel, translate("rightsForm.isAdmin") };
    final BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    String userRoles = "";
    List<String> roles = securityManager.getRolesAsString(tobeChangedIdentity);
    for (String role : roles) {
        for (int i = 0; i < roleKeys.length; i++) {
            if (roleKeys[i].equals(role)) {
                userRoles = userRoles + roleValues[i] + ", ";
            }
        }
    }
    if (userRoles.equals("")) {
        userRoles = translate("rightsForm.isAnonymous.false");
    } else {
        userRoles = userRoles.substring(0, userRoles.lastIndexOf(","));
    }
    uifactory.addStaticTextElement("rightsForm.roles", userRoles, formLayout);
    username.setElementCssClass("o_sel_home_settings_username");
    username.setEnabled(false);
    // Language
    Map<String, String> languages = I18nManager.getInstance().getEnabledLanguagesTranslated();
    String[] langKeys = StringHelper.getMapKeysAsStringArray(languages);
    String[] langValues = StringHelper.getMapValuesAsStringArray(languages);
    ArrayHelper.sort(langKeys, langValues, false, true, false);
    language = uifactory.addDropdownSingleselect("form.language", formLayout, langKeys, langValues, null);
    language.setElementCssClass("o_sel_home_settings_language");
    String langKey = prefs.getLanguage();
    // this server
    if (prefs.getLanguage() != null && i18nModule.getEnabledLanguageKeys().contains(langKey)) {
        language.select(prefs.getLanguage(), true);
    } else {
        language.select(I18nModule.getDefaultLocale().toString(), true);
    }
    // Font size
    String[] cssFontsizeValues = new String[] { translate("form.fontsize.xsmall"), translate("form.fontsize.small"), translate("form.fontsize.normal"), translate("form.fontsize.large"), translate("form.fontsize.xlarge"), translate("form.fontsize.presentation") };
    fontsize = uifactory.addDropdownSingleselect("form.fontsize", formLayout, cssFontsizeKeys, cssFontsizeValues, null);
    fontsize.setElementCssClass("o_sel_home_settings_fontsize");
    fontsize.select(prefs.getFontsize(), true);
    fontsize.addActionListener(FormEvent.ONCHANGE);
    // Email notification interval
    NotificationsManager nMgr = NotificationsManager.getInstance();
    List<String> intervals = nMgr.getEnabledNotificationIntervals();
    if (intervals.size() > 0) {
        String[] intervalKeys = new String[intervals.size()];
        intervals.toArray(intervalKeys);
        String[] intervalValues = new String[intervalKeys.length];
        String i18nPrefix = "interval.";
        for (int i = 0; i < intervalKeys.length; i++) {
            intervalValues[i] = translate(i18nPrefix + intervalKeys[i]);
        }
        notificationInterval = uifactory.addDropdownSingleselect("form.notification", formLayout, intervalKeys, intervalValues, null);
        notificationInterval.setElementCssClass("o_sel_home_settings_notification_interval");
        notificationInterval.select(prefs.getNotificationInterval(), true);
    }
    // fxdiff VCRP-16: intern mail system
    MailModule mailModule = (MailModule) CoreSpringFactory.getBean("mailModule");
    if (mailModule.isInternSystem()) {
        String userEmail = UserManager.getInstance().getUserDisplayEmail(tobeChangedIdentity, ureq.getLocale());
        String[] mailInternLabels = new String[] { translate("mail." + mailIntern[0], userEmail), translate("mail." + mailIntern[1], userEmail) };
        mailSystem = uifactory.addRadiosVertical("mail-system", "mail.system", formLayout, mailIntern, mailInternLabels);
        mailSystem.setElementCssClass("o_sel_home_settings_mail");
        String mailPrefs = prefs.getReceiveRealMail();
        if (StringHelper.containsNonWhitespace(mailPrefs)) {
            if ("true".equals(mailPrefs)) {
                mailSystem.select(mailIntern[1], true);
            } else {
                mailSystem.select(mailIntern[0], true);
            }
        } else if (mailModule.isReceiveRealMailUserDefaultSetting()) {
            mailSystem.select(mailIntern[1], true);
        } else {
            mailSystem.select(mailIntern[0], true);
        }
    }
    // Text encoding
    Map<String, Charset> charsets = Charset.availableCharsets();
    String currentCharset = UserManager.getInstance().getUserCharset(tobeChangedIdentity);
    String[] csKeys = StringHelper.getMapKeysAsStringArray(charsets);
    charset = uifactory.addDropdownSingleselect("form.charset", formLayout, csKeys, csKeys, null);
    charset.setElementCssClass("o_sel_home_settings_charset");
    if (currentCharset != null) {
        for (String csKey : csKeys) {
            if (csKey.equals(currentCharset)) {
                charset.select(currentCharset, true);
            }
        }
    }
    if (!charset.isOneSelected() && charsets.containsKey("UTF-8")) {
        charset.select("UTF-8", true);
    }
    // Submit and cancel buttons
    final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);
    buttonLayout.setElementCssClass("o_sel_home_settings_prefs_buttons");
    uifactory.addFormSubmitButton("submit", buttonLayout);
    uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
Also used : Charset(java.nio.charset.Charset) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) BaseSecurity(org.olat.basesecurity.BaseSecurity) MailModule(org.olat.core.util.mail.MailModule) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) Preferences(org.olat.core.id.Preferences)

Example 39 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class PreferencesFormController method formOK.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest)
 */
protected void formOK(UserRequest ureq) {
    UserManager um = UserManager.getInstance();
    BaseSecurity secMgr = BaseSecurityManager.getInstance();
    // Refresh user from DB to prevent stale object issues
    tobeChangedIdentity = secMgr.loadIdentityByKey(tobeChangedIdentity.getKey());
    Preferences prefs = tobeChangedIdentity.getUser().getPreferences();
    prefs.setLanguage(language.getSelectedKey());
    prefs.setFontsize(fontsize.getSelectedKey());
    if (notificationInterval != null) {
        // only read notification interval if available, could be disabled by configuration
        prefs.setNotificationInterval(notificationInterval.getSelectedKey());
    }
    // Maybe the user changed the font size
    if (ureq.getIdentity().equalsByPersistableKey(tobeChangedIdentity)) {
        int fontSize = Integer.parseInt(fontsize.getSelectedKey());
        WindowManager wm = getWindowControl().getWindowBackOffice().getWindowManager();
        if (fontSize != wm.getFontSize()) {
            getWindowControl().getWindowBackOffice().getWindow().setDirty(true);
        }
    }
    if (mailSystem != null && mailSystem.isOneSelected()) {
        String val = mailSystem.isSelected(1) ? "true" : "false";
        prefs.setReceiveRealMail(val);
    }
    if (um.updateUserFromIdentity(tobeChangedIdentity)) {
        // Language change needs logout / login
        showInfo("preferences.successful");
    } else {
        showInfo("preferences.unsuccessful");
    }
    um.setUserCharset(tobeChangedIdentity, charset.getSelectedKey());
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : Preferences(org.olat.core.id.Preferences) BaseSecurity(org.olat.basesecurity.BaseSecurity) WindowManager(org.olat.core.gui.WindowManager)

Example 40 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class UsersSubscriptionManagerImpl method getNewIdentityCreated.

/**
 * The search in the ManagerFactory is date based and not timestamp based.
 * The guest are also removed from the list.
 */
@Override
public List<Identity> getNewIdentityCreated(Date from) {
    if (from == null)
        return Collections.emptyList();
    BaseSecurity manager = BaseSecurityManager.getInstance();
    PermissionOnResourceable[] permissions = { new PermissionOnResourceable(Constants.PERMISSION_HASROLE, Constants.ORESOURCE_GUESTONLY) };
    List<Identity> guests = manager.getIdentitiesByPowerSearch(null, null, true, null, permissions, null, from, null, null, null, Identity.STATUS_VISIBLE_LIMIT);
    List<Identity> identities = manager.getIdentitiesByPowerSearch(null, null, true, null, null, null, from, null, null, null, Identity.STATUS_VISIBLE_LIMIT);
    if (!identities.isEmpty() && !guests.isEmpty()) {
        identities.removeAll(guests);
    }
    for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
        Identity identity = identityIt.next();
        if (identity.getCreationDate().before(from)) {
            identityIt.remove();
        }
    }
    return identities;
}
Also used : Identity(org.olat.core.id.Identity) PermissionOnResourceable(org.olat.basesecurity.PermissionOnResourceable) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Aggregations

BaseSecurity (org.olat.basesecurity.BaseSecurity)116 Identity (org.olat.core.id.Identity)88 Path (javax.ws.rs.Path)48 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)28 PUT (javax.ws.rs.PUT)24 Produces (javax.ws.rs.Produces)22 SecurityGroup (org.olat.basesecurity.SecurityGroup)20 RepositoryEntry (org.olat.repository.RepositoryEntry)20 DELETE (javax.ws.rs.DELETE)14 Authentication (org.olat.basesecurity.Authentication)14 MailPackage (org.olat.core.util.mail.MailPackage)14 RepositoryManager (org.olat.repository.RepositoryManager)14 Consumes (javax.ws.rs.Consumes)12 WebApplicationException (javax.ws.rs.WebApplicationException)12 CertificatesManager (org.olat.course.certificate.CertificatesManager)10 OLATResource (org.olat.resource.OLATResource)10 OLATResourceManager (org.olat.resource.OLATResourceManager)10 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)8