Search in sources :

Example 1 with MongoDbSession

use of org.graylog2.security.MongoDbSession in project graylog2-server by Graylog2.

the class UsersResource method toUserResponse.

private UserSummary toUserResponse(User user, boolean includePermissions, @SuppressWarnings("OptionalUsedAsFieldOrParameterType") Optional<MongoDbSession> mongoDbSession) {
    final Set<String> roleIds = user.getRoleIds();
    Set<String> roleNames = Collections.emptySet();
    if (!roleIds.isEmpty()) {
        roleNames = userService.getRoleNames(user);
        if (roleNames.isEmpty()) {
            LOG.error("Unable to load role names for role IDs {} for user {}", roleIds, user);
        }
    }
    boolean sessionActive = false;
    Date lastActivity = null;
    String clientAddress = null;
    if (mongoDbSession.isPresent()) {
        final MongoDbSession session = mongoDbSession.get();
        sessionActive = true;
        lastActivity = session.getLastAccessTime();
        clientAddress = session.getHost();
    }
    return UserSummary.create(user.getId(), user.getName(), user.getEmail(), user.getFullName(), includePermissions ? userService.getPermissionsForUser(user) : Collections.emptyList(), user.getPreferences(), firstNonNull(user.getTimeZone(), DateTimeZone.UTC).getID(), user.getSessionTimeoutMs(), user.isReadOnly(), user.isExternalUser(), user.getStartpage(), roleNames, sessionActive, lastActivity, clientAddress);
}
Also used : MongoDbSession(org.graylog2.security.MongoDbSession) Date(java.util.Date)

Example 2 with MongoDbSession

use of org.graylog2.security.MongoDbSession in project graylog2-server by Graylog2.

the class UsersResource method toUserResponse.

private UserSummary toUserResponse(User user, boolean includePermissions, AllUserSessions sessions) {
    final Set<String> roleIds = user.getRoleIds();
    Set<String> roleNames = Collections.emptySet();
    if (!roleIds.isEmpty()) {
        roleNames = userManagementService.getRoleNames(user);
        if (roleNames.isEmpty()) {
            LOG.error("Unable to load role names for role IDs {} for user {}", roleIds, user);
        }
    }
    boolean sessionActive = false;
    Date lastActivity = null;
    String clientAddress = null;
    final Optional<MongoDbSession> mongoDbSession = sessions.forUser(user);
    if (mongoDbSession.isPresent()) {
        final MongoDbSession session = mongoDbSession.get();
        sessionActive = true;
        lastActivity = session.getLastAccessTime();
        clientAddress = session.getHost();
    }
    List<WildcardPermission> wildcardPermissions;
    List<GRNPermission> grnPermissions;
    if (includePermissions) {
        wildcardPermissions = userManagementService.getWildcardPermissionsForUser(user);
        grnPermissions = userManagementService.getGRNPermissionsForUser(user);
    } else {
        wildcardPermissions = ImmutableList.of();
        grnPermissions = ImmutableList.of();
    }
    return UserSummary.create(user.getId(), user.getName(), user.getEmail(), user.getFirstName().orElse(null), user.getLastName().orElse(null), user.getFullName(), wildcardPermissions, grnPermissions, user.getPreferences(), user.getTimeZone() == null ? null : user.getTimeZone().getID(), user.getSessionTimeoutMs(), user.isReadOnly(), user.isExternalUser(), user.getStartpage(), roleNames, sessionActive, lastActivity, clientAddress, user.getAccountStatus());
}
Also used : GRNPermission(org.graylog.security.permissions.GRNPermission) MongoDbSession(org.graylog2.security.MongoDbSession) WildcardPermission(org.apache.shiro.authz.permission.WildcardPermission) Date(java.util.Date)

Example 3 with MongoDbSession

use of org.graylog2.security.MongoDbSession in project graylog2-server by Graylog2.

the class UsersResource method getAdminUserDTO.

private UserOverviewDTO getAdminUserDTO(AllUserSessions sessions) {
    final Optional<User> optionalAdmin = userManagementService.getRootUser();
    if (!optionalAdmin.isPresent()) {
        return null;
    }
    final User admin = optionalAdmin.get();
    final Set<String> adminRoles = userManagementService.getRoleNames(admin);
    final Optional<MongoDbSession> lastSession = sessions.forUser(admin);
    return UserOverviewDTO.builder().username(admin.getName()).fullName(admin.getFullName()).email(admin.getEmail()).externalUser(admin.isExternalUser()).readOnly(admin.isReadOnly()).id(admin.getId()).fillSession(lastSession).roles(adminRoles).build();
}
Also used : User(org.graylog2.plugin.database.users.User) MongoDbSession(org.graylog2.security.MongoDbSession)

Aggregations

MongoDbSession (org.graylog2.security.MongoDbSession)3 Date (java.util.Date)2 WildcardPermission (org.apache.shiro.authz.permission.WildcardPermission)1 GRNPermission (org.graylog.security.permissions.GRNPermission)1 User (org.graylog2.plugin.database.users.User)1