Examples of WhitelistedSite


Examples of org.mitre.openid.connect.model.WhitelistedSite

  }

  @Test(expected = IllegalArgumentException.class)
  public void saveNew_notNullId() {

    WhitelistedSite site = Mockito.mock(WhitelistedSite.class);
    Mockito.when(site.getId()).thenReturn(12345L); // arbitrary long value

    service.saveNew(site);
  }
View Full Code Here

Examples of org.mitre.openid.connect.model.WhitelistedSite

    service.saveNew(site);
  }

  @Test
  public void saveNew_success() {
    WhitelistedSite site = Mockito.mock(WhitelistedSite.class);
    Mockito.when(site.getId()).thenReturn(null);

    service.saveNew(site);

    Mockito.verify(repository).save(site);
  }
View Full Code Here

Examples of org.mitre.openid.connect.model.WhitelistedSite

  }

  @Test
  public void update_nullSites() {

    WhitelistedSite oldSite = Mockito.mock(WhitelistedSite.class);
    WhitelistedSite newSite = Mockito.mock(WhitelistedSite.class);

    // old client null
    try {
      service.update(null, newSite);
      fail("Old site input is null. Expected a IllegalArgumentException.");
View Full Code Here

Examples of org.mitre.openid.connect.model.WhitelistedSite

  }

  @Test
  public void update_success() {

    WhitelistedSite oldSite = Mockito.mock(WhitelistedSite.class);
    WhitelistedSite newSite = Mockito.mock(WhitelistedSite.class);

    service.update(oldSite, newSite);

    Mockito.verify(repository).update(oldSite, newSite);
  }
View Full Code Here

Examples of org.mitre.openid.connect.model.WhitelistedSite

          }
        }
      }

      if (!alreadyApproved) {
        WhitelistedSite ws = whitelistedSiteService.getByClientId(clientId);
        if (ws != null && systemScopes.scopesMatch(ws.getAllowedScopes(), authorizationRequest.getScope())) {

          //Create an approved site
          ApprovedSite newSite = approvedSiteService.createApprovedSite(clientId, userId, null, ws.getAllowedScopes(), ws);
          authorizationRequest.getExtensions().put("approved_site", newSite.getId());
          authorizationRequest.setApproved(true);

          setAuthTime(authorizationRequest);
        }
View Full Code Here

Examples of org.mitre.openid.connect.model.WhitelistedSite

    assertThat(savedSites.get(2).getUri(), equalTo(site3.getUri()));
  }

  @Test
  public void testImportWhitelistedSites() throws IOException {
    WhitelistedSite site1 = new WhitelistedSite();
        site1.setId(1L);
        site1.setClientId("foo");

        WhitelistedSite site2 = new WhitelistedSite();
        site2.setId(2L);
        site2.setClientId("bar");
       
        WhitelistedSite site3 = new WhitelistedSite();
        site3.setId(3L);
        site3.setClientId("baz");

    String configJson = "{" +
        "\"" + MITREidDataService.CLIENTS + "\": [], " +
        "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
        "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
        "\"" + MITREidDataService.GRANTS + "\": [], " +
        "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
                "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
        "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
        "\"" + MITREidDataService.WHITELISTEDSITES + "\": [" +
       
        "{\"id\":1,\"clientId\":\"foo\"}," +
        "{\"id\":2,\"clientId\":\"bar\"}," +
        "{\"id\":3,\"clientId\":\"baz\"}" +
       
        "  ]" +
        "}"
   
    System.err.println(configJson);
   
    JsonReader reader = new JsonReader(new StringReader(configJson));
   
        final Map<Long, WhitelistedSite> fakeDb = new HashMap<Long, WhitelistedSite>();
        when(wlSiteRepository.save(isA(WhitelistedSite.class))).thenAnswer(new Answer<WhitelistedSite>() {
            Long id = 345L;
            @Override
            public WhitelistedSite answer(InvocationOnMock invocation) throws Throwable {
                WhitelistedSite _site = (WhitelistedSite) invocation.getArguments()[0];
                if(_site.getId() == null) {
                    _site.setId(id++);
                }
                fakeDb.put(_site.getId(), _site);
                return _site;
            }
        });
        when(wlSiteRepository.getById(anyLong())).thenAnswer(new Answer<WhitelistedSite>() {
            @Override
View Full Code Here

Examples of org.mitre.openid.connect.model.WhitelistedSite

    @Test
    public void testImportGrants() throws IOException {
        Date creationDate1 = DateUtil.utcToDate("2014-09-10T22:49:44.090+0000");
        Date accessDate1 = DateUtil.utcToDate("2014-09-10T23:49:44.090+0000");
       
        WhitelistedSite mockWlSite1 = mock(WhitelistedSite.class);
        when(mockWlSite1.getId()).thenReturn(1L);
       
        OAuth2AccessTokenEntity mockToken1 = mock(OAuth2AccessTokenEntity.class);
        when(mockToken1.getId()).thenReturn(1L);
       
    ApprovedSite site1 = new ApprovedSite();
        site1.setId(1L);
        site1.setClientId("foo");
        site1.setCreationDate(creationDate1);
        site1.setAccessDate(accessDate1);
        site1.setUserId("user1");
        site1.setWhitelistedSite(mockWlSite1);
        site1.setAllowedScopes(ImmutableSet.of("openid", "phone"));
        site1.setApprovedAccessTokens(ImmutableSet.of(mockToken1));

        Date creationDate2 = DateUtil.utcToDate("2014-09-11T18:49:44.090+0000");
        Date accessDate2 = DateUtil.utcToDate("2014-09-11T20:49:44.090+0000");
        Date timeoutDate2 = DateUtil.utcToDate("2014-10-01T20:49:44.090+0000");
       
    ApprovedSite site2 = new ApprovedSite();
        site2.setId(2L);
        site2.setClientId("bar");
        site2.setCreationDate(creationDate2);
        site2.setAccessDate(accessDate2);
        site2.setUserId("user2");
        site2.setAllowedScopes(ImmutableSet.of("openid", "offline_access", "email", "profile"));
        site2.setTimeoutDate(timeoutDate2);

    String configJson = "{" +
        "\"" + MITREidDataService.CLIENTS + "\": [], " +
        "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
        "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
        "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
        "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
                "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
        "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
        "\"" + MITREidDataService.GRANTS + "\": [" +
       
        "{\"id\":1,\"clientId\":\"foo\",\"creationDate\":\"2014-09-10T22:49:44.090+0000\",\"accessDate\":\"2014-09-10T23:49:44.090+0000\","
                + "\"userId\":\"user1\",\"whitelistedSiteId\":null,\"allowedScopes\":[\"openid\",\"phone\"], \"whitelistedSiteId\":1,"
                + "\"approvedAccessTokens\":[1]}," +
        "{\"id\":2,\"clientId\":\"bar\",\"creationDate\":\"2014-09-11T18:49:44.090+0000\",\"accessDate\":\"2014-09-11T20:49:44.090+0000\","
                + "\"timeoutDate\":\"2014-10-01T20:49:44.090+0000\",\"userId\":\"user2\","
                + "\"allowedScopes\":[\"openid\",\"offline_access\",\"email\",\"profile\"]}" +
               
        "  ]" +
        "}"
   
    System.err.println(configJson);
   
    JsonReader reader = new JsonReader(new StringReader(configJson));
   
        final Map<Long, ApprovedSite> fakeDb = new HashMap<Long, ApprovedSite>();
        when(approvedSiteRepository.save(isA(ApprovedSite.class))).thenAnswer(new Answer<ApprovedSite>() {
            Long id = 343L;
            @Override
            public ApprovedSite answer(InvocationOnMock invocation) throws Throwable {
                ApprovedSite _site = (ApprovedSite) invocation.getArguments()[0];
                if(_site.getId() == null) {
                    _site.setId(id++);
                }
                fakeDb.put(_site.getId(), _site);
                return _site;
            }
        });
        when(approvedSiteRepository.getById(anyLong())).thenAnswer(new Answer<ApprovedSite>() {
            @Override
            public ApprovedSite answer(InvocationOnMock invocation) throws Throwable {
                Long _id = (Long) invocation.getArguments()[0];
                return fakeDb.get(_id);
            }
        });
        when(wlSiteRepository.getById(isNull(Long.class))).thenAnswer(new Answer<WhitelistedSite>() {
            Long id = 244L;
            @Override
            public WhitelistedSite answer(InvocationOnMock invocation) throws Throwable {
                WhitelistedSite _site = mock(WhitelistedSite.class);
                when(_site.getId()).thenReturn(id++);
                return _site;
            }
        });
        when(tokenRepository.getAccessTokenById(isNull(Long.class))).thenAnswer(new Answer<OAuth2AccessTokenEntity>() {
            Long id = 221L;
View Full Code Here

Examples of org.mitre.openid.connect.model.WhitelistedSite

    assertThat(savedSites.get(2).getUri(), equalTo(site3.getUri()));
  }
   
  @Test
  public void testExportWhitelistedSites() throws IOException {   
    WhitelistedSite site1 = new WhitelistedSite();
        site1.setId(1L);
        site1.setClientId("foo");

        WhitelistedSite site2 = new WhitelistedSite();
        site2.setId(2L);
        site2.setClientId("bar");
       
        WhitelistedSite site3 = new WhitelistedSite();
        site3.setId(3L);
        site3.setClientId("baz");

    Set<WhitelistedSite> allWhitelistedSites = ImmutableSet.of(site1, site2, site3);
   
    Mockito.when(clientRepository.getAllClients()).thenReturn(new HashSet<ClientDetailsEntity>());
    Mockito.when(approvedSiteRepository.getAll()).thenReturn(new HashSet<ApprovedSite>());
    Mockito.when(blSiteRepository.getAll()).thenReturn(new HashSet<BlacklistedSite>());
    Mockito.when(wlSiteRepository.getAll()).thenReturn(allWhitelistedSites);
    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(new HashSet<SystemScope>());
   
    // 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 sites = config.get(MITREidDataService.WHITELISTEDSITES).getAsJsonArray();

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

      WhitelistedSite compare = null;
      if (site.get("id").getAsLong() == site1.getId().longValue()) {
        compare = site1;
      } else if (site.get("id").getAsLong() == site2.getId().longValue()) {
        compare = site2;
      } else if (site.get("id").getAsLong() == site3.getId().longValue()) {
        compare = site3;
      }
     
      if (compare == null) {
        fail("Could not find matching whitelisted site id: " + site.get("id").getAsString());
      } else {
        assertThat(site.get("clientId").getAsString(), equalTo(compare.getClientId()));
        checked.add(compare);
      }
    }
    // make sure all of our clients were found
    assertThat(checked.containsAll(allWhitelistedSites), is(true));
View Full Code Here

Examples of org.mitre.openid.connect.model.WhitelistedSite

    // clean out any approved sites for this client
    approvedSiteService.clearApprovedSitesForClient(client);

    // clear out any whitelisted sites for this client
    WhitelistedSite whitelistedSite = whitelistedSiteService.getByClientId(client.getClientId());
    if (whitelistedSite != null) {
      whitelistedSiteService.remove(whitelistedSite);
    }

    // take care of the client itself
View Full Code Here

Examples of org.mitre.openid.connect.model.WhitelistedSite

   
  }

  @Test
  public void testImportWhitelistedSites() throws IOException {
    WhitelistedSite site1 = new WhitelistedSite();
        site1.setId(1L);
        site1.setClientId("foo");

        WhitelistedSite site2 = new WhitelistedSite();
        site2.setId(2L);
        site2.setClientId("bar");
       
        WhitelistedSite site3 = new WhitelistedSite();
        site3.setId(3L);
        site3.setClientId("baz");
        //site3.setAllowedScopes(null);

    String configJson = "{" +
        "\"" + MITREidDataService.CLIENTS + "\": [], " +
        "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
        "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
        "\"" + MITREidDataService.GRANTS + "\": [], " +
        "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " +
                "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
        "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
        "\"" + MITREidDataService.WHITELISTEDSITES + "\": [" +
       
        "{\"id\":1,\"clientId\":\"foo\"}," +
        "{\"id\":2,\"clientId\":\"bar\"}," +
        "{\"id\":3,\"clientId\":\"baz\"}" +
       
        "  ]" +
        "}"
   
    System.err.println(configJson);
   
    JsonReader reader = new JsonReader(new StringReader(configJson));
   
        final Map<Long, WhitelistedSite> fakeDb = new HashMap<Long, WhitelistedSite>();
        when(wlSiteRepository.save(isA(WhitelistedSite.class))).thenAnswer(new Answer<WhitelistedSite>() {
            Long id = 333L;
            @Override
            public WhitelistedSite answer(InvocationOnMock invocation) throws Throwable {
                WhitelistedSite _site = (WhitelistedSite) invocation.getArguments()[0];
                if(_site.getId() == null) {
                    _site.setId(id++);
                }
                fakeDb.put(_site.getId(), _site);
                return _site;
            }
        });
        when(wlSiteRepository.getById(anyLong())).thenAnswer(new Answer<WhitelistedSite>() {
            @Override
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.