Search in sources :

Example 1 with PermissionOnResourceable

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

the class UsermanagerUserSearchForm method findIdentitiesFromSearchForm.

/**
 * @return List of identities that match the criterias from the search form
 */
private List<Identity> findIdentitiesFromSearchForm() {
    // get user attributes from form
    String login = searchform.getStringValue("login");
    // when searching for deleted users, add wildcard to match with backup prefix
    if (searchform.getStatus().equals(Identity.STATUS_DELETED)) {
        login = "*" + login;
    }
    Integer status = null;
    // get user fields from form
    // build user fields search map
    Map<String, String> userPropertiesSearch = new HashMap<String, String>();
    for (UserPropertyHandler userPropertyHandler : searchform.getPropertyHandlers()) {
        if (userPropertyHandler == null)
            continue;
        FormItem ui = searchform.getItem(userPropertyHandler.getName());
        String uiValue = userPropertyHandler.getStringValue(ui);
        if (userPropertyHandler.getName().startsWith("genericCheckboxProperty") && ui instanceof MultipleSelectionElement) {
            if (!"false".equals(uiValue)) {
                // ignore false for the search
                userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
            }
        } else if (StringHelper.containsNonWhitespace(uiValue)) {
            // when searching for deleted users, add wildcard to match with backup prefix
            if (userPropertyHandler instanceof EmailProperty && searchform.getStatus().equals(Identity.STATUS_DELETED)) {
                uiValue = "*" + uiValue;
            }
            userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
        }
    }
    if (userPropertiesSearch.isEmpty())
        userPropertiesSearch = null;
    // get group memberships from form
    List<SecurityGroup> groupsList = new ArrayList<SecurityGroup>();
    if (searchform.getRole("admin")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_ADMIN);
        groupsList.add(group);
    }
    if (searchform.getRole("author")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
        groupsList.add(group);
    }
    if (searchform.getRole("groupmanager")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_GROUPMANAGERS);
        groupsList.add(group);
    }
    if (searchform.getRole("usermanager")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_USERMANAGERS);
        groupsList.add(group);
    }
    if (searchform.getRole("oresmanager")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_INST_ORES_MANAGER);
        groupsList.add(group);
    }
    if (searchform.getRole("poolmanager")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_POOL_MANAGER);
        groupsList.add(group);
    }
    status = searchform.getStatus();
    SecurityGroup[] groups = groupsList.toArray(new SecurityGroup[groupsList.size()]);
    // no permissions in this form so far
    PermissionOnResourceable[] permissionOnResources = null;
    String[] authProviders = searchform.getAuthProviders();
    // get date constraints from form
    Date createdBefore = searchform.getBeforeDate();
    Date createdAfter = searchform.getAfterDate();
    Date userLoginBefore = searchform.getUserLoginBefore();
    Date userLoginAfter = searchform.getUserLoginAfter();
    // now perform power search
    List<Identity> myIdentities = securityManager.getIdentitiesByPowerSearch((login.equals("") ? null : login), userPropertiesSearch, true, groups, permissionOnResources, authProviders, createdAfter, createdBefore, userLoginAfter, userLoginBefore, status);
    return myIdentities;
}
Also used : HashMap(java.util.HashMap) FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) SecurityGroup(org.olat.basesecurity.SecurityGroup) Date(java.util.Date) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) EmailProperty(org.olat.user.propertyhandlers.EmailProperty) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) PermissionOnResourceable(org.olat.basesecurity.PermissionOnResourceable)

Example 2 with PermissionOnResourceable

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

the class SystemRegistrationManager method getRegistrationPropertiesMessage.

public Map<String, String> getRegistrationPropertiesMessage() {
    Map<String, String> msgProperties = new HashMap<String, String>();
    boolean website = registrationModule.isPublishWebsite();
    boolean notify = registrationModule.isNotifyReleases();
    // OLAT version
    msgProperties.put("appName", Settings.getApplicationName());
    msgProperties.put("version", Settings.getFullVersionInfo());
    // Location
    msgProperties.put("location", registrationModule.getLocation());
    msgProperties.put("locationCSV", registrationModule.getLocationCoordinates());
    // System config
    msgProperties.put("instantMessagingEnabled", String.valueOf(CoreSpringFactory.getImpl(InstantMessagingModule.class).isEnabled()));
    msgProperties.put("enabledLanguages", CoreSpringFactory.getImpl(I18nModule.class).getEnabledLanguageKeys().toString());
    msgProperties.put("clusterEnabled", clusterMode);
    msgProperties.put("debuggingEnabled", String.valueOf(Settings.isDebuging()));
    // Course counts
    int allCourses = repositoryManager.countByTypeLimitAccess(CourseModule.ORES_TYPE_COURSE, RepositoryEntry.ACC_OWNERS);
    int publishedCourses = repositoryManager.countByTypeLimitAccess(CourseModule.ORES_TYPE_COURSE, RepositoryEntry.ACC_USERS);
    msgProperties.put("courses", String.valueOf(allCourses));
    msgProperties.put("coursesPublished", String.valueOf(publishedCourses));
    // User counts
    SecurityGroup olatuserGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
    int users = securityManager.countIdentitiesOfSecurityGroup(olatuserGroup);
    long disabled = securityManager.countIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, Identity.STATUS_LOGIN_DENIED);
    msgProperties.put("usersEnabled", String.valueOf(users - disabled));
    PermissionOnResourceable[] permissions = { new PermissionOnResourceable(Constants.PERMISSION_HASROLE, Constants.ORESOURCE_AUTHOR) };
    long authors = securityManager.countIdentitiesByPowerSearch(null, null, true, null, permissions, null, null, null, null, null, null);
    msgProperties.put("authors", String.valueOf(authors));
    // Activity
    Calendar lastLoginLimit = Calendar.getInstance();
    // -1 - 6 = -7 for last week
    lastLoginLimit.add(Calendar.DAY_OF_YEAR, -6);
    Long activeUsersLastWeek = securityManager.countUniqueUserLoginsSince(lastLoginLimit.getTime());
    msgProperties.put("activeUsersLastWeek", String.valueOf(activeUsersLastWeek));
    lastLoginLimit = Calendar.getInstance();
    lastLoginLimit.add(Calendar.MONTH, -1);
    Long activeUsersLastMonth = securityManager.countUniqueUserLoginsSince(lastLoginLimit.getTime());
    msgProperties.put("activeUsersLastMonth", String.valueOf(activeUsersLastMonth));
    // Groups
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    int groups = businessGroupService.countBusinessGroups(params, null);
    msgProperties.put("buddyGroups", String.valueOf(groups));
    msgProperties.put("learningGroups", String.valueOf(groups));
    msgProperties.put("rightGroups", String.valueOf(groups));
    msgProperties.put("groups", String.valueOf(groups));
    // URL
    msgProperties.put("url", Settings.getServerContextPathURI());
    msgProperties.put("publishWebsite", String.valueOf(website));
    // Description
    String desc = registrationModule.getWebsiteDescription();
    msgProperties.put("description", desc);
    if (notify) {
        // Email
        String email = registrationModule.getEmail();
        msgProperties.put("email", email);
    }
    return msgProperties;
}
Also used : I18nModule(org.olat.core.util.i18n.I18nModule) HashMap(java.util.HashMap) Calendar(java.util.Calendar) SecurityGroup(org.olat.basesecurity.SecurityGroup) InstantMessagingModule(org.olat.instantMessaging.InstantMessagingModule) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) PermissionOnResourceable(org.olat.basesecurity.PermissionOnResourceable)

Example 3 with PermissionOnResourceable

use of org.olat.basesecurity.PermissionOnResourceable 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)

Example 4 with PermissionOnResourceable

use of org.olat.basesecurity.PermissionOnResourceable in project OpenOLAT by OpenOLAT.

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)

Example 5 with PermissionOnResourceable

use of org.olat.basesecurity.PermissionOnResourceable in project OpenOLAT by OpenOLAT.

the class SystemRegistrationManager method getRegistrationPropertiesMessage.

public Map<String, String> getRegistrationPropertiesMessage() {
    Map<String, String> msgProperties = new HashMap<String, String>();
    boolean website = registrationModule.isPublishWebsite();
    boolean notify = registrationModule.isNotifyReleases();
    // OLAT version
    msgProperties.put("appName", Settings.getApplicationName());
    msgProperties.put("version", Settings.getFullVersionInfo());
    // Location
    msgProperties.put("location", registrationModule.getLocation());
    msgProperties.put("locationCSV", registrationModule.getLocationCoordinates());
    // System config
    msgProperties.put("instantMessagingEnabled", String.valueOf(CoreSpringFactory.getImpl(InstantMessagingModule.class).isEnabled()));
    msgProperties.put("enabledLanguages", CoreSpringFactory.getImpl(I18nModule.class).getEnabledLanguageKeys().toString());
    msgProperties.put("clusterEnabled", clusterMode);
    msgProperties.put("debuggingEnabled", String.valueOf(Settings.isDebuging()));
    // Course counts
    int allCourses = repositoryManager.countByTypeLimitAccess(CourseModule.ORES_TYPE_COURSE, RepositoryEntry.ACC_OWNERS);
    int publishedCourses = repositoryManager.countByTypeLimitAccess(CourseModule.ORES_TYPE_COURSE, RepositoryEntry.ACC_USERS);
    msgProperties.put("courses", String.valueOf(allCourses));
    msgProperties.put("coursesPublished", String.valueOf(publishedCourses));
    // User counts
    SecurityGroup olatuserGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
    int users = securityManager.countIdentitiesOfSecurityGroup(olatuserGroup);
    long disabled = securityManager.countIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, Identity.STATUS_LOGIN_DENIED);
    msgProperties.put("usersEnabled", String.valueOf(users - disabled));
    PermissionOnResourceable[] permissions = { new PermissionOnResourceable(Constants.PERMISSION_HASROLE, Constants.ORESOURCE_AUTHOR) };
    long authors = securityManager.countIdentitiesByPowerSearch(null, null, true, null, permissions, null, null, null, null, null, null);
    msgProperties.put("authors", String.valueOf(authors));
    // Activity
    Calendar lastLoginLimit = Calendar.getInstance();
    // -1 - 6 = -7 for last week
    lastLoginLimit.add(Calendar.DAY_OF_YEAR, -6);
    Long activeUsersLastWeek = securityManager.countUniqueUserLoginsSince(lastLoginLimit.getTime());
    msgProperties.put("activeUsersLastWeek", String.valueOf(activeUsersLastWeek));
    lastLoginLimit = Calendar.getInstance();
    lastLoginLimit.add(Calendar.MONTH, -1);
    Long activeUsersLastMonth = securityManager.countUniqueUserLoginsSince(lastLoginLimit.getTime());
    msgProperties.put("activeUsersLastMonth", String.valueOf(activeUsersLastMonth));
    // Groups
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    int groups = businessGroupService.countBusinessGroups(params, null);
    msgProperties.put("buddyGroups", String.valueOf(groups));
    msgProperties.put("learningGroups", String.valueOf(groups));
    msgProperties.put("rightGroups", String.valueOf(groups));
    msgProperties.put("groups", String.valueOf(groups));
    // URL
    msgProperties.put("url", Settings.getServerContextPathURI());
    msgProperties.put("publishWebsite", String.valueOf(website));
    // Description
    String desc = registrationModule.getWebsiteDescription();
    msgProperties.put("description", desc);
    if (notify) {
        // Email
        String email = registrationModule.getEmail();
        msgProperties.put("email", email);
    }
    return msgProperties;
}
Also used : I18nModule(org.olat.core.util.i18n.I18nModule) HashMap(java.util.HashMap) Calendar(java.util.Calendar) SecurityGroup(org.olat.basesecurity.SecurityGroup) InstantMessagingModule(org.olat.instantMessaging.InstantMessagingModule) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) PermissionOnResourceable(org.olat.basesecurity.PermissionOnResourceable)

Aggregations

PermissionOnResourceable (org.olat.basesecurity.PermissionOnResourceable)6 HashMap (java.util.HashMap)4 SecurityGroup (org.olat.basesecurity.SecurityGroup)4 Identity (org.olat.core.id.Identity)4 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)2 I18nModule (org.olat.core.util.i18n.I18nModule)2 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)2 InstantMessagingModule (org.olat.instantMessaging.InstantMessagingModule)2 EmailProperty (org.olat.user.propertyhandlers.EmailProperty)2 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)2