Package org.mitre.oauth2.model

Examples of org.mitre.oauth2.model.RegisteredClient


        // save the client
        ClientDetailsEntity savedClient = clientService.updateClient(oldClient, newClient);

        OAuth2AccessTokenEntity token = fetchValidRegistrationToken(auth, savedClient);

        RegisteredClient registered = new RegisteredClient(savedClient, token.getValue(), config.getIssuer() + "register/" + 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


  }

  @Test
  public void getClientConfiguration_success() {

    RegisteredClient result = service.getClientConfiguration(mockServerConfig);

    assertThat(mockClient, is(notNullValue()));
    assertEquals(mockClient, result);
  }
View Full Code Here

   */
  @Test
  public void getClientConfiguration_noIssuer() {
    Mockito.when(mockServerConfig.getIssuer()).thenReturn("www.badexample.net");

    RegisteredClient actualClient = service.getClientConfiguration(mockServerConfig);

    assertThat(actualClient, is(nullValue()));
  }
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

  }

  @PreAuthorize("hasRole('ROLE_ADMIN')")
  @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  public String deleteScope(@PathVariable("id") Long id, ModelMap m) {
    SystemScope existing = scopeService.getById(id);

    if (existing != null) {

      scopeService.remove(existing);
View Full Code Here

  public void prepare() {

    Mockito.reset(repository);

    // two default and dynamically registerable scopes
    defaultDynScope1 = new SystemScope(defaultDynScope1String);
    defaultDynScope2 = new SystemScope(defaultDynScope2String);
    defaultDynScope1.setAllowDynReg(true);
    defaultDynScope2.setAllowDynReg(true);
    defaultDynScope1.setDefaultScope(true);
    defaultDynScope2.setDefaultScope(true);

    // two strictly default scopes (isAllowDynReg false)
    defaultScope1 = new SystemScope(defaultScope1String);
    defaultScope2 = new SystemScope(defaultScope2String);
    defaultScope1.setDefaultScope(true);
    defaultScope2.setDefaultScope(true);

    // one strictly dynamically registerable scope (isDefault false)
    dynScope1 = new SystemScope(dynScope1String);
    dynScope1.setAllowDynReg(true);

    // extraScope1 : extra scope that is neither (defaults to false/false)
    extraScope1 = new SystemScope(extraScope1String);

    // structuredScope1 : structured scope
    structuredScope1 = new SystemScope(structuredScope1String);
    structuredScope1.setStructured(true);

    // structuredScope1Value : structured scope with value
    structuredScope1Value = new SystemScope(structuredScope1String);
    structuredScope1Value.setStructured(true);
    structuredScope1Value.setStructuredValue(structuredValue);

    allScopes = Sets.newHashSet(defaultDynScope1, defaultDynScope2, defaultScope1, defaultScope2, dynScope1, extraScope1, structuredScope1, structuredScope1Value);
    allScopeStrings = Sets.newHashSet(defaultDynScope1String, defaultDynScope2String, defaultScope1String, defaultScope2String, dynScope1String, extraScope1String, structuredScope1String, structuredScope1String + ":" + structuredValue);

    Mockito.when(repository.getByValue(defaultDynScope1String)).thenReturn(defaultDynScope1);
    Mockito.when(repository.getByValue(defaultDynScope2String)).thenReturn(defaultDynScope2);
    Mockito.when(repository.getByValue(defaultScope1String)).thenReturn(defaultScope1);
    Mockito.when(repository.getByValue(defaultScope2String)).thenReturn(defaultScope2);
    Mockito.when(repository.getByValue(dynScope1String)).thenReturn(dynScope1);
    Mockito.when(repository.getByValue(extraScope1String)).thenReturn(extraScope1);
    // we re-use this value so we've got to use thenAnswer instead
    Mockito.when(repository.getByValue(structuredScope1String)).thenAnswer(new Answer<SystemScope>() {
      @Override
      public SystemScope answer(InvocationOnMock invocation) throws Throwable {
        SystemScope s = new SystemScope(structuredScope1String);
        s.setStructured(true);
        return s;
      }

    });
View Full Code Here

    // note: we have to use "thenAnswer" here to mimic the repository not serializing the structuredValue field
    Mockito.when(repository.getByValue("foo")).thenAnswer(new Answer<SystemScope>() {
      @Override
      public SystemScope answer(InvocationOnMock invocation) throws Throwable {
        SystemScope foo = new SystemScope("foo");
        foo.setStructured(true);
        return foo;
      }

    });
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.