<commit_before>/**
 * ***************************************************************
 * Agent.GUI is a framework to develop Multi-agent based simulation 
 * applications based on the JADE - Framework in compliance with the 
 * FIPA specifications. 
 * Copyright (C) 2010 <NAME> and DAWIS
 * http://www.dawis.wiwi.uni-due.de
 * http://sourceforge.net/projects/agentgui/
 * http://www.agentgui.org 
 *
 * GNU Lesser General Public License
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation,
 * version 2.1 of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 * **************************************************************
 */
package de.enflexit.oidc;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Window;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ProtocolException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Map;

import javax.net.ssl.HttpsURLConnection;
import javax.swing.JDialog;

import com.nimbusds.oauth2.sdk.ParseException;
import com.nimbusds.oauth2.sdk.token.AccessToken;

import de.enflexit.api.Translator;

/**
 * This class provides a simple interface to the OpenID Connect authorisation.
 * Use with getInstance(), getDialog()/connect() and getUserID().
 */
public class OIDCAuthorization {

	/** The claim representing the user ID in OIDC (subject) */
	private static final String OIDC_ID_CLAIM_USERID = "sub";

	/** The single instance of this singleton class. */
	private static OIDCAuthorization instance;

	/** The OIDC client. */
	private SimpleOIDCClient oidcClient;

	/** The accessed resource URI, initialized with @see OIDCPanel.DEBUG_RESOURCE_URI. */
	private String resourceURI = OIDCPanel.DEBUG_RESOURCE_URI;

	/** The URI of the OIDC provider/issuer. */
	private String issuerURI = "";

	/** The availability handler called when the resource is available. */
	private OIDCResourceAvailabilityHandler availabilityHandler;

	/** The URLProcessor used for the network communication. */
	private URLProcessor urlProcessor;

	/** The authorization dialog. */
	private JDialog authDialog;

	private String presetUsername;

	private Frame ownerFrame;
	
	private boolean inited = false;

	Translator translator;

	private File truststoreFile;

	private String lastSuccessfulUser = null;

	/**
	 * Instantiates a new OIDC authorization.
	 */
	private OIDCAuthorization() {
	}

	/**
	 * Gets the single instance of OIDCAuthorization.
	 *
	 * @return single instance of OIDCAuthorization
	 */
	public static OIDCAuthorization getInstance() {
		if (instance == null) {
			instance = new OIDCAuthorization();
		}
		return instance;
	}

	/**
	 * Gets the OIDC client.
	 * 
	 * @return the OIDC client
	 * @throws URISyntaxException
	 */
	public SimpleOIDCClient getOIDCClient() throws URISyntaxException {
		if (oidcClient == null) {
			oidcClient = new SimpleOIDCClient();
			oidcClient.setIssuerURI(getIssuerURI());
		}
		return oidcClient;
	}

	/**
	 * Gets the url processor.
	 *
	 * @return the url processor
	 * @throws IOException
	 * @throws URISyntaxException
	 * @throws ParseException
	 * @throws KeyStoreException 
	 * @throws CertificateException 
	 * @throws NoSuchAlgorithmException 
	 * @throws KeyManagementException 
	 */
	public URLProcessor getUrlProcessor() throws URISyntaxException, IOException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		if (urlProcessor == null) {
			init();
		}
		return urlProcessor;
	}

	/**
	 * Sets the trust store.
	 *
	 * @param truststoreFile the new trust store
	 * @throws URISyntaxException
	 */
	public void setTrustStore(File truststoreFile) throws URISyntaxException {
		this.truststoreFile=truststoreFile;
		getOIDCClient();
		oidcClient.setTrustStore(truststoreFile);
	}

	/**
	 * Sets the availability handler.
	 *
	 * @param availabilityHandler the availability handler
	 * @return the OIDC authorization
	 */
	public OIDCAuthorization setAvailabilityHandler(OIDCResourceAvailabilityHandler availabilityHandler) {
		this.availabilityHandler = availabilityHandler;
		return this;
	}

	/**
	 * Gets the issuer URI.
	 * 
	 * @return the issuer URI
	 */
	public String getIssuerURI() {
		return issuerURI;
	}

	/**
	 * Sets the issuer URI.
	 *
	 * @param issuerURI the new issuer URI
	 */
	public void setIssuerURI(String issuerURI) {
		this.issuerURI = issuerURI;
	}

	/**
	 * Gets the resource URI.
	 * 
	 * @return the resource URI
	 */
	public String getResourceURI() {

		return resourceURI;
	}

	/**
	 * Sets the resource URI.
	 *
	 * @param resourceURI the new resource URI
	 */
	public void setResourceURI(String resourceURI) {
		this.resourceURI = resourceURI;
	}

	/**
	 * Gets the client id.
	 * 
	 * @return the client id
	 */
	public String getClientID() {
		return OIDCPanel.DEBUG_CLIENT_ID;
	}

	/**
	 * Gets the client secret.
	 * 
	 * @return the client secret
	 */
	public String getClientSecret() {
		return OIDCPanel.DEBUG_CLIENT_SECRET;
	}

	/**
	 * Gets the authorization dialog (with null defaults).
	 *
	 * @return the dialog
	 */
	public JDialog getDialog() {
		if (authDialog == null) {
			authDialog = getDialog("", null);
		}
		return authDialog;
	}

	/**
	 * Gets the authorization dialog.
	 *
	 * @param presetUsername username which should be shown preset when displaying the dialog
	 * @param owner the window to which the dialog should belong (to center etc.)
	 * @return the dialog
	 */
	public JDialog getDialog(String presetUsername, Window owner) {

		authDialog = new JDialog(owner);
		OIDCPanel oidcPanel = new OIDCPanel(this);
		if (presetUsername != null) {
			oidcPanel.getJTextFieldUsername().setText(presetUsername);
		}
		authDialog.setContentPane(oidcPanel);
		authDialog.setSize(new Dimension(500, 190));
		authDialog.setLocationRelativeTo(null);
		return authDialog;
	}

	/**
	 * Checks if OIDC token is valid, so access has been granted.
	 *
	 * @return true, if is valid
	 * @throws URISyntaxException
	 */
	public boolean isValid() throws URISyntaxException {
		if (getOIDCClient().getAccessToken() != null) {
			return true;
		}
		return false;
	}

	/**
	 * Gets the unique ID of the user authenticated.
	 *
	 * @return the user ID
	 * @throws OIDCProblemException if the token is not valid/the user is not authenticated yet
	 * @throws URISyntaxException
	 */
	public String getUserID() throws OIDCProblemException, URISyntaxException {
		String userID;
		if (!isValid()) {
			throw new OIDCProblemException();
		}
		Map<String, Object> allClaims = getOIDCClient().getIdClaims().getClaims();
		userID = (String) allClaims.get(OIDC_ID_CLAIM_USERID);

		if (userID != null) {
			return userID;
		}
		return "";
	}

	/**
	 * Initiates the authorization process by setting the necessary URIs and data to the OIDC client and preparing the URLProcessor.
	 * 
	 * @throws URISyntaxException
	 * @throws IOException
	 * @throws ParseException
	 * @throws KeyStoreException 
	 * @throws CertificateException 
	 * @throws NoSuchAlgorithmException 
	 * @throws KeyManagementException 
	 */
	public void init() throws URISyntaxException, IOException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		getOIDCClient();
//		oidcClient.reset();
		urlProcessor = new URLProcessor();

		oidcClient.setIssuerURI(getIssuerURI());
		try {
			oidcClient.retrieveProviderMetadata();
			oidcClient.setClientMetadata(getResourceURI());
		} catch (ParseException e) {
			throw new IOException("OIDC ParseException");
		}
		oidcClient.setClientID(getClientID(), getClientSecret());
		oidcClient.setRedirectURI(getResourceURI());
		urlProcessor.prepare(oidcClient.getRedirectURI().toURL());
		inited = true;
	}

	/**
	 * Connect to the authorization server and get a valid token.
	 *
	 * @param username the username
	 * @param password the password
	 * @return true, if successful
	 * @throws IOException
	 * @throws URISyntaxException
	 * @throws ParseException
	 * @throws KeyStoreException 
	 * @throws CertificateException 
	 * @throws NoSuchAlgorithmException 
	 * @throws KeyManagementException 
	 */
	public boolean authorizeByUserAndPW(String username, String password) throws URISyntaxException, IOException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		String authRedirection = "";

		if (!inited) {
			init();
		}

		oidcClient.setResourceOwnerCredentials(username, password);
		oidcClient.requestToken();

		urlProcessor.setAccessToken(oidcClient.getAccessToken());

		authRedirection = urlProcessor.prepare(oidcClient.getRedirectURI().toURL()).process();
		if (authRedirection == null) { 	// authenticated
			lastSuccessfulUser = username;
			if (availabilityHandler != null) {
				availabilityHandler.onResourceAvailable(urlProcessor);
			}
			return true;
		} else {
			System.err.println("OIDC authorization failed");
			System.err.println("authRedirection=" + authRedirection);
			return false;
		}
	}

	/**
	 * Access some resource previously set by {@link #setResourceURI(String)}. If not accessible, show user/password dialog
	 *
	 * @return true, if successful
	 * @throws KeyStoreException 
	 * @throws CertificateException 
	 * @throws NoSuchAlgorithmException 
	 * @throws KeyManagementException 
	 */
	public boolean accessResource() throws IOException, URISyntaxException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		getUrlProcessor().prepare(new URL(getResourceURI()));
		String result = urlProcessor.process();
		if (result == null) {
			// all good (unlikely on first call)
			if (availabilityHandler != null) {
				availabilityHandler.onResourceAvailable(urlProcessor);
			}
			return true;
		} else {
			try {
				getOIDCClient().parseAuthenticationDataFromRedirect(result, false); // don't override clientID
			} catch (ParseException e) {
				throw new IOException("OIDC ParseException");
			}
			boolean showDialog = true;
			if (availabilityHandler != null) {
				showDialog = availabilityHandler.onAuthorizationNecessary(this);
			} 
			if(showDialog){
				getDialog(presetUsername, ownerFrame).setVisible(true);
			}
			return false;
		}
	}

	/**
	 * Access some resource like {@link #accessResource()}, but also provide the URL and presetUsername/ownerFrame for the dialog.
	 *
	 * @param url the url
	 * @param presetUsername the preset username
	 * @param ownerFrame the owner frame
	 * @throws URISyntaxException
	 * @throws IOException
	 * @throws ParseException
	 * @throws KeyStoreException 
	 * @throws CertificateException 
	 * @throws NoSuchAlgorithmException 
	 * @throws KeyManagementException 
	 */
	public boolean accessResource(String url, String presetUsername, Frame ownerFrame) throws IOException, URISyntaxException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		setResourceURI(url);
		this.presetUsername = presetUsername;
		this.ownerFrame = ownerFrame;

		return accessResource();
	}

	/**
	 * Sets the translator.
	 * @param translator the new translator
	 */
	public void setTranslator(Translator translator) {
		this.translator = translator;
	}

	/**
	 * Translate.
	 *
	 * @param oidcPanel the oidc panel
	 * @param input the input
	 * @return the string
	 */
	String translate(OIDCPanel oidcPanel, String input){
		if (translator!=null) {
			return translator.dynamicTranslate(input);
		}
		return input;
	}
<commit_msg>Fix license OIDC dialog issue<commit_after>/**
 * ***************************************************************
 * Agent.GUI is a framework to develop Multi-agent based simulation 
 * applications based on the JADE - Framework in compliance with the 
 * FIPA specifications. 
 * Copyright (C) 2010 <NAME> and DAWIS
 * http://www.dawis.wiwi.uni-due.de
 * http://sourceforge.net/projects/agentgui/
 * http://www.agentgui.org 
 *
 * GNU Lesser General Public License
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation,
 * version 2.1 of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 * **************************************************************
 */
package de.enflexit.oidc;

import java.awt.Dimension;
import java.awt.Window;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ProtocolException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Map;

import javax.net.ssl.HttpsURLConnection;
import javax.swing.JDialog;

import com.nimbusds.oauth2.sdk.ParseException;
import com.nimbusds.oauth2.sdk.token.AccessToken;

import de.enflexit.api.Translator;

/**
 * This class provides a simple interface to the OpenID Connect authorisation.
 * Use with getInstance(), getDialog()/connect() and getUserID().
 */
public class OIDCAuthorization {

	/** The claim representing the user ID in OIDC (subject) */
	private static final String OIDC_ID_CLAIM_USERID = "sub";

	/** The single instance of this singleton class. */
	private static OIDCAuthorization instance;

	/** The OIDC client. */
	private SimpleOIDCClient oidcClient;

	/** The accessed resource URI, initialized with @see OIDCPanel.DEBUG_RESOURCE_URI. */
	private String resourceURI = OIDCPanel.DEBUG_RESOURCE_URI;

	/** The URI of the OIDC provider/issuer. */
	private String issuerURI = "";

	/** The availability handler called when the resource is available. */
	private OIDCResourceAvailabilityHandler availabilityHandler;

	/** The URLProcessor used for the network communication. */
	private URLProcessor urlProcessor;

	/** The authorization dialog. */
	private JDialog authDialog;

	private String presetUsername;

	private Window owner;
	
	private boolean inited = false;

	Translator translator;

	private File truststoreFile;

	private String lastSuccessfulUser = null;

	/**
	 * Instantiates a new OIDC authorization.
	 */
	private OIDCAuthorization() {
	}

	/**
	 * Gets the single instance of OIDCAuthorization.
	 *
	 * @return single instance of OIDCAuthorization
	 */
	public static OIDCAuthorization getInstance() {
		if (instance == null) {
			instance = new OIDCAuthorization();
		}
		return instance;
	}

	/**
	 * Gets the OIDC client.
	 * 
	 * @return the OIDC client
	 * @throws URISyntaxException
	 */
	public SimpleOIDCClient getOIDCClient() throws URISyntaxException {
		if (oidcClient == null) {
			oidcClient = new SimpleOIDCClient();
			oidcClient.setIssuerURI(getIssuerURI());
		}
		return oidcClient;
	}

	/**
	 * Gets the url processor.
	 *
	 * @return the url processor
	 * @throws IOException
	 * @throws URISyntaxException
	 * @throws ParseException
	 * @throws KeyStoreException 
	 * @throws CertificateException 
	 * @throws NoSuchAlgorithmException 
	 * @throws KeyManagementException 
	 */
	public URLProcessor getUrlProcessor() throws URISyntaxException, IOException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		if (urlProcessor == null) {
			init();
		}
		return urlProcessor;
	}

	/**
	 * Sets the trust store.
	 *
	 * @param truststoreFile the new trust store
	 * @throws URISyntaxException
	 */
	public void setTrustStore(File truststoreFile) throws URISyntaxException {
		this.truststoreFile=truststoreFile;
		getOIDCClient();
		oidcClient.setTrustStore(truststoreFile);
	}

	/**
	 * Sets the availability handler.
	 *
	 * @param availabilityHandler the availability handler
	 * @return the OIDC authorization
	 */
	public OIDCAuthorization setAvailabilityHandler(OIDCResourceAvailabilityHandler availabilityHandler) {
		this.availabilityHandler = availabilityHandler;
		return this;
	}

	/**
	 * Gets the issuer URI.
	 * 
	 * @return the issuer URI
	 */
	public String getIssuerURI() {
		return issuerURI;
	}

	/**
	 * Sets the issuer URI.
	 *
	 * @param issuerURI the new issuer URI
	 */
	public void setIssuerURI(String issuerURI) {
		this.issuerURI = issuerURI;
	}

	/**
	 * Gets the resource URI.
	 * 
	 * @return the resource URI
	 */
	public String getResourceURI() {

		return resourceURI;
	}

	/**
	 * Sets the resource URI.
	 *
	 * @param resourceURI the new resource URI
	 */
	public void setResourceURI(String resourceURI) {
		this.resourceURI = resourceURI;
	}

	/**
	 * Gets the client id.
	 * 
	 * @return the client id
	 */
	public String getClientID() {
		return OIDCPanel.DEBUG_CLIENT_ID;
	}

	/**
	 * Gets the client secret.
	 * 
	 * @return the client secret
	 */
	public String getClientSecret() {
		return OIDCPanel.DEBUG_CLIENT_SECRET;
	}

	/**
	 * Gets the authorization dialog (with null defaults).
	 *
	 * @return the dialog
	 */
	public JDialog getDialog() {
		if (authDialog == null) {
			authDialog = getDialog("", null);
		}
		return authDialog;
	}

	/**
	 * Gets the authorization dialog.
	 *
	 * @param presetUsername username which should be shown preset when displaying the dialog
	 * @param owner the window to which the dialog should belong (to center etc.)
	 * @return the dialog
	 */
	public JDialog getDialog(String presetUsername, Window owner) {

		authDialog = new JDialog(owner);
		OIDCPanel oidcPanel = new OIDCPanel(this);
		if (presetUsername != null) {
			oidcPanel.getJTextFieldUsername().setText(presetUsername);
		}
		authDialog.setContentPane(oidcPanel);
		authDialog.setSize(new Dimension(500, 190));
		authDialog.setLocationRelativeTo(null);
		return authDialog;
	}

	/**
	 * Checks if OIDC token is valid, so access has been granted.
	 *
	 * @return true, if is valid
	 * @throws URISyntaxException
	 */
	public boolean isValid() throws URISyntaxException {
		if (getOIDCClient().getAccessToken() != null) {
			return true;
		}
		return false;
	}

	/**
	 * Gets the unique ID of the user authenticated.
	 *
	 * @return the user ID
	 * @throws OIDCProblemException if the token is not valid/the user is not authenticated yet
	 * @throws URISyntaxException
	 */
	public String getUserID() throws OIDCProblemException, URISyntaxException {
		String userID;
		if (!isValid()) {
			throw new OIDCProblemException();
		}
		Map<String, Object> allClaims = getOIDCClient().getIdClaims().getClaims();
		userID = (String) allClaims.get(OIDC_ID_CLAIM_USERID);

		if (userID != null) {
			return userID;
		}
		return "";
	}

	/**
	 * Initiates the authorization process by setting the necessary URIs and data to the OIDC client and preparing the URLProcessor.
	 * 
	 * @throws URISyntaxException
	 * @throws IOException
	 * @throws ParseException
	 * @throws KeyStoreException 
	 * @throws CertificateException 
	 * @throws NoSuchAlgorithmException 
	 * @throws KeyManagementException 
	 */
	public void init() throws URISyntaxException, IOException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		getOIDCClient();
//		oidcClient.reset();
		urlProcessor = new URLProcessor();

		oidcClient.setIssuerURI(getIssuerURI());
		try {
			oidcClient.retrieveProviderMetadata();
			oidcClient.setClientMetadata(getResourceURI());
		} catch (ParseException e) {
			throw new IOException("OIDC ParseException");
		}
		oidcClient.setClientID(getClientID(), getClientSecret());
		oidcClient.setRedirectURI(getResourceURI());
		urlProcessor.prepare(oidcClient.getRedirectURI().toURL());
		inited = true;
	}

	/**
	 * Connect to the authorization server and get a valid token.
	 *
	 * @param username the username
	 * @param password the password
	 * @return true, if successful
	 * @throws IOException
	 * @throws URISyntaxException
	 * @throws ParseException
	 * @throws KeyStoreException 
	 * @throws CertificateException 
	 * @throws NoSuchAlgorithmException 
	 * @throws KeyManagementException 
	 */
	public boolean authorizeByUserAndPW(String username, String password) throws URISyntaxException, IOException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		String authRedirection = "";

		if (!inited) {
			init();
		}

		oidcClient.setResourceOwnerCredentials(username, password);
		oidcClient.requestToken();

		urlProcessor.setAccessToken(oidcClient.getAccessToken());

		authRedirection = urlProcessor.prepare(oidcClient.getRedirectURI().toURL()).process();
		if (authRedirection == null) { 	// authenticated
			lastSuccessfulUser = username;
			if (availabilityHandler != null) {
				availabilityHandler.onResourceAvailable(urlProcessor);
			}
			return true;
		} else {
			System.err.println("OIDC authorization failed");
			System.err.println("authRedirection=" + authRedirection);
			return false;
		}
	}

	/**
	 * Access some resource previously set by {@link #setResourceURI(String)}. If not accessible, show user/password dialog
	 *
	 * @return true, if successful
	 * @throws KeyStoreException 
	 * @throws CertificateException 
	 * @throws NoSuchAlgorithmException 
	 * @throws KeyManagementException 
	 */
	public boolean accessResource() throws IOException, URISyntaxException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		getUrlProcessor().prepare(new URL(getResourceURI()));
		String result = urlProcessor.process();
		if (result == null) {
			// all good (unlikely on first call)
			if (availabilityHandler != null) {
				availabilityHandler.onResourceAvailable(urlProcessor);
			}
			return true;
		} else {
			try {
				getOIDCClient().parseAuthenticationDataFromRedirect(result, false); // don't override clientID
			} catch (ParseException e) {
				throw new IOException("OIDC ParseException");
			}
			boolean showDialog = true;
			if (availabilityHandler != null) {
				showDialog = availabilityHandler.onAuthorizationNecessary(this);
			} 
			if(showDialog){
				getDialog(presetUsername, owner).setVisible(true);
			}
			return false;
		}
	}
	
	/**
	 * Access some resource like {@link #accessResource()}, but also provide the presetUsername/owner for the dialog.
	 *
	 * @param url the url
	 * @param presetUsername the preset username
	 * @param owner the owner frame
	 * @throws URISyntaxException
	 * @throws IOException
	 * @throws ParseException
	 * @throws KeyStoreException 
	 * @throws CertificateException 
	 * @throws NoSuchAlgorithmException 
	 * @throws KeyManagementException 
	 */
	public boolean accessResource(String presetUsername, Window owner) throws IOException, URISyntaxException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		this.presetUsername = presetUsername;
		this.owner = owner;

		return accessResource();
	}

	/**
	 * Access some resource like {@link #accessResource()}, but also provide the URL and presetUsername/owner for the dialog.
	 *
	 * @param url the url
	 * @param presetUsername the preset username
	 * @param owner the owner frame
	 * @throws URISyntaxException
	 * @throws IOException
	 * @throws ParseException
	 * @throws KeyStoreException 
	 * @throws CertificateException 
	 * @throws NoSuchAlgorithmException 
	 * @throws KeyManagementException 
	 */
	public boolean accessResource(String url, String presetUsername, Window owner) throws IOException, URISyntaxException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		setResourceURI(url);

		return accessResource(presetUsername, owner);
	}

	/**
	 * Sets the translator.
	 * @param translator the new translator
	 */
	public void setTranslator(Translator translator) {
		this.translator = translator;
	}

	/**
	 * Translate.
	 *
	 * @param oidcPanel the oidc panel
	 * @param input the input
	 * @return the string
	 */
	String translate(OIDCPanel oidcPanel, String input){
		if (translator!=null) {
			return translator.dynamicTranslate(input);
		}
		return input;
	}

{'fraction_non_alphanumeric': 0.10183500751403939, 'fraction_numerical': 0.002214664241082022, 'mean_word_length': 4.260453505304764, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1700086', 'n_tokens_mistral': 7895, 'n_tokens_neox': 6971, 'n_words': 2104}