diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Client.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Client.java index d7f1e15..2025c5c 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Client.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Client.java @@ -1,7 +1,13 @@ /* © SRSoftware 2024 */ package de.srsoftware.oidc.api; +import static de.srsoftware.oidc.api.Constants.*; + +import java.util.Map; import java.util.Set; public record Client(String id, String name, String secret, Set redirectUris) { + public Map map() { + return Map.of(CLIENT_ID, id, NAME, name, SECRET, secret, REDIRECT_URIS, redirectUris); + } } diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Constants.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Constants.java index ef8d022..5577cb7 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Constants.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Constants.java @@ -2,8 +2,9 @@ package de.srsoftware.oidc.api; public class Constants { - public static final String CLIENT_ID = "client_id"; - public static final String NAME = "name"; - public static final String REDIRECT_URI = "redirect_uri"; - public static final String SECRET = "secret"; + public static final String CLIENT_ID = "client_id"; + public static final String NAME = "name"; + public static final String REDIRECT_URI = "redirect_uri"; + public static final String REDIRECT_URIS = "redirect_uris"; + public static final String SECRET = "secret"; } diff --git a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/Backend.java b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/Backend.java index b9f485d..a67be3e 100644 --- a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/Backend.java +++ b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/Backend.java @@ -30,7 +30,7 @@ public class Backend extends PathHandler { if (!session.user().hasPermission(MANAGE_CLIENTS)) return sendError(ex, "NOT ALLOWED"); var json = json(ex); var redirects = new HashSet(); - for (Object o : json.getJSONArray(REDIRECT_URI)) { + for (Object o : json.getJSONArray(REDIRECT_URIS)) { if (o instanceof String s) redirects.add(s); } var client = new Client(json.getString(CLIENT_ID), json.getString(NAME), json.getString(SECRET), redirects); @@ -128,6 +128,8 @@ public class Backend extends PathHandler { return addClient(ex, session); case "/authorize": return authorize(ex, session); + case "/client": + return loadClient(ex, session); case "/clients": return clients(ex, session); case "/update/password": @@ -145,6 +147,17 @@ public class Backend extends PathHandler { return SessionToken.from(ex).map(SessionToken::sessionId).flatMap(sessions::retrieve); } + private boolean loadClient(HttpExchange ex, Session session) throws IOException { + if (!session.user().hasPermission(MANAGE_CLIENTS)) return sendEmptyResponse(HTTP_FORBIDDEN, ex); + var json = json(ex); + if (json.has(CLIENT_ID)) { + var clientID = json.getString(CLIENT_ID); + var client = clients.getClient(clientID).map(Client::map).map(JSONObject::new); + if (client.isPresent()) return sendContent(ex, client.get()); + } + return sendEmptyResponse(HTTP_NOT_FOUND, ex); + } + private boolean logout(HttpExchange ex, Session session) throws IOException { sessions.dropSession(session.id()); new SessionToken("").addTo(ex); diff --git a/de.srsoftware.oidc.web/src/main/resources/en/clients.html b/de.srsoftware.oidc.web/src/main/resources/en/clients.html index 3b08473..b19ed8e 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/clients.html +++ b/de.srsoftware.oidc.web/src/main/resources/en/clients.html @@ -12,24 +12,25 @@ Clients

Clients

- -These are clients that are registered with LightOIDC: - - - - - - - - - - - - - -
ClientIDRedirect URLsActions
- -
- +
+ These are clients that are registered with LightOIDC: + + + + + + + + + + + + + +
ClientIDRedirect URLsActions
+ +
+ +
\ No newline at end of file diff --git a/de.srsoftware.oidc.web/src/main/resources/en/clients.js b/de.srsoftware.oidc.web/src/main/resources/en/clients.js index 2f4108f..f13471b 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/clients.js +++ b/de.srsoftware.oidc.web/src/main/resources/en/clients.js @@ -8,7 +8,7 @@ async function handleClients(response){ for (let id in clients){ var row = document.createElement("tr"); var client = clients[id]; - row.innerHTML = ""+client.name+"\n"+id+"\n"+client.redirect_uris.join("
")+'\n'; + row.innerHTML = ""+client.name+"\n"+id+"\n"+client.redirect_uris.join("
")+'\n'; bottom.parentNode.insertBefore(row,bottom); } } @@ -27,4 +27,8 @@ function remove(clientId){ } } +function edit(clientId){ + redirect("edit_client.html?id="+clientId); +} + fetch(api+"/clients",{method:'POST'}).then(handleClients); \ No newline at end of file diff --git a/de.srsoftware.oidc.web/src/main/resources/en/common.js b/de.srsoftware.oidc.web/src/main/resources/en/common.js index 41d1c25..62ee924 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/common.js +++ b/de.srsoftware.oidc.web/src/main/resources/en/common.js @@ -19,6 +19,11 @@ function getValue(id){ return get(id).value; } +function hide(id){ + console.log('hide('+id+')'); + get(id).style.display = 'none'; +} + function redirect(page){ window.location.href = page; } @@ -29,6 +34,10 @@ function setText(id, text){ function setValue(id,newVal){ - document.getElementById(id).value = newVal; + get(id).value = newVal; } +function show(id){ + console.log('show('+id+')'); + get(id).style.display = ''; +} \ No newline at end of file diff --git a/de.srsoftware.oidc.web/src/main/resources/en/edit_client.html b/de.srsoftware.oidc.web/src/main/resources/en/edit_client.html new file mode 100644 index 0000000..1871ba0 --- /dev/null +++ b/de.srsoftware.oidc.web/src/main/resources/en/edit_client.html @@ -0,0 +1,41 @@ + + + + Light OIDC + + + + + + + +

Edit client

+
+ Data + + + + + + + + + + + + + + + + + + + + + +
ID
Name
Secret
Redirect URIs + +
+
+ + \ No newline at end of file diff --git a/de.srsoftware.oidc.web/src/main/resources/en/edit_client.js b/de.srsoftware.oidc.web/src/main/resources/en/edit_client.js new file mode 100644 index 0000000..196e77d --- /dev/null +++ b/de.srsoftware.oidc.web/src/main/resources/en/edit_client.js @@ -0,0 +1,20 @@ +var params = new URLSearchParams(window.location.search); +var id = params.get('id'); + +fetch(api+'/client', + { + method: 'POST', + body: JSON.stringify({ + client_id : id + }) + }).then(handleResponse); + +async function handleResponse(response){ + if (response.ok){ + var json = await response.json(); + get('client_id').value = json.client_id; + get('name').value = json.name; + get('secret').value = json.secret; + get('redirects').value = json.redirect_uris.join("\n"); + } +} diff --git a/de.srsoftware.oidc.web/src/main/resources/en/login.html b/de.srsoftware.oidc.web/src/main/resources/en/login.html index fac4445..29245ba 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/login.html +++ b/de.srsoftware.oidc.web/src/main/resources/en/login.html @@ -10,16 +10,24 @@

Login

User credentials - - - + + + + + + + + + + + + + + + + + +
User name
Password
-
\ No newline at end of file diff --git a/de.srsoftware.oidc.web/src/main/resources/en/login.js b/de.srsoftware.oidc.web/src/main/resources/en/login.js index 06d9c8f..7217326 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/login.js +++ b/de.srsoftware.oidc.web/src/main/resources/en/login.js @@ -1,10 +1,11 @@ async function handleLogin(response){ if (response.ok){ var body = await response.json(); - + hide('error'); setTimeout(doRedirect,100); + } else { + show('error'); } - return false; } function doRedirect(){ @@ -14,7 +15,6 @@ function doRedirect(){ } function tryLogin(){ - document.getElementById("error").innerHTML = ""; var username = getValue('username'); var password = getValue('password'); fetch(api+"/login",{ diff --git a/de.srsoftware.oidc.web/src/main/resources/en/newclient.html b/de.srsoftware.oidc.web/src/main/resources/en/newclient.html index cef9bad..9e31e8d 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/newclient.html +++ b/de.srsoftware.oidc.web/src/main/resources/en/newclient.html @@ -29,8 +29,11 @@ redirect urls + + + + - \ No newline at end of file diff --git a/de.srsoftware.oidc.web/src/main/resources/en/newclient.js b/de.srsoftware.oidc.web/src/main/resources/en/newclient.js index 9ac95dc..20e9cf6 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/newclient.js +++ b/de.srsoftware.oidc.web/src/main/resources/en/newclient.js @@ -4,7 +4,7 @@ function addClient(){ client_id : getValue('client-id'), name : getValue('client-name'), secret : getValue('client-secret'), - redirect_uri : getValue('redirect-urls').split("\n") + redirect_uris : getValue('redirect-urls').split("\n") }; fetch(api+'/add/client',{ method : 'POST', diff --git a/de.srsoftware.oidc.web/src/main/resources/en/settings.html b/de.srsoftware.oidc.web/src/main/resources/en/settings.html index 52fb86b..116f7b5 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/settings.html +++ b/de.srsoftware.oidc.web/src/main/resources/en/settings.html @@ -28,8 +28,15 @@ ID + + Error + Failed to update settings! + + + + + -
@@ -48,8 +55,19 @@ Repeat Password + + Error + Wrong password! + + + Error + Mismatch between new password and repetition! + + + + + -
diff --git a/de.srsoftware.oidc.web/src/main/resources/en/settings.js b/de.srsoftware.oidc.web/src/main/resources/en/settings.js index 7fcde49..1ee2df9 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/settings.js +++ b/de.srsoftware.oidc.web/src/main/resources/en/settings.js @@ -11,18 +11,16 @@ function fillForm(){ function handleResponse(response){ - setText('updateBtn',response.ok ? 'saved.' : 'failed!'); + if (response.ok){ + hide('update_error') + setText('updateBtn', 'saved.'); + } else { + show('update_error'); + setText('updateBtn', 'Update failed!'); + } + enable('updateBtn'); setTimeout(function(){ setText('updateBtn','Update'); - enable('updateBtn'); - },10000); -} - -function handlePasswordResponse(response){ - setText('passBtn',response.ok ? 'saved.' : 'failed!'); - setTimeout(function(){ - setText('passBtn','Update'); - enable('passBtn'); },10000); } @@ -43,6 +41,26 @@ function update(){ setText('updateBtn','sent…'); } + +async function handlePasswordResponse(response){ + if (response.ok){ + hide('wrong_password'); + hide('password_mismatch'); + setText('passBtn', 'saved.'); + } else { + setText('passBtn', 'Update failed!'); + var text = await response.text(); + if (text == 'wrong password') show('wrong_password'); + if (text == 'password mismatch') show('password_mismatch'); + + } + enable('passBtn'); + setTimeout(function(){ + setText('passBtn','Update'); + },10000); +} + + function updatePass(){ disable('passBtn'); var newData = { @@ -58,10 +76,6 @@ function updatePass(){ body : JSON.stringify(newData) }).then(handlePasswordResponse); setText('passBtn','sent…'); - setTimeout(function(){ - setText('passBtn','Update'); - enable('passBtn'); - },10000); } function passKeyDown(ev){ diff --git a/de.srsoftware.oidc.web/src/main/resources/en/style.css b/de.srsoftware.oidc.web/src/main/resources/en/style.css index c54667c..a97ff66 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/style.css +++ b/de.srsoftware.oidc.web/src/main/resources/en/style.css @@ -5,12 +5,22 @@ body { body fieldset { border-radius: 10px; + display: inline-block; } a { color: yellow; } +input, textarea{ + width: 600px; +} + +input:disabled{ + color: white; + background-color: gray; +} + fieldset th, form th{ text-align: right; @@ -18,4 +28,8 @@ form th{ .hidden{ display: none; +} + +.warning{ + color: yellow; } \ No newline at end of file