Examples of BlacklistedSite


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

     * @throws IOException
     */
    private void readBlacklistedSites(JsonReader reader) throws IOException {
        reader.beginArray();
        while (reader.hasNext()) {
            BlacklistedSite blSite = new BlacklistedSite();
            reader.beginObject();
            while (reader.hasNext()) {
                switch (reader.peek()) {
                    case END_OBJECT:
                        continue;
                    case NAME:
                        String name = reader.nextName();
                        if (name.equals("id")) {
                            reader.skipValue();
                        } else if (name.equals("uri")) {
                            blSite.setUri(reader.nextString());
                        } else {
                            logger.debug("Found unexpected entry");
                            reader.skipValue();
                        }
                        break;
View Full Code Here

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

  @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
  public String addNewBlacklistedSite(@RequestBody String jsonString, ModelMap m, Principal p) {

    JsonObject json;

    BlacklistedSite blacklist = null;

    try {

      json = parser.parse(jsonString).getAsJsonObject();
      blacklist = gson.fromJson(json, BlacklistedSite.class);
      BlacklistedSite newBlacklist = blacklistService.saveNew(blacklist);
      m.put("entity", newBlacklist);

    }
    catch (JsonSyntaxException e) {
      logger.error("addNewBlacklistedSite failed due to JsonSyntaxException: ", e);
View Full Code Here

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

  @RequestMapping(value="/{id}", method = RequestMethod.PUT, consumes = "application/json", produces = "application/json")
  public String updateBlacklistedSite(@PathVariable("id") Long id, @RequestBody String jsonString, ModelMap m, Principal p) {

    JsonObject json;

    BlacklistedSite blacklist = null;

    try {

      json = parser.parse(jsonString).getAsJsonObject();
      blacklist = gson.fromJson(json, BlacklistedSite.class);

    }
    catch (JsonSyntaxException e) {
      logger.error("updateBlacklistedSite failed due to JsonSyntaxException", e);
      m.put("code", HttpStatus.BAD_REQUEST);
      m.put("errorMessage", "Could not update blacklisted site. The server encountered a JSON syntax exception. Contact a system administrator for assistance.");
      return JsonErrorView.VIEWNAME;
    } catch (IllegalStateException e) {
      logger.error("updateBlacklistedSite failed due to IllegalStateException", e);
      m.put("code", HttpStatus.BAD_REQUEST);
      m.put("errorMessage", "Could not update blacklisted site. The server encountered an IllegalStateException. Refresh and try again - if the problem persists, contact a system administrator for assistance.");
      return JsonErrorView.VIEWNAME;
    }


    BlacklistedSite oldBlacklist = blacklistService.getById(id);

    if (oldBlacklist == null) {
      logger.error("updateBlacklistedSite failed; blacklist with id " + id + " could not be found");
      m.put("code", HttpStatus.NOT_FOUND);
      m.put("errorMessage", "Could not update blacklisted site. The requested blacklist with id " + id + "could not be found.");
      return JsonErrorView.VIEWNAME;
    } else {

      BlacklistedSite newBlacklist = blacklistService.update(oldBlacklist, blacklist);

      m.put("entity", newBlacklist);

      return JsonEntityView.VIEWNAME;
    }
View Full Code Here

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

   * Delete a blacklisted site
   *
   */
  @RequestMapping(value="/{id}", method = RequestMethod.DELETE)
  public String deleteBlacklistedSite(@PathVariable("id") Long id, ModelMap m) {
    BlacklistedSite blacklist = blacklistService.getById(id);

    if (blacklist == null) {
      logger.error("deleteBlacklistedSite failed; blacklist with id " + id + " could not be found");
      m.put("errorMessage", "Could not delete bladklist. The requested bladklist with id " + id + " could not be found.");
      return JsonErrorView.VIEWNAME;
View Full Code Here

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

  /**
   * Get a single blacklisted site
   */
  @RequestMapping(value="/{id}", method = RequestMethod.GET, produces = "application/json")
  public String getBlacklistedSite(@PathVariable("id") Long id, ModelMap m) {
    BlacklistedSite blacklist = blacklistService.getById(id);
    if (blacklist == null) {
      logger.error("getBlacklistedSite failed; blacklist with id " + id + " could not be found");
      m.put("code", HttpStatus.NOT_FOUND);
      m.put("errorMessage", "Could not delete bladklist. The requested bladklist with id " + id + " could not be found.");
      return JsonErrorView.VIEWNAME;
View Full Code Here

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

   * @see org.mitre.openid.connect.repository.BlacklistedSiteRepository#remove(org.mitre.openid.connect.model.BlacklistedSite)
   */
  @Override
  @Transactional
  public void remove(BlacklistedSite blacklistedSite) {
    BlacklistedSite found = manager.find(BlacklistedSite.class, blacklistedSite.getId());

    if (found != null) {
      manager.remove(found);
    } else {
      throw new IllegalArgumentException();
View Full Code Here

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

     * @throws IOException
     */
    private void readBlacklistedSites(JsonReader reader) throws IOException {
        reader.beginArray();
        while (reader.hasNext()) {
            BlacklistedSite blSite = new BlacklistedSite();
            reader.beginObject();
            while (reader.hasNext()) {
                switch (reader.peek()) {
                    case END_OBJECT:
                        continue;
                    case NAME:
                        String name = reader.nextName();
                        if (name.equals("id")) {
                            reader.skipValue();
                        } else if (name.equals("uri")) {
                            blSite.setUri(reader.nextString());
                        } else {
                            logger.debug("Found unexpected entry");
                            reader.skipValue();
                        }
                        break;
View Full Code Here

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

   * @throws java.lang.Exception
   */
  @Before
  public void prepare() throws Exception {

    site1 = new BlacklistedSite();
    site2 = new BlacklistedSite();

    site1.setUri(uri1);
    site2.setUri(uri2);

    blackListedSitesSet = Sets.newHashSet(site1, site2);
View Full Code Here

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

    assertThat(savedClients.get(1).isAllowIntrospection(), equalTo(client2.isAllowIntrospection()));
  }

  @Test
  public void testImportBlacklistedSites() throws IOException {
    BlacklistedSite site1 = new BlacklistedSite();
        site1.setId(1L);
        site1.setUri("http://foo.com");

        BlacklistedSite site2 = new BlacklistedSite();
        site2.setId(2L);
        site2.setUri("http://bar.com");
       
        BlacklistedSite site3 = new BlacklistedSite();
        site3.setId(3L);
        site3.setUri("http://baz.com");

    String configJson = "{" +
        "\"" + MITREidDataService.CLIENTS + "\": [], " +
        "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " +
        "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " +
        "\"" + MITREidDataService.GRANTS + "\": [], " +
        "\"" + MITREidDataService.WHITELISTEDSITES + "\": [], " +
                "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " +
        "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " +
        "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [" +
       
        "{\"id\":1,\"uri\":\"http://foo.com\"}," +
        "{\"id\":2,\"uri\":\"http://bar.com\"}," +
        "{\"id\":3,\"uri\":\"http://baz.com\"}" +
       
        "  ]" +
        "}";
   
   
    System.err.println(configJson);
   
    JsonReader reader = new JsonReader(new StringReader(configJson));
   
    dataService.importData(reader);
    verify(blSiteRepository, times(3)).save(capturedBlacklistedSites.capture());
   
    List<BlacklistedSite> savedSites = capturedBlacklistedSites.getAllValues();
   
    assertThat(savedSites.size(), is(3));
       
    assertThat(savedSites.get(0).getUri(), equalTo(site1.getUri()));
    assertThat(savedSites.get(1).getUri(), equalTo(site2.getUri()));       
    assertThat(savedSites.get(2).getUri(), equalTo(site3.getUri()));
  }
View Full Code Here

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

    assertThat(savedClients.get(1).isAllowIntrospection(), equalTo(client2.isAllowIntrospection()));
  }
   
  @Test
  public void testExportBlacklistedSites() throws IOException
    BlacklistedSite site1 = new BlacklistedSite();
        site1.setId(1L);
        site1.setUri("http://foo.com");

        BlacklistedSite site2 = new BlacklistedSite();
        site2.setId(2L);
        site2.setUri("http://bar.com");
       
        BlacklistedSite site3 = new BlacklistedSite();
        site3.setId(3L);
        site3.setUri("http://baz.com");

    Set<BlacklistedSite> allBlacklistedSites = ImmutableSet.of(site1, site2, site3);
   
    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(allBlacklistedSites);
    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.BLACKLISTEDSITES).getAsJsonArray();

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

      BlacklistedSite 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 blacklisted site id: " + site.get("id").getAsString());
      } else {
        assertThat(site.get("uri").getAsString(), equalTo(compare.getUri()));
        checked.add(compare);
      }
    }
    // make sure all of our clients were found
    assertThat(checked.containsAll(allBlacklistedSites), is(true));
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.