public String getRawResponse(Map m) { return getRawResponse(convertToStringRequest(host().toString(), m)); }
protected String getRTResponse(URI uri, RefreshToken refreshToken, Client client) { HashMap map = new HashMap(); map.put(OA2Constants.GRANT_TYPE, OA2Constants.REFRESH_TOKEN); map.put(OA2Constants.REFRESH_TOKEN, refreshToken.getToken()); map.put(OA2Constants.CLIENT_ID, client.getIdentifierString()); map.put(OA2Constants.CLIENT_SECRET, client.getSecret()); map.put(OA2Constants.SCOPE, "edu.uiuc.ncsa.myproxy"); String response = getServiceClient().getRawResponse(map); return response; }
@Override public void doIt() throws Exception { HashMap<String, String> map = new HashMap<>(); map.put(AbstractServlet.PING_PARAMETER, ""); info("Making initial request to service at " + serviceClient.host()); try { // Quick comment: In the service client, a response with HTML status code of 204 (status=ok, no body) is // processed and if correct, returns a raw response of length zero. If another code occurs and there is // no body, then an exception is raised. This is why the check below is the right one for the current case. String response = serviceClient.getRawResponse(map); if (response.length() == 0) { // then all is ok. Maybe do some logging info("ping ok"); } else { // moar logging warn("Ping failed to server " + serviceClient.host() + ". This ping works against servers that are version 3.0 or higher."); System.exit(1); } } catch (Throwable t) { error("ping failed to server " + serviceClient.host(), t); System.exit(1); } // From here on down is the older version for servers that do not support the ping command. }
public TokenAwareServer(ServiceClient serviceClient, String wellKnown) { super(serviceClient.host()); this.serviceClient = serviceClient; this.wellKnown = wellKnown; }
@Override public DelegationResponse processDelegationRequest(DelegationRequest delegationRequest) { DelegationResponse delResp = new DelegationResponse(null); Map<String,String> m = delegationRequest.getParameters(); m.put(OA2Constants.CLIENT_ID, delegationRequest.getClient().getIdentifierString()); m.put(OA2Constants.REDIRECT_URI, delegationRequest.getParameters().get(OA2Constants.REDIRECT_URI)); URI authZUri = ((AGServer2)getAgServer()).getServiceClient().host(); URI redirectURI = URI.create(ServiceClient.convertToStringRequest(authZUri.toString(), m)); delResp.setParameters(m); //send them all back. delResp.setRedirectUri(redirectURI); return delResp; }
public ServiceClient createServiceClient(URI host) { return new ServiceClient(host, getSSLConfiguration()); }
public static String convertToStringRequest(String host, Map m) { int size = m.size(); int i = 0; String[][] strings = new String[size][2]; for (Object o : m.keySet()) { Object v = m.get(o); if (v != null) { strings[i][0] = o.toString(); strings[i++][1] = v.toString(); } } return convertToStringRequest(host, strings); }
public static String convertToStringRequest(String host, String[][] args) { //String getString = host().toString(); String getString = host; boolean firstPass = true; if (args != null && args.length != 0) { for (int i = 0; i < args.length; i++) { if (args[i].length != 0) { try { // We have to encode the string to UTF-8 since we are doing an http GET. // The HTML spec says non-ASCII characters must be escaped some way, but // is not specific, so we have to do this. // Other than this case, // we should not be decoding anything since UTF-8 is the encoding set in the response. getString = getString + (firstPass ? "?" : "&") + args[i][0] + "=" + encode(args[i][1]); if (firstPass) firstPass = false; } catch (UnsupportedEncodingException e) { throw new GeneralException("Error encoding argument", e); } } } } return getString; }
/** * Gets asset * * @param client Client ID * @param props Map of properties * @param accessToken Access token * @return asset */ protected PAResponse getAsset(Client client, Map props, AccessToken accessToken) { HashMap m = new HashMap(); m.put(OA2Constants.ACCESS_TOKEN, accessToken.getToken().toString()); m.put(OA2Constants.CLIENT_ID, client.getIdentifierString()); m.put(OA2Constants.CLIENT_SECRET, client.getSecret()); m.put(OA2Constants.REDIRECT_URI, props.get(OA2Constants.REDIRECT_URI)); m.put(OA2Constants.CERT_REQ, String.valueOf(props.get(AbstractClientEnvironment.CERT_REQUEST_KEY))); m.put(OA2Constants.CERT_LIFETIME, String.valueOf(props.get(AbstractClientEnvironment.CERT_LIFETIME_KEY))); String response = getServiceClient().getRawResponse(m); // No JSON in the spec. Just a string of certs. MyX509Certificates myX509Certificate = null; try { myX509Certificate = new MyX509Certificates(CertUtil.fromX509PEM(response)); } catch (CertificateException e) { e.printStackTrace(); } PAResponse par = new PAResponse(myX509Certificate); return par; } }
public PAServer2(ServiceClient serviceClient) { super(serviceClient.host()); this.serviceClient = serviceClient; }
/** * Create a basic {@link ServiceClient} to get the keys from the well known page. If you require a special * setup (e.g. your own SSL certs), you will need to create your own ServiceClient and supply that in the * related call getJSONWebKeys(ServiceClient, String wellKnown). * @param wellKnown * @return */ public static JSONWebKeys getJsonWebKeys(String wellKnown) { if(wellKnown == null || wellKnown.isEmpty()){ throw new GeneralException("Error: missing well known URI. Cannot get keys"); } ServiceClient serviceClient = new ServiceClient(URI.create(wellKnown)); return getJsonWebKeys(serviceClient, wellKnown); }
/** * Processes UserInfo request * * @param uiRequest User info request * @return User Info response */ public UIResponse processUIRequest(UIRequest uiRequest) { HashMap m = new HashMap(); m.put(OA2Constants.ACCESS_TOKEN, uiRequest.getAccessToken().getToken()); String response = getServiceClient().getRawResponse(m); return new UIResponse(uiRequest.getAccessToken(), response); } }
public AGServer2(ServiceClient serviceClient) { super(serviceClient.host()); this.serviceClient = serviceClient; }
wellKnown = inputLine.getArg(1); try { keys = JWTUtil.getJsonWebKeys(new ServiceClient(URI.create("https://scitokens.org")), wellKnown); }catch(Throwable t){ t.printStackTrace();
public static JSONWebKeys getJsonWebKeys(ServiceClient serviceClient, String wellKnown) { if(serviceClient == null){ throw new GeneralException("Error: Missing service client."); } if(wellKnown == null || wellKnown.isEmpty()){ throw new GeneralException("Error: missing well known URI. Cannot get keys"); } // Fix for OAUTH-164, id_token support follows. String rawResponse = serviceClient.getRawResponse(wellKnown); JSON rawJSON = JSONSerializer.toJSON(rawResponse); if (!(rawJSON instanceof JSONObject)) { throw new IllegalStateException("Error: Attempted to get JSON Object but returned result is not JSON"); } JSONObject json = (JSONObject) rawJSON; String rawKeys = serviceClient.getRawResponse(json.getString("jwks_uri")); JSONWebKeys keys = null; JSONObject claims = null; try { keys = JSONWebKeyUtil.fromJSON(rawKeys); } catch (Throwable e) { throw new GeneralException("Error getting keys", e); } return keys; } /** Strictly for testing.
public UIServer2(ServiceClient serviceClient) { super(serviceClient.host()); this.serviceClient = serviceClient; }
m.put(OA2Constants.NONCE, nonce); m.put(OA2Constants.PROMPT, OA2Constants.PROMPT_LOGIN); String responseString = getServiceClient().getRawResponse(m);
String response = getServiceClient().getRawResponse(m); JSONObject jsonObject = getAndCheckResponse(response); if (!jsonObject.containsKey(ACCESS_TOKEN)) {