Skip to content
Snippets Groups Projects
Commit 078ea120 authored by Elisa Giglio's avatar Elisa Giglio
Browse files

prova

parent 6c15485e
No related branches found
No related tags found
No related merge requests found
Showing
with 75 additions and 5 deletions
File added
File added
File added
File added
File added
File added
File added
File added
#!/bin/bash
javac -cp .:./org.json-1.0.0.v201011060100.jar -d bin src/code/*
javac -cp .:./org.json-1.0.0.v201011060100.jar:./jar_files_for_KeyCloak/* -d bin src/code/*
echo 'server compiled'
cd bin
java -classpath .:../org.json-1.0.0.v201011060100.jar code.Server $1
java -classpath .:../org.json-1.0.0.v201011060100.jar:../jar_files_for_KeyCloak/* code.Server $1
package code;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.json.JSONException;
import org.json.JSONObject;
import org.keycloak.representations.AccessToken;
import org.keycloak.OAuthErrorException;
import org.keycloak.adapters.ServerRequest.HttpFailure;
import org.keycloak.adapters.installed.KeycloakInstalled;
import org.keycloak.common.VerificationException;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
public class Home implements HttpHandler {
private KeycloakInstalled kcs;
private AccessToken token;
public Home() {
kcs = null;
token = null;
}
// public Home() {
// String path = "../../webapp/public/keycloak.json";
// try {
// File f = new File(path);
// InputStream is = new FileInputStream(f);
// kcs = new KeycloakInstalled(is); // reads the configuration from InputStream
// kcs.loginDesktop(); // opens desktop browser
// token = kcs.getToken();
// } catch (FileNotFoundException e1) {
// // TODO Auto-generated catch block
// System.out.println("Unable to open file '" + path + "'");
// e1.printStackTrace();
// }
// catch (IOException | VerificationException | OAuthErrorException | URISyntaxException | HttpFailure
// | InterruptedException e) {
// e.printStackTrace();
// }
// }
@Override
public void handle(HttpExchange exchange) throws IOException {
// if(kcs==null && token==null) {
// kcs = new KeycloakInstalled(); // reads the configuration from classpath: META-INF/keycloak.json
// // keycloak.setLocale(Locale.ENGLISH);
// try {
// kcs.loginDesktop(); // opens desktop browser
// } catch (IOException | VerificationException | OAuthErrorException | URISyntaxException | HttpFailure
// | InterruptedException e) {
// e.printStackTrace();
// }
//
// token = kcs.getToken();
// }
if(token==null) {
String path = "../../webapp/public/keycloak.json";
try {
File f = new File(path);
InputStream is = new FileInputStream(f);
kcs = new KeycloakInstalled(is); // reads the configuration from InputStream
kcs.loginDesktop(); // opens desktop browser
token = kcs.getToken();
} catch (FileNotFoundException e1) {
System.out.println("Unable to open file '" + path + "'");
}
catch (IOException | VerificationException | OAuthErrorException | URISyntaxException | HttpFailure
| InterruptedException e) {
System.out.println("Error: "+ e.getMessage());
// e.printStackTrace();
}
}
System.out.println("keycloak object = "+ kcs);
System.out.println("Token = "+ kcs.getTokenString());
URI requestURI = exchange.getRequestURI();
boolean wantsHome = Helper.compareText(requestURI.toString(),URI.create("/").toString());
boolean wantsKeycloak = Helper.compareText(requestURI.toString(),URI.create("/keycloak.json").toString());
......
......@@ -7,7 +7,7 @@ import Secured from './authentication/secured.js';
// import { setToggleMovement } from "./toggles.js";
// launch each class
new Secured();
// new Secured();
new Sensori();
new Antifurto();
new Scenari();
......
......@@ -5,4 +5,4 @@
"resource": "myclient",
"public-client": true,
"confidential-port": 0
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment