Package org.mitre.oauth2.model

Examples of org.mitre.oauth2.model.RegisteredClient


    @Test
    public void shouldAssembleExpectedResultForRefreshTokenWithoutExpiry() {

        // given
        OAuth2RefreshTokenEntity refreshToken = refreshToken(null,
                authentication("name", request("clientId", scopes("foo""bar"))));

        UserInfo userInfo = userInfo("sub");

        // when
View Full Code Here


        given(accessToken.getAuthenticationHolder().getAuthentication()).willReturn(authentication);
        return accessToken;
    }

    private OAuth2RefreshTokenEntity refreshToken(Date exp, OAuth2Authentication authentication) {
        OAuth2RefreshTokenEntity refreshToken = mock(OAuth2RefreshTokenEntity.class, RETURNS_DEEP_STUBS);
        given(refreshToken.getExpiration()).willReturn(exp);
        given(refreshToken.getAuthenticationHolder().getAuthentication()).willReturn(authentication);
        return refreshToken;
    }
View Full Code Here

  @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

  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

    // 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

        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

      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

        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

    @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

  @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

TOP

Related Classes of org.mitre.oauth2.model.RegisteredClient

Copyright © 2018 www.massapicom. 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.