Package org.mitre.openid.connect.model

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


          Calendar cal = Calendar.getInstance();
          cal.add(Calendar.HOUR, 1);
          timeout = cal.getTime();
        }

        ApprovedSite newSite = approvedSiteService.createApprovedSite(clientId, userId, timeout, allowedScopes, null);
        authorizationRequest.getExtensions().put("approved_site", newSite.getId());
      }

      setAuthTime(authorizationRequest);

View Full Code Here


  public void prepare() {

    client = new ClientDetailsEntity();
    client.setClientId(clientId);

    site1 = new ApprovedSite();
    site1.setId(1L);
    site1.setUserId("user1");
    site1.setClientId("other");

    site2 = new ApprovedSite();
    site2.setId(2L);
    site2.setUserId("user1");
    site2.setClientId(clientId);

    site3 = new ApprovedSite();
    site3.setId(3L);
    site3.setUserId("user2");
    site3.setClientId(clientId);

    Mockito.reset(repository, statsService);
View Full Code Here

      OAuth2Request originalAuthRequest = authHolder.getAuthentication().getOAuth2Request();

      if (originalAuthRequest.getExtensions() != null && originalAuthRequest.getExtensions().containsKey("approved_site")) {

        Long apId = (Long) originalAuthRequest.getExtensions().get("approved_site");
        ApprovedSite ap = approvedSiteService.getById(apId);
        Set<OAuth2AccessTokenEntity> apTokens = ap.getApprovedAccessTokens();
        apTokens.add(savedToken);
        ap.setApprovedAccessTokens(apTokens);
        approvedSiteService.save(ap);

      }

      if (savedToken.getRefreshToken() != null) {
View Full Code Here

        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

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

    Set<ApprovedSite> allApprovedSites = ImmutableSet.of(site1, site2);
   
    Mockito.when(clientRepository.getAllClients()).thenReturn(new HashSet<ClientDetailsEntity>());
    Mockito.when(approvedSiteRepository.getAll()).thenReturn(allApprovedSites);
    Mockito.when(blSiteRepository.getAll()).thenReturn(new HashSet<BlacklistedSite>());
    Mockito.when(wlSiteRepository.getAll()).thenReturn(new HashSet<WhitelistedSite>());
    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.GRANTS).getAsJsonArray();

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

      ApprovedSite compare = null;
      if (site.get("id").getAsLong() == site1.getId().longValue()) {
        compare = site1;
      } else if (site.get("id").getAsLong() == site2.getId().longValue()) {
        compare = site2;
      }
     
      if (compare == null) {
        fail("Could not find matching whitelisted site id: " + site.get("id").getAsString());
      } else {
        assertThat(site.get("clientId").getAsString(), equalTo(compare.getClientId()));
                assertThat(site.get("creationDate").getAsString(), equalTo(DateUtil.toUTCString(compare.getCreationDate())));
                assertThat(site.get("accessDate").getAsString(), equalTo(DateUtil.toUTCString(compare.getAccessDate())));
                if(site.get("timeoutDate").isJsonNull()) {
                    assertNull(compare.getTimeoutDate());
                } else {
                    assertThat(site.get("timeoutDate").getAsString(), equalTo(DateUtil.toUTCString(compare.getTimeoutDate())));
                }
                assertThat(site.get("userId").getAsString(), equalTo(compare.getUserId()));
                assertThat(jsonArrayToStringSet(site.getAsJsonArray("allowedScopes")), equalTo(compare.getAllowedScopes()));
                if (site.get("whitelistedSiteId").isJsonNull()) {
                    assertNull(compare.getWhitelistedSite());
                } else {
                    assertThat(site.get("whitelistedSiteId").getAsLong(), equalTo(compare.getWhitelistedSite().getId()));
                }
                if (site.get("approvedAccessTokens").isJsonNull() || site.getAsJsonArray("approvedAccessTokens") == null) {
                    assertTrue(compare.getApprovedAccessTokens() == null || compare.getApprovedAccessTokens().isEmpty());
                } else {
                    assertNotNull(compare.getApprovedAccessTokens());
                    Set<String> tokenIds = new HashSet<String>();
                    for(OAuth2AccessTokenEntity entity : compare.getApprovedAccessTokens()) {
                        tokenIds.add(entity.getId().toString());
                    }
                    assertThat(jsonArrayToStringSet(site.getAsJsonArray("approvedAccessTokens")), equalTo(tokenIds));
                }
        checked.add(compare);
View Full Code Here

        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 = 364L;
            @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 = 432L;
            @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 = 245L;
View Full Code Here

TOP

Related Classes of org.mitre.openid.connect.model.ApprovedSite

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.