@Test public void testGetServerUsingURL() { AMIdentity id = PowerMockito.mock(AMIdentity.class); PowerMockito.mockStatic(OAuth2Utils.class); when(OAuth2Utils.getRequestParameter(any(Request.class), eq("resource"), any(Class.class))) .thenReturn("http: when(OAuth2Utils.getRequestParameter(any(Request.class), eq("rel"), any(Class.class))) .thenReturn("http: when(OAuth2Utils.getIdentity(any(String.class), any(String.class))).thenReturn(id); when(OAuth2Utils.getRealm(any(Request.class))).thenReturn("/"); when(OAuth2Utils.getDeploymentURL(any(Request.class))) .thenReturn("http: OpenIDConnectDiscovery test = new OpenIDConnectDiscovery(); Representation r = test.discovery(); Map<String, Object> response = new HashMap<String, Object>(); response.put("subject", "http: Set<Object> set = new HashSet<Object>(); Map<String, Object> objectMap = new HashMap<String, Object>(); objectMap.put("rel", "http: objectMap.put("href", "http: set.add(objectMap); response.put("links",set); JsonRepresentation expected = new JsonRepresentation(response); assert(r.equals(expected)); }
@Get public Representation discovery(){ String resource = OAuth2Utils.getRequestParameter(getRequest(), "resource", String.class); String rel = OAuth2Utils.getRequestParameter(getRequest(), "rel", String.class); String realm = OAuth2Utils.getRealm(getRequest()); if (resource == null || resource.isEmpty()){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::No resource provided in discovery."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::No resource provided in discovery."); } if (rel == null || rel.isEmpty() || !rel.equalsIgnoreCase("http: OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::No or invalid rel provided in discovery."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::No or invalid rel provided in discovery."); } String userid = null; try { URI object = new URI(resource); if (object.getScheme().equalsIgnoreCase("https") || object.getScheme().equalsIgnoreCase("http")){ if (object.getPath().isEmpty()){ } else { userid = object.getPath(); userid = userid.substring(1,userid.length()); } } else if (object.getScheme().equalsIgnoreCase("acct")) { String s = new String(resource); s = s.replaceFirst("acct:", ""); int firstAt = s.indexOf('@'); userid = s.substring(0,firstAt); } else { OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } } catch (Exception e){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters.", e); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } if (userid != null){ AMIdentity id = null; try { id = OAuth2Utils.getIdentity(userid, realm); } catch (Exception e){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters.", e); throw OAuthProblemException.OAuthError.NOT_FOUND.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } if (id == null){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters."); throw OAuthProblemException.OAuthError.NOT_FOUND.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } } Map<String, Object> response = new HashMap<String, Object>(); response.put("subject", resource); Set<Object> set = new HashSet<Object>(); Map<String, Object> objectMap = new HashMap<String, Object>(); objectMap.put("rel", rel); objectMap.put("href", OAuth2Utils.getDeploymentURL(getRequest())); set.add(objectMap); response.put("links",set); return new JsonRepresentation(response); }
OpenIDConnectDiscovery extends ServerResource { @Get public Representation discovery(){ String resource = OAuth2Utils.getRequestParameter(getRequest(), "resource", String.class); String rel = OAuth2Utils.getRequestParameter(getRequest(), "rel", String.class); String realm = OAuth2Utils.getRealm(getRequest()); if (resource == null || resource.isEmpty()){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::No resource provided in discovery."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::No resource provided in discovery."); } if (rel == null || rel.isEmpty() || !rel.equalsIgnoreCase("http: OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::No or invalid rel provided in discovery."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::No or invalid rel provided in discovery."); } String userid = null; try { URI object = new URI(resource); if (object.getScheme().equalsIgnoreCase("https") || object.getScheme().equalsIgnoreCase("http")){ if (object.getPath().isEmpty()){ } else { userid = object.getPath(); userid = userid.substring(1,userid.length()); } } else if (object.getScheme().equalsIgnoreCase("acct")) { String s = new String(resource); s = s.replaceFirst("acct:", ""); int firstAt = s.indexOf('@'); userid = s.substring(0,firstAt); } else { OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } } catch (Exception e){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters.", e); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } if (userid != null){ AMIdentity id = null; try { id = OAuth2Utils.getIdentity(userid, realm); } catch (Exception e){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters.", e); throw OAuthProblemException.OAuthError.NOT_FOUND.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } if (id == null){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters."); throw OAuthProblemException.OAuthError.NOT_FOUND.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } } Map<String, Object> response = new HashMap<String, Object>(); response.put("subject", resource); Set<Object> set = new HashSet<Object>(); Map<String, Object> objectMap = new HashMap<String, Object>(); objectMap.put("rel", rel); objectMap.put("href", OAuth2Utils.getDeploymentURL(getRequest())); set.add(objectMap); response.put("links",set); return new JsonRepresentation(response); } }
OpenIDConnectDiscovery extends ServerResource { @Get public Representation discovery(){ String resource = OAuth2Utils.getRequestParameter(getRequest(), "resource", String.class); String rel = OAuth2Utils.getRequestParameter(getRequest(), "rel", String.class); String realm = OAuth2Utils.getRealm(getRequest()); if (resource == null || resource.isEmpty()){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::No resource provided in discovery."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::No resource provided in discovery."); } if (rel == null || rel.isEmpty() || !rel.equalsIgnoreCase("http: OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::No or invalid rel provided in discovery."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::No or invalid rel provided in discovery."); } String userid = null; try { URI object = new URI(resource); if (object.getScheme().equalsIgnoreCase("https") || object.getScheme().equalsIgnoreCase("http")){ if (object.getPath().isEmpty()){ } else { userid = object.getPath(); userid = userid.substring(1,userid.length()); } } else if (object.getScheme().equalsIgnoreCase("acct")) { String s = new String(resource); s = s.replaceFirst("acct:", ""); int firstAt = s.indexOf('@'); userid = s.substring(0,firstAt); } else { OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } } catch (Exception e){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters.", e); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } if (userid != null){ AMIdentity id = null; try { id = OAuth2Utils.getIdentity(userid, realm); } catch (Exception e){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters.", e); throw OAuthProblemException.OAuthError.NOT_FOUND.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } if (id == null){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters."); throw OAuthProblemException.OAuthError.NOT_FOUND.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } } Map<String, Object> response = new HashMap<String, Object>(); response.put("subject", resource); Set<Object> set = new HashSet<Object>(); Map<String, Object> objectMap = new HashMap<String, Object>(); objectMap.put("rel", rel); objectMap.put("href", OAuth2Utils.getDeploymentURL(getRequest())); set.add(objectMap); response.put("links",set); return new JsonRepresentation(response); }  }
OpenIDConnectDiscovery extends ServerResource { @Get public Representation discovery(){ String resource = OAuth2Utils.getRequestParameter(getRequest(), "resource", String.class); String rel = OAuth2Utils.getRequestParameter(getRequest(), "rel", String.class); String realm = OAuth2Utils.getRealm(getRequest()); if (resource == null || resource.isEmpty()){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::No resource provided in discovery."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::No resource provided in discovery."); } if (rel == null || rel.isEmpty() || !rel.equalsIgnoreCase("http: OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::No or invalid rel provided in discovery."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::No or invalid rel provided in discovery."); } String userid = null; try { URI object = new URI(resource); if (object.getScheme().equalsIgnoreCase("https") || object.getScheme().equalsIgnoreCase("http")){ if (object.getPath().isEmpty()){ } else { userid = object.getPath(); userid = userid.substring(1,userid.length()); } } else if (object.getScheme().equalsIgnoreCase("acct")) { String s = new String(resource); s = s.replaceFirst("acct:", ""); int firstAt = s.indexOf('@'); userid = s.substring(0,firstAt); } else { OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } } catch (Exception e){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters.", e); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } if (userid != null){ AMIdentity id = null; try { id = OAuth2Utils.getIdentity(userid, realm); } catch (Exception e){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters.", e); throw OAuthProblemException.OAuthError.NOT_FOUND.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } if (id == null){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters."); throw OAuthProblemException.OAuthError.NOT_FOUND.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } } Map<String, Object> response = new HashMap<String, Object>(); response.put("subject", resource); Set<Object> set = new HashSet<Object>(); Map<String, Object> objectMap = new HashMap<String, Object>(); objectMap.put("rel", rel); objectMap.put("href", OAuth2Utils.getDeploymentURL(getRequest())); set.add(objectMap); response.put("links",set); return new JsonRepresentation(response); }  @Get Representation discovery(); }
OpenIDConnectDiscovery extends ServerResource { @Get public Representation discovery(){ String resource = OAuth2Utils.getRequestParameter(getRequest(), "resource", String.class); String rel = OAuth2Utils.getRequestParameter(getRequest(), "rel", String.class); String realm = OAuth2Utils.getRealm(getRequest()); if (resource == null || resource.isEmpty()){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::No resource provided in discovery."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::No resource provided in discovery."); } if (rel == null || rel.isEmpty() || !rel.equalsIgnoreCase("http: OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::No or invalid rel provided in discovery."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::No or invalid rel provided in discovery."); } String userid = null; try { URI object = new URI(resource); if (object.getScheme().equalsIgnoreCase("https") || object.getScheme().equalsIgnoreCase("http")){ if (object.getPath().isEmpty()){ } else { userid = object.getPath(); userid = userid.substring(1,userid.length()); } } else if (object.getScheme().equalsIgnoreCase("acct")) { String s = new String(resource); s = s.replaceFirst("acct:", ""); int firstAt = s.indexOf('@'); userid = s.substring(0,firstAt); } else { OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters."); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } } catch (Exception e){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters.", e); throw OAuthProblemException.OAuthError.BAD_REQUEST.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } if (userid != null){ AMIdentity id = null; try { id = OAuth2Utils.getIdentity(userid, realm); } catch (Exception e){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters.", e); throw OAuthProblemException.OAuthError.NOT_FOUND.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } if (id == null){ OAuth2Utils.DEBUG.error("OpenIDConnectDiscovery.discover()::Invalid parameters."); throw OAuthProblemException.OAuthError.NOT_FOUND.handle(null, "OpenIDConnectDiscovery.discover()::Invalid parameters."); } } Map<String, Object> response = new HashMap<String, Object>(); response.put("subject", resource); Set<Object> set = new HashSet<Object>(); Map<String, Object> objectMap = new HashMap<String, Object>(); objectMap.put("rel", rel); objectMap.put("href", OAuth2Utils.getDeploymentURL(getRequest())); set.add(objectMap); response.put("links",set); return new JsonRepresentation(response); }  @Get Representation discovery();  }