I have tried to add:
org.keycloak.representations.IDToken idToken = principal.getKeycloakSecurityContext().getIdToken();
org.keycloak.representations.AccessToken token = principal.getKeycloakSecurityContext().getToken();
writer.write("<br/>Access Token id: " + token.getId());
writer.write("<br/>Access Token String: " + principal.getKeycloakSecurityContext().getTokenString());
writer.write("<br/>ID Token id: " + idToken.getId());
writer.write("<br/>ID Token String: " + principal.getKeycloakSecurityContext().getIdTokenString());
writer.write(String.format("<br/><a href=\"/multitenant/%s/logout\">Logout</a>", realm));
try
{
java.net.URL url = new java.net.URL( "
http://localhost:8080/auth/admin/realms/" + principal.getKeycloakSecurityContext().getRealm() + "/roles" );
java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection();
conn.setRequestMethod( "GET" );
conn.setRequestProperty("Authorization", "Bearer " + principal.getKeycloakSecurityContext().getTokenString());
java.io.BufferedReader in = new java.io.BufferedReader( new java.io.InputStreamReader( conn.getInputStream()));
String line;
while ((line = in.readLine()) != null)
{
writer.write( line );
}
in.close();
}
catch( Exception e )
{
e.printStackTrace();
}
to keycloak-demo-1.3.1.Final/examples/multi-tenant/src/main/java/org/keycloak/example/multitenant/boundary/ProtectedServlet.java