|
|
@ -1,5 +1,6 @@ |
|
|
|
/* © SRSoftware 2024 */ |
|
|
|
/* © SRSoftware 2024 */ |
|
|
|
package de.srsoftware.oidc.datastore.file; /* © SRSoftware 2024 */ |
|
|
|
package de.srsoftware.oidc.datastore.file; /* © SRSoftware 2024 */ |
|
|
|
|
|
|
|
import static de.srsoftware.oidc.api.Constants.CLIENT_ID; |
|
|
|
import static de.srsoftware.oidc.api.User.*; |
|
|
|
import static de.srsoftware.oidc.api.User.*; |
|
|
|
|
|
|
|
|
|
|
|
import de.srsoftware.oidc.api.*; |
|
|
|
import de.srsoftware.oidc.api.*; |
|
|
@ -15,7 +16,11 @@ import java.util.*; |
|
|
|
import org.json.JSONObject; |
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
|
|
|
|
public class FileStore implements ClientService, SessionService, UserService { |
|
|
|
public class FileStore implements ClientService, SessionService, UserService { |
|
|
|
|
|
|
|
private static final String CLIENTS = "clients"; |
|
|
|
private static final String EXPIRATION = "expiration"; |
|
|
|
private static final String EXPIRATION = "expiration"; |
|
|
|
|
|
|
|
private static final String NAME = "name"; |
|
|
|
|
|
|
|
private static final String REDIRECT_URIS = "redirect_uris"; |
|
|
|
|
|
|
|
private static final String SECRET = "secret"; |
|
|
|
private static final String SESSIONS = "sessions"; |
|
|
|
private static final String SESSIONS = "sessions"; |
|
|
|
private static final String USERS = "users"; |
|
|
|
private static final String USERS = "users"; |
|
|
|
private static final String USER = "user"; |
|
|
|
private static final String USER = "user"; |
|
|
@ -57,13 +62,13 @@ public class FileStore implements ClientService, SessionService, UserService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public FileStore init(User defaultUser) { |
|
|
|
public FileStore init(User defaultUser) { |
|
|
|
|
|
|
|
if (!json.has(CLIENTS)) json.put(CLIENTS, new JSONObject()); |
|
|
|
if (!json.has(SESSIONS)) json.put(SESSIONS, new JSONObject()); |
|
|
|
if (!json.has(SESSIONS)) json.put(SESSIONS, new JSONObject()); |
|
|
|
if (!json.has(USERS)) save(defaultUser); |
|
|
|
if (!json.has(USERS)) save(defaultUser); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<User> list() { |
|
|
|
public List<User> list() { |
|
|
|
return List.of(); |
|
|
|
return List.of(); |
|
|
@ -195,7 +200,9 @@ public class FileStore implements ClientService, SessionService, UserService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public ClientService add(Client client) { |
|
|
|
public ClientService add(Client client) { |
|
|
|
return null; |
|
|
|
json.getJSONObject(CLIENTS).put(client.id(), Map.of(NAME,client.name(),SECRET,client.secret(),REDIRECT_URIS,client.redirectUris())); |
|
|
|
|
|
|
|
save(); |
|
|
|
|
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -205,7 +212,18 @@ public class FileStore implements ClientService, SessionService, UserService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<Client> listClients() { |
|
|
|
public List<Client> listClients() { |
|
|
|
return List.of(); |
|
|
|
var clients = json.getJSONObject(CLIENTS); |
|
|
|
|
|
|
|
var list = new ArrayList<Client>(); |
|
|
|
|
|
|
|
for (var clientId : clients.keySet()){ |
|
|
|
|
|
|
|
var clientData = clients.getJSONObject(clientId); |
|
|
|
|
|
|
|
var redirectUris = new HashSet<String>(); |
|
|
|
|
|
|
|
for (var o : clientData.getJSONArray(REDIRECT_URIS)){ |
|
|
|
|
|
|
|
if (o instanceof String s) redirectUris.add(s); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var client = new Client(clientId,clientData.getString(NAME),clientData.getString(SECRET),redirectUris); |
|
|
|
|
|
|
|
list.add(client); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|