implemented custom loggin

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-07-24 00:16:55 +02:00
parent a277be5091
commit fe14e81304
21 changed files with 335 additions and 66 deletions

View File

@@ -5,6 +5,8 @@ import com.sun.net.httpserver.HttpExchange;
import de.srsoftware.oidc.api.PathHandler;
import java.io.IOException;
import static java.lang.System.Logger.Level.INFO;
public class Forward extends PathHandler {
private final int CODE = 302;
private final String toPath;
@@ -15,7 +17,7 @@ public class Forward extends PathHandler {
@Override
public boolean doGet(String path, HttpExchange ex) throws IOException {
System.out.printf("Forwarding (%d) %s to %s…\n", CODE, path, toPath);
return sendRedirect(ex,toPath);
LOG.log(INFO,"Forwarding ({0}}) {1} to {2}…", CODE, path, toPath);
return sendRedirect(ex, toPath);
}
}

View File

@@ -1,6 +1,7 @@
/* © SRSoftware 2024 */
package de.srsoftware.oidc.web;
import static java.lang.System.Logger.Level.*;
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import com.sun.net.httpserver.HttpExchange;
@@ -36,14 +37,12 @@ public class StaticPages extends PathHandler {
relativePath = ex.getRequestURI().toString().endsWith(FAVICON) ? FAVICON : INDEX;
}
try {
System.out.printf("Loading %s for language %s…", relativePath, lang);
Response response = loadFile(lang, relativePath).orElseThrow(() -> new FileNotFoundException());
ex.getResponseHeaders().add(CONTENT_TYPE, response.contentType);
System.out.println("success.");
LOG.log(DEBUG,"Loaded {0} for language {1}…success.", relativePath, lang);
return sendContent(ex, response.content);
} catch (FileNotFoundException fnf) {
System.err.println("failed!");
LOG.log(WARNING,"Loaded {0} for language {1}…failed.", relativePath, lang);
return sendEmptyResponse(HTTP_NOT_FOUND, ex);
}
}

View File

@@ -8,8 +8,13 @@
<link rel="stylesheet" href="style.css" />
</head>
<body>
<nav></nav>
<h1>Authorization!</h1>
Not implemented, yet!
<nav></nav>
<div id="content" style="display: none">
<h1>Authorization</h1>
Confirmation required: are you shure you want to grant access to <span id="name">some client</span>?
<button type="button" onclick="grantAutorization()">Yes</button>
<button type="button" onclick="denyAutorization()">No</button>
</div>
<div id="error" class="error" style="display: none"></div>
</body>
</html>

View File

@@ -1,19 +1,46 @@
var params = new URLSearchParams(window.location.search)
var json = Object.fromEntries(params);
function showConfirmationDialog(name){
get('name').innerHTML = name;
show('content');
}
async function handleResponse(response){
if (response.ok){
var json = await response.json();
console.log(json);
redirect(json.redirect_uri+'?code='+json.code+'&state='+json.state);
console.log("handleResponse(ok) ←",json);
if (!json.confirmed){
showConfirmationDialog(json.name);
} else {
redirect(json.redirect_uri+'?code='+json.code+'&state='+json.state+'&scope=openid');
}
return;
} else {
var json = await response.json();
console.log("handleResponse(error) ←",json);
get('error').innerHTML = "Error: <br/>"+JSON.stringify(json);
show('error');
}
}
fetch(api+"/authorize",{
method: 'POST',
body: JSON.stringify(json),
headers: {
'Content-Type': 'application/json'
}
}).then(handleResponse);
function grantAutorization(){
json.confirmed = true;
backendAutorization();
}
function denyAutorization(){
redirect(params.get('redirect_uri')+"?error=access denied");
}
function backendAutorization(){
fetch(api+"/authorize",{
method: 'POST',
body: JSON.stringify(json),
headers: {
'Content-Type': 'application/json'
}
}).then(handleResponse);
}
backendAutorization();

View File

@@ -20,7 +20,6 @@ function getValue(id){
}
function hide(id){
console.log('hide('+id+')');
get(id).style.display = 'none';
}
@@ -38,6 +37,5 @@ function setValue(id,newVal){
}
function show(id){
console.log('show('+id+')');
get(id).style.display = '';
}

View File

@@ -29,5 +29,6 @@
</tr>
</table>
</fieldset>
<a href="https://umbrella.srsoftware.de/user/login">Umbrella</a>
</body>
</html>