working on user settings

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-07-21 23:57:42 +02:00
parent 03a0ba139f
commit f078491344
13 changed files with 252 additions and 17 deletions

View File

@@ -2,5 +2,5 @@ package de.srsoftware.oidc.api;
import java.util.Set;
public record Client(String id, String name, Set<String> redirectUris) {
public record Client(String id, String name, String secret, Set<String> redirectUris) {
}

View File

@@ -1,6 +1,7 @@
/* © SRSoftware 2024 */
package de.srsoftware.oidc.api;
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -8,6 +9,7 @@ import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
@@ -106,13 +108,25 @@ public abstract class PathHandler implements HttpHandler {
return false;
}
public static boolean sendContent(HttpExchange ex, byte[] bytes) throws IOException {
ex.sendResponseHeaders(HTTP_OK, bytes.length);
public static boolean sendContent(HttpExchange ex, int status, byte[] bytes) throws IOException {
ex.sendResponseHeaders(status, bytes.length);
ex.getResponseBody().write(bytes);
return true;
}
public static boolean sendContent(HttpExchange ex, byte[] bytes) throws IOException {
return sendContent(ex,HTTP_OK,bytes);
}
public static boolean sendContent(HttpExchange ex, Object o) throws IOException {
return sendContent(ex, o.toString().getBytes(UTF_8));
return sendContent(ex, HTTP_OK, o.toString().getBytes(UTF_8));
}
public static boolean sendError(HttpExchange ex, byte[] bytes) throws IOException {
return sendContent(ex,HTTP_BAD_REQUEST,bytes);
}
public static boolean sendError(HttpExchange ex, Object o) throws IOException {
return sendContent(ex,HTTP_BAD_REQUEST,o.toString().getBytes(UTF_8));
}
}

View File

@@ -9,6 +9,7 @@ public final class User {
public static final String PERMISSIONS = "permissions";
public static final String REALNAME = "realname";
public static final String USERNAME = "username";
public static final String UUID = "uuid";
private final Set<Permission> permissions = new HashSet<>();
@@ -65,8 +66,8 @@ public final class User {
public Map<String, Object> map(boolean includePassword) {
return includePassword
? Map.of(USERNAME, username, REALNAME, realName, EMAIL, email, PERMISSIONS, permissions, PASSWORD, hashedPassword)
: Map.of(USERNAME, username, REALNAME, realName, EMAIL, email, PERMISSIONS, permissions);
? Map.of(USERNAME, username, REALNAME, realName, EMAIL, email, PERMISSIONS, permissions, UUID, uuid, PASSWORD, hashedPassword)
: Map.of(USERNAME, username, REALNAME, realName, EMAIL, email, PERMISSIONS, permissions, UUID, uuid);
}
public String realName() {

View File

@@ -6,9 +6,11 @@ import java.util.Optional;
public interface UserService {
public UserService delete(User user);
public boolean passwordMatches(String password, String hashedPassword);
public UserService init(User defaultUser);
public List<User> list();
public Optional<User> load(String id);
public Optional<User> load(String username, String password);
public <T extends UserService> T save(User user);
public <T extends UserService> T updatePassword(User user, String plaintextPassword);
}