preparing for main menu configuration
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package de.srsoftware.umbrella.core;
|
||||
|
||||
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.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Token;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.MENU;
|
||||
|
||||
public class SettingsService extends BaseHandler {
|
||||
|
||||
private final Configuration config;
|
||||
|
||||
public SettingsService(Configuration config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
try {
|
||||
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||
var user = userService().loadUser(token);
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
var head = path.pop();
|
||||
return switch (head) {
|
||||
case MENU -> getMenuSettings(user.get(), ex);
|
||||
case null, default -> super.doGet(path, ex);
|
||||
};
|
||||
} catch (UmbrellaException e) {
|
||||
return send(ex, e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getMenuSettings(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
Optional<JSONObject> modules = config.get("umbrella.modules");
|
||||
if (modules.isEmpty()) throw UmbrellaException.missingConfig("umbrella.modules");
|
||||
var key = modules.get().keySet();
|
||||
|
||||
|
||||
return notFound(ex);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,9 @@ public class Path {
|
||||
public static final String LOGIN = "login";
|
||||
|
||||
public static final String LOGOUT = "logout";
|
||||
|
||||
public static final String MENU = "menu";
|
||||
|
||||
public static final String PAGE = "page";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String PROJECT = "project";
|
||||
|
||||
Reference in New Issue
Block a user