use of org.graylog.security.authservice.AuthServiceBackendDTO in project graylog2-server by Graylog2.
the class AuthServiceBackendsResource method getUsers.
@GET
@Path("{backendId}/users")
@ApiOperation("Get paginated users for an authentication service backend")
@RequiresPermissions({ RestPermissions.AUTH_SERVICE_GLOBAL_CONFIG_READ, RestPermissions.USERS_READ })
public PaginatedResponse<UserOverviewDTO> getUsers(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("50") int perPage, @ApiParam(name = "query") @QueryParam("query") @DefaultValue("") String query, @ApiParam(name = "sort", value = "The field to sort the result on", required = true, allowableValues = "username,full_name,email") @DefaultValue(UserOverviewDTO.FIELD_FULL_NAME) @QueryParam("sort") String sort, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order, @ApiParam(name = "backendId", required = true) @PathParam("backendId") @NotBlank String backendId) {
final AuthServiceBackendDTO activeConfig = loadConfig(backendId);
final PaginatedList<UserOverviewDTO> userList = userService.findPaginatedByAuthServiceBackend(parseSearchQuery(query), page, perPage, sort, order, activeConfig.id());
return PaginatedResponse.create("users", userList, query, Collections.singletonMap("roles", createRoleContext(userList.delegate())));
}
use of org.graylog.security.authservice.AuthServiceBackendDTO in project graylog2-server by Graylog2.
the class AuthServiceBackendsResource method update.
@PUT
@Path("{backendId}")
@ApiOperation("Updates an existing authentication service backend")
@AuditEvent(type = SecurityAuditEventTypes.AUTH_SERVICE_BACKEND_UPDATE)
public Response update(@ApiParam(name = "backendId", required = true) @PathParam("backendId") @NotBlank String backendId, @ApiParam(name = "JSON body", required = true) @NotNull AuthServiceBackendDTO updatedConfig) {
checkPermission(RestPermissions.AUTH_SERVICE_BACKEND_EDIT, backendId);
validateConfig(updatedConfig);
final AuthServiceBackendDTO currentConfig = loadConfig(backendId);
return toResponse(dbService.save(updatedConfig.withId(currentConfig.id())));
}
use of org.graylog.security.authservice.AuthServiceBackendDTO in project graylog2-server by Graylog2.
the class AuthServiceBackendsResource method list.
@GET
@ApiOperation("Returns available authentication service backends")
public PaginatedResponse<AuthServiceBackendDTO> list(@ApiParam(name = "pagination parameters") @BeanParam PaginationParameters paginationParameters) {
final AuthServiceBackendDTO activeBackendConfig = globalAuthServiceConfig.getActiveBackendConfig().filter(this::checkReadPermission).orElse(null);
final PaginatedList<AuthServiceBackendDTO> list = dbService.findPaginated(paginationParameters, this::checkReadPermission);
return PaginatedResponse.create("backends", list, Collections.singletonMap("active_backend", activeBackendConfig));
}
use of org.graylog.security.authservice.AuthServiceBackendDTO in project graylog2-server by Graylog2.
the class V20201103145400_LegacyAuthServiceMigration method upgrade.
@Override
public void upgrade() {
final MigrationCompleted migrationState = clusterConfigService.getOrDefault(MigrationCompleted.class, MigrationCompleted.createEmpty());
final ImmutableSet.Builder<String> migratedConfigsBuilder = ImmutableSet.builder();
// While the LDAP settings collection could contain more than one document, in practice we only expect a
// single one. That's why we are using the ID of the last created auth service for the notification.
String lastCreatedAuthServiceId = null;
// Add all configs that have already been migrated
migratedConfigsBuilder.addAll(migrationState.migratedConfigs());
for (final Document document : ldapSettings.find().sort(Sorts.ascending("_id"))) {
final String idString = document.getObjectId("_id").toHexString();
if (!document.getBoolean("enabled")) {
LOG.debug("Skipping disabled configuration <{}>", idString);
continue;
}
if (migrationState.isDone(idString)) {
LOG.debug("Configuration <{}> already migrated", idString);
continue;
}
final AuthServiceBackendDTO newConfig;
if (document.getBoolean("active_directory")) {
newConfig = buildActiveDirectoryConfig(document);
} else {
newConfig = buildLDAPConfig(document);
}
final AuthServiceBackendDTO savedConfig = authServiceBackendService.save(newConfig);
for (final MigrationModule migrationModule : migrationModules) {
migrationModule.upgrade(document, savedConfig);
}
lastCreatedAuthServiceId = savedConfig.id();
migratedConfigsBuilder.add(idString);
}
final ImmutableSet<String> migratedConfigs = migratedConfigsBuilder.build();
clusterConfigService.write(MigrationCompleted.create(migratedConfigs));
if (lastCreatedAuthServiceId != null) {
final Notification notification = notificationService.buildNow().addType(Notification.Type.LEGACY_LDAP_CONFIG_MIGRATION).addSeverity(Notification.Severity.URGENT).addDetail("auth_service_id", lastCreatedAuthServiceId);
notificationService.publishIfFirst(notification);
}
}
Aggregations