Package org.mitre.oauth2.model

Examples of org.mitre.oauth2.model.SystemScope


  }

  @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

     * @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

          //Make sure this scope is allowed for the given client
          if (systemScopes.scopesMatch(client.getScope(), approveSet)) {

            // If it's structured, assign the user-specified parameter
            SystemScope systemScope = systemScopes.getByValue(scope);
            if (systemScope != null && systemScope.isStructured()){
              String paramValue = approvalParams.get("scopeparam_" + scope);
              allowedScopes.add(scope + ":"+paramValue);
              // .. and if it's unstructured, we're all set
            } else {
              allowedScopes.add(scope);
View Full Code Here

   * @see org.mitre.oauth2.repository.SystemScopeRepository#remove(org.mitre.oauth2.model.SystemScope)
   */
  @Override
  @Transactional
  public void remove(SystemScope scope) {
    SystemScope found = getById(scope.getId());

    if (found != null) {
      em.remove(found);
    }

View Full Code Here

        assertThat(savedAuthHolders.get(1).getAuthentication().getOAuth2Request().getClientId(), equalTo(holder2.getAuthentication().getOAuth2Request().getClientId()));
    }

  @Test
  public void testImportSystemScopes() throws IOException {
    SystemScope scope1 = new SystemScope();
    scope1.setId(1L);
    scope1.setValue("scope1");
    scope1.setDescription("Scope 1");
    scope1.setAllowDynReg(false);
    scope1.setDefaultScope(false);
    scope1.setIcon("glass");

    SystemScope scope2 = new SystemScope();
    scope2.setId(2L);
    scope2.setValue("scope2");
    scope2.setDescription("Scope 2");
    scope2.setAllowDynReg(true);
    scope2.setDefaultScope(false);
    scope2.setIcon("ball");

    SystemScope scope3 = new SystemScope();
    scope3.setId(3L);
    scope3.setValue("scope3");
    scope3.setDescription("Scope 3");
    scope3.setAllowDynReg(true);
    scope3.setDefaultScope(true);
    scope3.setIcon("road");

    String configJson = "{" +
        "\"" + MITREidDataService.CLIENTS + "\": [], " +
        "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
        "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
        "\"" + MITREidDataService.GRANTS + "\": [], " +
        "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
        "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
        "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
        "\"" + MITREidDataService.SYSTEMSCOPES + "\": [" +
       
        "{\"id\":1,\"description\":\"Scope 1\",\"icon\":\"glass\",\"value\":\"scope1\",\"allowDynReg\":false,\"defaultScope\":false}," +
        "{\"id\":2,\"description\":\"Scope 2\",\"icon\":\"ball\",\"value\":\"scope2\",\"allowDynReg\":true,\"defaultScope\":false}," +
        "{\"id\":3,\"description\":\"Scope 3\",\"icon\":\"road\",\"value\":\"scope3\",\"allowDynReg\":true,\"defaultScope\":true}" +
       
        "  ]" +
        "}"
   
    System.err.println(configJson);
   
    JsonReader reader = new JsonReader(new StringReader(configJson));
   
    dataService.importData(reader);
    verify(sysScopeRepository, times(3)).save(capturedScope.capture());
   
    List<SystemScope> savedScopes = capturedScope.getAllValues();
   
    assertThat(savedScopes.size(), is(3));
    assertThat(savedScopes.get(0).getValue(), equalTo(scope1.getValue()));
    assertThat(savedScopes.get(0).getDescription(), equalTo(scope1.getDescription()));
    assertThat(savedScopes.get(0).getIcon(), equalTo(scope1.getIcon()));
    assertThat(savedScopes.get(0).isDefaultScope(), equalTo(scope1.isDefaultScope()));
    assertThat(savedScopes.get(0).isAllowDynReg(), equalTo(scope1.isAllowDynReg()));

    assertThat(savedScopes.get(1).getValue(), equalTo(scope2.getValue()));
    assertThat(savedScopes.get(1).getDescription(), equalTo(scope2.getDescription()));
    assertThat(savedScopes.get(1).getIcon(), equalTo(scope2.getIcon()));
    assertThat(savedScopes.get(1).isDefaultScope(), equalTo(scope2.isDefaultScope()));
    assertThat(savedScopes.get(1).isAllowDynReg(), equalTo(scope2.isAllowDynReg()));

    assertThat(savedScopes.get(2).getValue(), equalTo(scope3.getValue()));
    assertThat(savedScopes.get(2).getDescription(), equalTo(scope3.getDescription()));
    assertThat(savedScopes.get(2).getIcon(), equalTo(scope3.getIcon()));
    assertThat(savedScopes.get(2).isDefaultScope(), equalTo(scope3.isDefaultScope()));
    assertThat(savedScopes.get(2).isAllowDynReg(), equalTo(scope3.isAllowDynReg()));
   
  }
View Full Code Here

    assertThat(savedAuthHolders.get(1).getAuthentication().getOAuth2Request().getClientId(), equalTo(holder2.getAuthentication().getOAuth2Request().getClientId()));
    }
   
  @Test
  public void testExportSystemScopes() throws IOException {   
    SystemScope scope1 = new SystemScope();
    scope1.setId(1L);
    scope1.setValue("scope1");
    scope1.setDescription("Scope 1");
    scope1.setAllowDynReg(false);
    scope1.setDefaultScope(false);
    scope1.setIcon("glass");

    SystemScope scope2 = new SystemScope();
    scope2.setId(2L);
    scope2.setValue("scope2");
    scope2.setDescription("Scope 2");
    scope2.setAllowDynReg(true);
    scope2.setDefaultScope(false);
    scope2.setIcon("ball");

    SystemScope scope3 = new SystemScope();
    scope3.setId(3L);
    scope3.setValue("scope3");
    scope3.setDescription("Scope 3");
    scope3.setAllowDynReg(true);
    scope3.setDefaultScope(true);
    scope3.setIcon("road");

    Set<SystemScope> allScopes = ImmutableSet.of(scope1, scope2, scope3);
   
    Mockito.when(clientRepository.getAllClients()).thenReturn(new HashSet<ClientDetailsEntity>());
    Mockito.when(approvedSiteRepository.getAll()).thenReturn(new HashSet<ApprovedSite>());
    Mockito.when(wlSiteRepository.getAll()).thenReturn(new HashSet<WhitelistedSite>());
    Mockito.when(blSiteRepository.getAll()).thenReturn(new HashSet<BlacklistedSite>());
    Mockito.when(authHolderRepository.getAll()).thenReturn(new ArrayList<AuthenticationHolderEntity>());
    Mockito.when(tokenRepository.getAllAccessTokens()).thenReturn(new HashSet<OAuth2AccessTokenEntity>());
    Mockito.when(tokenRepository.getAllRefreshTokens()).thenReturn(new HashSet<OAuth2RefreshTokenEntity>());
    Mockito.when(sysScopeRepository.getAll()).thenReturn(allScopes);
   
    // do the data export
    StringWriter stringWriter = new StringWriter();
    JsonWriter writer = new JsonWriter(stringWriter);
    writer.beginObject();
    dataService.exportData(writer);
    writer.endObject();
    writer.close();
   
    // parse the output as a JSON object for testing
    JsonElement elem = new JsonParser().parse(stringWriter.toString());
    JsonObject root = elem.getAsJsonObject();

    // make sure the root is there
    assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_1), is(true));
   
    JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_1).getAsJsonObject();
   
    // make sure all the root elements are there
    assertThat(config.has(MITREidDataService.CLIENTS), is(true));
    assertThat(config.has(MITREidDataService.GRANTS), is(true));
        assertThat(config.has(MITREidDataService.WHITELISTEDSITES), is(true));
        assertThat(config.has(MITREidDataService.BLACKLISTEDSITES), is(true));
    assertThat(config.has(MITREidDataService.REFRESHTOKENS), is(true));
    assertThat(config.has(MITREidDataService.ACCESSTOKENS), is(true));
    assertThat(config.has(MITREidDataService.SYSTEMSCOPES), is(true));
    assertThat(config.has(MITREidDataService.AUTHENTICATIONHOLDERS), is(true));
   
    // make sure the root elements are all arrays
    assertThat(config.get(MITREidDataService.CLIENTS).isJsonArray(), is(true));
    assertThat(config.get(MITREidDataService.GRANTS).isJsonArray(), is(true));
        assertThat(config.get(MITREidDataService.WHITELISTEDSITES).isJsonArray(), is(true));
        assertThat(config.get(MITREidDataService.BLACKLISTEDSITES).isJsonArray(), is(true));
    assertThat(config.get(MITREidDataService.REFRESHTOKENS).isJsonArray(), is(true));
    assertThat(config.get(MITREidDataService.ACCESSTOKENS).isJsonArray(), is(true));
    assertThat(config.get(MITREidDataService.SYSTEMSCOPES).isJsonArray(), is(true));
    assertThat(config.get(MITREidDataService.AUTHENTICATIONHOLDERS).isJsonArray(), is(true));

   
    // check our scope list (this test)
    JsonArray scopes = config.get(MITREidDataService.SYSTEMSCOPES).getAsJsonArray();

    assertThat(scopes.size(), is(3));
    // check for both of our clients in turn
    Set<SystemScope> checked = new HashSet<SystemScope>();
    for (JsonElement e : scopes) {
      assertThat(e.isJsonObject(), is(true));
      JsonObject scope = e.getAsJsonObject();

      SystemScope compare = null;
      if (scope.get("value").getAsString().equals(scope1.getValue())) {
        compare = scope1;
      } else if (scope.get("value").getAsString().equals(scope2.getValue())) {
        compare = scope2;
      } else if (scope.get("value").getAsString().equals(scope3.getValue())) {
        compare = scope3;
      }
     
      if (compare == null) {
        fail("Could not find matching scope value: " + scope.get("value").getAsString());
      } else {
        assertThat(scope.get("value").getAsString(), equalTo(compare.getValue()));
        assertThat(scope.get("description").getAsString(), equalTo(compare.getDescription()));
        assertThat(scope.get("icon").getAsString(), equalTo(compare.getIcon()));
        assertThat(scope.get("allowDynReg").getAsBoolean(), equalTo(compare.isAllowDynReg()));
        assertThat(scope.get("defaultScope").getAsBoolean(), equalTo(compare.isDefaultScope()));
        checked.add(compare);
      }
    }
    // make sure all of our clients were found
    assertThat(checked.containsAll(allScopes), is(true));
View Full Code Here

   
  }

  @Test
  public void testImportSystemScopes() throws IOException {
    SystemScope scope1 = new SystemScope();
    scope1.setId(1L);
    scope1.setValue("scope1");
    scope1.setDescription("Scope 1");
    scope1.setAllowDynReg(false);
    scope1.setDefaultScope(false);
    scope1.setIcon("glass");

    SystemScope scope2 = new SystemScope();
    scope2.setId(2L);
    scope2.setValue("scope2");
    scope2.setDescription("Scope 2");
    scope2.setAllowDynReg(true);
    scope2.setDefaultScope(false);
    scope2.setIcon("ball");

    SystemScope scope3 = new SystemScope();
    scope3.setId(3L);
    scope3.setValue("scope3");
    scope3.setDescription("Scope 3");
    scope3.setAllowDynReg(true);
    scope3.setDefaultScope(true);
    scope3.setIcon("road");

    String configJson = "{" +
        "\"" + MITREidDataService.CLIENTS + "\": [], " +
        "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
        "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
        "\"" + MITREidDataService.GRANTS + "\": [], " +
        "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
        "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
        "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
        "\"" + MITREidDataService.SYSTEMSCOPES + "\": [" +
       
        "{\"id\":1,\"description\":\"Scope 1\",\"icon\":\"glass\",\"value\":\"scope1\",\"allowDynReg\":false,\"defaultScope\":false}," +
        "{\"id\":2,\"description\":\"Scope 2\",\"icon\":\"ball\",\"value\":\"scope2\",\"allowDynReg\":true,\"defaultScope\":false}," +
        "{\"id\":3,\"description\":\"Scope 3\",\"icon\":\"road\",\"value\":\"scope3\",\"allowDynReg\":true,\"defaultScope\":true}" +
       
        "  ]" +
        "}"
   
    System.err.println(configJson);
   
    JsonReader reader = new JsonReader(new StringReader(configJson));
   
    dataService.importData(reader);
    verify(sysScopeRepository, times(3)).save(capturedScope.capture());
   
    List<SystemScope> savedScopes = capturedScope.getAllValues();
   
    assertThat(savedScopes.size(), is(3));
    assertThat(savedScopes.get(0).getValue(), equalTo(scope1.getValue()));
    assertThat(savedScopes.get(0).getDescription(), equalTo(scope1.getDescription()));
    assertThat(savedScopes.get(0).getIcon(), equalTo(scope1.getIcon()));
    assertThat(savedScopes.get(0).isDefaultScope(), equalTo(scope1.isDefaultScope()));
    assertThat(savedScopes.get(0).isAllowDynReg(), equalTo(scope1.isAllowDynReg()));

    assertThat(savedScopes.get(1).getValue(), equalTo(scope2.getValue()));
    assertThat(savedScopes.get(1).getDescription(), equalTo(scope2.getDescription()));
    assertThat(savedScopes.get(1).getIcon(), equalTo(scope2.getIcon()));
    assertThat(savedScopes.get(1).isDefaultScope(), equalTo(scope2.isDefaultScope()));
    assertThat(savedScopes.get(1).isAllowDynReg(), equalTo(scope2.isAllowDynReg()));

    assertThat(savedScopes.get(2).getValue(), equalTo(scope3.getValue()));
    assertThat(savedScopes.get(2).getDescription(), equalTo(scope3.getDescription()));
    assertThat(savedScopes.get(2).getIcon(), equalTo(scope3.getIcon()));
    assertThat(savedScopes.get(2).isDefaultScope(), equalTo(scope3.isDefaultScope()));
    assertThat(savedScopes.get(2).isAllowDynReg(), equalTo(scope3.isAllowDynReg()));
   
  }
View Full Code Here

        // we didn't find an exact match
        if (actScope.isStructured() && !Strings.isNullOrEmpty(actScope.getStructuredValue())) {
          // if we didn't get an exact match but the actual scope is structured, we need to check further

          // first, find the "base" scope for this
          SystemScope base = getByValue(actScope.getValue());
          if (!ex.contains(base)) {
            // if the expected doesn't contain the base scope, fail
            return false;
          } else {
            // we did find an exact match, need to check the rest
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.