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);
}
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());
}
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();
}
Aggregations