Package org.mitre.oauth2.model

Examples of org.mitre.oauth2.model.SystemScope


  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

     * @throws IOException
     */
    private void readSystemScopes(JsonReader reader) throws IOException {
        reader.beginArray();
        while (reader.hasNext()) {
            SystemScope scope = new SystemScope();
            reader.beginObject();
            while (reader.hasNext()) {
                switch (reader.peek()) {
                    case END_OBJECT:
                        continue;
                    case NAME:
                        String name = reader.nextName();
                        if (reader.peek() == JsonToken.NULL) {
                            reader.skipValue();
                        } else if (name.equals("value")) {
                            scope.setValue(reader.nextString());
                        } else if (name.equals("description")) {
                            scope.setDescription(reader.nextString());
                        } else if (name.equals("allowDynReg")) {
                            scope.setAllowDynReg(reader.nextBoolean());
                        } else if (name.equals("defaultScope")) {
                            scope.setDefaultScope(reader.nextBoolean());
                        } else if (name.equals("icon")) {
                            scope.setIcon(reader.nextString());
                        } else {
                            logger.debug("found unexpected entry");
                            reader.skipValue();
                        }
                        break;
View Full Code Here

  }

  @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json")
  public String getScope(@PathVariable("id") Long id, ModelMap m) {

    SystemScope scope = scopeService.getById(id);

    if (scope != null) {

      m.put("entity", scope);
View Full Code Here

  @PreAuthorize("hasRole('ROLE_ADMIN')")
  @RequestMapping(value = "/{id}", method = RequestMethod.PUT, produces = "application/json", consumes = "application/json")
  public String updateScope(@PathVariable("id") Long id, @RequestBody String json, ModelMap m) {

    SystemScope existing = scopeService.getById(id);

    SystemScope scope = gson.fromJson(json, SystemScope.class);

    if (existing != null && scope != null) {

      if (existing.getId().equals(scope.getId())) {
        // sanity check

        scope = scopeService.save(scope);

        m.put("entity", scope);

        return JsonEntityView.VIEWNAME;
      } else {

        logger.error("updateScope failed; scope ids to not match: got "
            + existing.getId() + " and " + scope.getId());

        m.put("code", HttpStatus.BAD_REQUEST);
        m.put("errorMessage", "Could not update scope. Scope ids to not match: got "
            + existing.getId() + " and " + scope.getId());
        return JsonErrorView.VIEWNAME;
      }

    } else {
View Full Code Here

  }

  @PreAuthorize("hasRole('ROLE_ADMIN')")
  @RequestMapping(value = "", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
  public String createScope(@RequestBody String json, ModelMap m) {
    SystemScope scope = gson.fromJson(json, SystemScope.class);

    SystemScope alreadyExists = scopeService.getByValue(scope.getValue());
    if (alreadyExists != null) {
      //Error, cannot save a scope with the same value as an existing one
      logger.error("Error: attempting to save a scope with a value that already exists: " + scope.getValue());
      m.put("code", HttpStatus.CONFLICT);
      m.put("errorMessage", "A scope with value " + scope.getValue() + " already exists, please choose a different value.");
View Full Code Here

TOP

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

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.