Browse Source

implemented legacy module for company

feature/brute_force_protection
Stephan Richter 3 months ago
parent
commit
6b2a437539
  1. 3
      backend/src/main/java/de/srsoftware/umbrella/backend/Application.java
  2. 75
      legacy/src/main/java/de/srsoftware/umbrella/legacy/CompanyLegacy.java

3
backend/src/main/java/de/srsoftware/umbrella/backend/Application.java

@ -15,6 +15,7 @@ import de.srsoftware.umbrella.core.Util; @@ -15,6 +15,7 @@ import de.srsoftware.umbrella.core.Util;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.documents.DocumentApi;
import de.srsoftware.umbrella.items.ItemApi;
import de.srsoftware.umbrella.legacy.CompanyLegacy;
import de.srsoftware.umbrella.legacy.NotesLegacy;
import de.srsoftware.umbrella.legacy.ProjectLegacy;
import de.srsoftware.umbrella.legacy.UserLegacy;
@ -69,6 +70,7 @@ public class Application { @@ -69,6 +70,7 @@ public class Application {
var tagModule = new TagModule(registry,config);
var bookmarkApi = new BookmarkApi(registry,config);
var companyModule = new CompanyModule(registry, config);
var companyLegacy = new CompanyLegacy(registry, config);
var documentApi = new DocumentApi(registry, config);
var itemApi = new ItemApi(registry, config);
var userLegacy = new UserLegacy(registry,config);
@ -84,6 +86,7 @@ public class Application { @@ -84,6 +86,7 @@ public class Application {
bookmarkApi .bindPath("/api/bookmark") .on(server);
documentApi .bindPath("/api/document") .on(server);
companyModule .bindPath("/api/company") .on(server);
companyLegacy .bindPath("/legacy/company") .on(server);
itemApi .bindPath("/api/items") .on(server);
markdownApi .bindPath("/api/markdown") .on(server);
notesModule .bindPath("/api/notes") .on(server);

75
legacy/src/main/java/de/srsoftware/umbrella/legacy/CompanyLegacy.java

@ -0,0 +1,75 @@ @@ -0,0 +1,75 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.legacy;
import com.sun.net.httpserver.HttpExchange;
import de.srsoftware.configuration.Configuration;
import de.srsoftware.tools.Path;
import de.srsoftware.tools.SessionToken;
import de.srsoftware.umbrella.core.BaseHandler;
import de.srsoftware.umbrella.core.ModuleRegistry;
import de.srsoftware.umbrella.core.model.Token;
import de.srsoftware.umbrella.core.model.UmbrellaUser;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import static de.srsoftware.tools.Optionals.nullable;
import static de.srsoftware.umbrella.core.Constants.TOKEN;
import static de.srsoftware.umbrella.core.Constants.USERS;
import static de.srsoftware.umbrella.core.Paths.JSON;
import static de.srsoftware.umbrella.core.Util.mapValues;
public class CompanyLegacy extends BaseHandler {
private final ModuleRegistry registry;
private final Configuration config;
public CompanyLegacy(ModuleRegistry registry, Configuration config) {
this.registry = registry;
this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules"));
}
@Override
public boolean doDelete(Path path, HttpExchange ex) throws IOException {
return super.doDelete(path, ex);
}
@Override
public boolean doGet(Path path, HttpExchange ex) throws IOException {
if (path.empty()) return sendRedirect(ex, url(ex).replaceAll("/legacy/.*",""));
return super.doGet(path, ex);
}
@Override
public boolean doOptions(Path path, HttpExchange ex) throws IOException {
return super.doOptions(path, ex);
}
@Override
public boolean doPatch(Path path, HttpExchange ex) throws IOException {
return super.doPatch(path, ex);
}
@Override
public boolean doPost(Path path, HttpExchange ex) throws IOException{
var params = formData(ex);
Optional<Token> token = SessionToken.from(ex).map(Token::of);
if (token.isEmpty()) token = nullable(params.get(TOKEN)).map(Object::toString).map(Token::of);
var user = registry.userService().loadUser(token);
if (user.isEmpty()) return unauthorized(ex);
return switch (path.pop()){
case JSON -> postCompanyJson(ex,params,user.get());
default -> super.doPost(path, ex);
};
}
private boolean postCompanyJson(HttpExchange ex, Map<String, Object> params, UmbrellaUser user) throws IOException {
var companies = registry.companyService().listCompaniesOf(user);
return sendContent(ex, mapValues(companies));
}
}
Loading…
Cancel
Save