Examples of RegisteredClient


Examples of org.mitre.oauth2.model.RegisteredClient

  @Test
  public void getClientConfiguration_useStatic() {

    Mockito.when(mockStaticService.getClientConfiguration(mockServerConfig)).thenReturn(mockClient);

    RegisteredClient result = hybridService.getClientConfiguration(mockServerConfig);

    Mockito.verify(mockStaticService).getClientConfiguration(mockServerConfig);
    Mockito.verify(mockDynamicService, Mockito.never()).getClientConfiguration(Matchers.any(ServerConfiguration.class));
    assertEquals(mockClient, result);
  }
View Full Code Here

Examples of org.mitre.oauth2.model.RegisteredClient

  public void getClientConfiguration_useDynamic() {

    Mockito.when(mockStaticService.getClientConfiguration(mockServerConfig)).thenReturn(null);
    Mockito.when(mockDynamicService.getClientConfiguration(mockServerConfig)).thenReturn(mockClient);

    RegisteredClient result = hybridService.getClientConfiguration(mockServerConfig);

    Mockito.verify(mockStaticService).getClientConfiguration(mockServerConfig);
    Mockito.verify(mockDynamicService).getClientConfiguration(mockServerConfig);
    assertEquals(mockClient, result);
  }
View Full Code Here

Examples of org.mitre.oauth2.model.RegisteredClient

    // But oh noes! We're going to ask it to find us some other issuer
    ServerConfiguration badIssuer = Mockito.mock(ServerConfiguration.class);
    Mockito.when(badIssuer.getIssuer()).thenReturn("www.badexample.com");

    RegisteredClient result = hybridService.getClientConfiguration(badIssuer);

    Mockito.verify(mockStaticService).getClientConfiguration(badIssuer);
    Mockito.verify(mockDynamicService).getClientConfiguration(badIssuer);
    assertThat(result, is(nullValue()));
  }
View Full Code Here

Examples of org.mitre.oauth2.model.RegisteredClient

        OAuth2AccessTokenEntity token = connectTokenService.createResourceAccessToken(savedClient);
        tokenService.saveAccessToken(token);

        // send it all out to the view

        RegisteredClient registered = new RegisteredClient(savedClient, token.getValue(), config.getIssuer() + "resource/" + UriUtils.encodePathSegment(savedClient.getClientId(), "UTF-8"));
        m.addAttribute("client", registered);
        m.addAttribute("code", HttpStatus.CREATED); // http 201

        return ClientInformationResponseView.VIEWNAME;
      } catch (UnsupportedEncodingException e) {
View Full Code Here

Examples of org.mitre.oauth2.model.RegisteredClient

      try {
        // possibly update the token
        OAuth2AccessTokenEntity token = fetchValidRegistrationToken(auth, client);

        RegisteredClient registered = new RegisteredClient(client, token.getValue(), config.getIssuer() + "resource/" +  UriUtils.encodePathSegment(client.getClientId(), "UTF-8"));

        // send it all out to the view
        m.addAttribute("client", registered);
        m.addAttribute("code", HttpStatus.OK); // http 200
View Full Code Here

Examples of org.mitre.oauth2.model.RegisteredClient

        ClientDetailsEntity savedClient = clientService.updateClient(oldClient, newClient);

        // possibly update the token
        OAuth2AccessTokenEntity token = fetchValidRegistrationToken(auth, savedClient);

        RegisteredClient registered = new RegisteredClient(savedClient, token.getValue(), config.getIssuer() + "resource/" + UriUtils.encodePathSegment(savedClient.getClientId(), "UTF-8"));

        // send it all out to the view
        m.addAttribute("client", registered);
        m.addAttribute("code", HttpStatus.OK); // http 200
View Full Code Here

Examples of org.mitre.oauth2.model.RegisteredClient

    @Override
    public RegisteredClient load(ServerConfiguration serverConfig) throws Exception {
      RestTemplate restTemplate = new RestTemplate(httpFactory);


      RegisteredClient knownClient = registeredClientService.getByIssuer(serverConfig.getIssuer());
      if (knownClient == null) {

        // dynamically register this client
        JsonObject jsonRequest = ClientDetailsEntityJsonProcessor.serialize(template);
        String serializedClient = gson.toJson(jsonRequest);

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setAccept(Lists.newArrayList(MediaType.APPLICATION_JSON));

        HttpEntity<String> entity = new HttpEntity<String>(serializedClient, headers);

        String registered = restTemplate.postForObject(serverConfig.getRegistrationEndpointUri(), entity, String.class);
        // TODO: handle HTTP errors

        RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);

        // save this client for later
        registeredClientService.save(serverConfig.getIssuer(), client);

        return client;
      } else {

        if (knownClient.getClientId() == null) {
       
          // load this client's information from the server
          HttpHeaders headers = new HttpHeaders();
          headers.set("Authorization", String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, knownClient.getRegistrationAccessToken()));
          headers.setAccept(Lists.newArrayList(MediaType.APPLICATION_JSON));
 
          HttpEntity<String> entity = new HttpEntity<String>(headers);
 
          String registered = restTemplate.exchange(knownClient.getRegistrationClientUri(), HttpMethod.GET, entity, String.class).getBody();
          // TODO: handle HTTP errors
 
          RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);
 
          return client;
        } else {
          // it's got a client ID from the store, don't bother trying to load it
          return knownClient;
View Full Code Here

Examples of org.mitre.oauth2.model.RegisteredClient

  @Override
  protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {

    response.setContentType("application/json");

    RegisteredClient c = (RegisteredClient) model.get("client");
    //OAuth2AccessTokenEntity token = (OAuth2AccessTokenEntity) model.get("token");
    //String uri = (String)model.get("uri"); //request.getRequestURL() + "/" + c.getClientId();

    HttpStatus code = (HttpStatus) model.get("code");
    if (code == null) {
View Full Code Here

Examples of org.mitre.oauth2.model.RegisteredClient

  // sucess, false otherwise.
  private boolean parseToken(String accessToken) {

    // find out which URL to ask
    String introspectionUrl;
    RegisteredClient client;
    try {
      introspectionUrl = introspectionConfigurationService.getIntrospectionUrl(accessToken);
      client = introspectionConfigurationService.getClientConfiguration(accessToken);
    } catch (IllegalArgumentException e) {
      logger.error("Unable to load introspection URL or client configuration", e);
      return false;
    }
    // Use the SpringFramework RestTemplate to send the request to the
    // endpoint
    String validatedToken = null;

    RestTemplate restTemplate;
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();

    final String clientId = client.getClientId();
    final String clientSecret = client.getClientSecret();

    if (SECRET_BASIC.equals(client.getTokenEndpointAuthMethod())){
      // use BASIC auth if configured to do so
      restTemplate = new RestTemplate(factory) {

        @Override
        protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException {
View Full Code Here

Examples of org.mitre.oauth2.model.RegisteredClient

        "   \"contacts\": [\"ve7jtb@example.org\", \"mary@example.org\"],\n" +
        "   \"request_uris\":\n" +
        "     [\"https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA\"]\n" +
        "  }";

    RegisteredClient c = ClientDetailsEntityJsonProcessor.parseRegistered(json);


    assertEquals("s6BhdRkqt3", c.getClientId());
    assertEquals("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk", c.getClientSecret());
    assertEquals(new Date(1577858400L * 1000L), c.getClientSecretExpiresAt());
    assertEquals("this.is.an.access.token.value.ffx83", c.getRegistrationAccessToken());
    assertEquals("https://server.example.com/connect/register?client_id=s6BhdRkqt3", c.getRegistrationClientUri());
    assertEquals(ClientDetailsEntity.AppType.WEB, c.getApplicationType());
    assertEquals(ImmutableSet.of("https://client.example.org/callback", "https://client.example.org/callback2"), c.getRedirectUris());
    assertEquals("My Example", c.getClientName());
    assertEquals(ImmutableSet.of("code", "token"), c.getResponseTypes());
    assertEquals(ImmutableSet.of("authorization_code", "implicit"), c.getGrantTypes());
    assertEquals("https://client.example.org/logo.png", c.getLogoUri());
    assertEquals(ClientDetailsEntity.SubjectType.PAIRWISE, c.getSubjectType());
    assertEquals("https://other.example.net/file_of_redirect_uris.json", c.getSectorIdentifierUri());
    assertEquals(ClientDetailsEntity.AuthMethod.SECRET_BASIC, c.getTokenEndpointAuthMethod());
    assertEquals("https://client.example.org/my_public_keys.jwks", c.getJwksUri());
    assertEquals(JWEAlgorithm.RSA1_5, c.getUserInfoEncryptedResponseAlg());
    assertEquals(EncryptionMethod.A128CBC_HS256, c.getUserInfoEncryptedResponseEnc());
    assertEquals(ImmutableSet.of("ve7jtb@example.org", "mary@example.org"), c.getContacts());
    assertEquals(ImmutableSet.of("https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA"), c.getRequestUris());

  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.