Пример #1
0
 private Asset resourceToAsset(Resource resource) {
   Asset out = new Asset();
   out.setMedia(resource.getId());
   out.setCredit(resource.getContentType());
   out.setCaption(resource.getName());
   out.setThumbnail(resource.getId());
   return out;
 }
Пример #2
0
  public static final void main(String[] args) {

    setup();

    System.out.println("Waiting for messages...");
    System.out.println("Press [return] to quit\n");

    ArrayList<Resource> resources = new ArrayList<Resource>();

    //
    SimpleEventGenerator myGenerator =
        new SimpleEventGenerator(
            wm, new SimpleEventListener(wm), PseudoSessionClock.timeInMinutes(15));

    // create fab resources and add them to working memory
    for (int i = 0; i < NUMBER_RESOURCES; i++) {

      Resource res = new Resource("mach" + i);
      resources.add(res);
      wm.insert(res.getOpStatus());

      SlidingWindow sw =
          new SlidingWindow(
              0,
              res.getId(),
              PseudoSessionClock.timeInMinutes(10),
              PseudoSessionClock.timeInMinutes(2));
      // GlobalWorkingMemory.getInstance().insert(new Event(Event.SLIDING_WINDOW, res.getId(),
      // systemTime, systemTime));
      wm.insert(sw);

      // add eventSenders to EventGenerator
      myGenerator.addEventSource(
          "Conveyor" + i,
          new ProductionEvent(res.getId()),
          MIN_OCCUR_PRODUCTION_EVENT,
          AVG_OCCUR_PRODUCTION_EVENT,
          0,
          0);
    }

    // start generating events
    myGenerator.generate();

    BufferedReader waiter = new BufferedReader(new InputStreamReader(System.in));
    try {
      waiter.readLine();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    // stop logging
    // logger.writeToDisk();
    // System.out.println("Application terminated - Audit log written to disk");

  }
Пример #3
0
 private HashMap<String, Asset> resourcesToAssetMap(Iterable<Resource> resources) {
   HashMap<String, Asset> out = new HashMap<>();
   for (Resource item : resources) {
     out.put(item.getId(), resourceToAsset(item));
   }
   return out;
 }
Пример #4
0
  public static List<Node> findNodesByParent(Node parent, long regionId) {
    if (parent == null) {
      throw new IllegalArgumentException("The parent argument is required");
    }
    List<Node> resultList = new ArrayList<Node>();
    Set<Node> availableList = new HashSet<Node>();
    Set<Node> currentList;

    EntityManager em = Node.entityManager();

    TypedQuery<Node> q;
    if (NO_REGION == regionId) {
      q = em.createQuery("SELECT o FROM Node AS o WHERE o.active = :active", Node.class);
    } else {
      q =
          em.createQuery(
              "SELECT o FROM Node AS o WHERE o.region = :region AND o.active = :active",
              Node.class);
      q.setParameter("region", Region.findRegion(regionId));
    }
    q.setParameter("active", true);

    availableList.addAll(q.getResultList());
    currentList = collectParents(new ArrayList<Node>(availableList), parent);
    availableList.addAll(currentList);

    q =
        em.createQuery(
            "SELECT o FROM Node AS o WHERE o IN :childs AND o.active = :active", Node.class);
    while (currentList.size() > 0) {

      q.setParameter("childs", currentList);
      q.setParameter("active", true);
      currentList = collectParents(q.getResultList(), parent);
      availableList.addAll(currentList);
    }

    q =
        em.createQuery(
            "SELECT o FROM Node AS o WHERE o IN :avaliable AND o.parent = :parent ORDER BY o.rate DESC, o.name ASC",
            Node.class);
    q.setParameter("parent", parent);
    q.setParameter("avaliable", availableList);

    for (Node node : q.getResultList()) {
      if (node instanceof Entity) {
        Entity entity = (Entity) node;
        Set<Resource> resList = new HashSet<Resource>();

        for (Resource res : entity.getResources()) {
          resList.add(Resource.findResource(res.getId()));
        }
        entity.setResources(resList);
      }

      resultList.add(node);
    }

    return resultList;
  }
Пример #5
0
 public void show() {
   for (int i = 0; i < resourceCount; i++) {
     Resource resource = (Resource) resources.elementAt(i);
     ((Label) resourceIdLabelVector.elementAt(i)).setText(Integer.toString(resource.getId()));
     ((Label) resourceAvailableLabelVector.elementAt(i))
         .setText(Integer.toString(resource.getCurrentAvailable()));
   }
   super.show();
 }
 private void processContentXml(InputStream in, String sitePath, Session session, ZipFile zip)
     throws XMLStreamException {
   Map<String, Resource> resources = new HashMap<String, Resource>();
   String currentResourceId = null;
   XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(in);
   for (int event = reader.next(); event != XMLStreamReader.END_DOCUMENT; event = reader.next()) {
     String localName = null;
     switch (event) {
       case XMLStreamReader.START_ELEMENT:
         localName = reader.getLocalName();
         if ("archive".equalsIgnoreCase(localName)) {
           final String system = reader.getAttributeValue(null, "system");
           boolean supportedVersion = false;
           for (String version : supportedVersions) {
             if (version.equalsIgnoreCase(system)) {
               supportedVersion = true;
             }
           }
           if (!supportedVersion) {
             throw new Error("Not a supported version: " + system);
           }
           break;
         }
         if ("collection".equalsIgnoreCase(localName) || "resource".equalsIgnoreCase(localName)) {
           // grab the resource's attributes
           Resource resource = new Resource();
           for (int i = 0; i < reader.getAttributeCount(); i++) {
             resource.attributes.put(
                 reader.getAttributeLocalName(i).toLowerCase(), reader.getAttributeValue(i));
           }
           currentResourceId = resource.getId();
           resources.put(currentResourceId, resource);
           break;
         }
         if ("property".equalsIgnoreCase(localName)) {
           Resource resource = resources.get(currentResourceId);
           final String name = reader.getAttributeValue(null, "name");
           String value = reader.getAttributeValue(null, "value");
           if (value != null && !"".equals(value)) {
             if (reader.getAttributeValue(null, "enc").equalsIgnoreCase("BASE64")) {
               value = new String(base64.decode(value));
             }
             resource.properties.put(name, value);
           }
           break;
         }
         break;
       case XMLStreamReader.END_ELEMENT:
         localName = reader.getLocalName();
         if ("collection".equalsIgnoreCase(localName) || "resource".equalsIgnoreCase(localName)) {
           makeResource(resources.get(currentResourceId), sitePath, session, zip);
         }
         break;
     } // end switch
   } // end for
   reader.close();
 }
Пример #7
0
 /**
  * Extract the id from a resource element and add to the resource map then recurse into any
  * contained resources. Also extract the ids from any contained method and its representation or
  * fault elements.
  *
  * @param file the URI of the current WADL file being processed
  * @param r the resource element
  * @throws javax.xml.bind.JAXBException if the WADL file is invalid or if the code generator
  *     encounters a problem.
  * @throws java.io.IOException if the specified WADL file cannot be read.
  */
 protected void extractResourceIds(Resource r, URI file) throws JAXBException, IOException {
   processIDHref(file, r.getId(), null, r);
   for (String type : r.getType()) {
     processIDHref(file, null, type, r);
   }
   for (Object child : r.getMethodOrResource()) {
     if (child instanceof Method) extractMethodIds((Method) child, file);
     else if (child instanceof Resource) extractResourceIds((Resource) child, file);
   }
 }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.table_cell_bulb, parent, false);

    Resource resource = (Resource) getItem(position);

    ImageView imageView = (ImageView) rowView.findViewById(R.id.bulbStatusImage);
    if (resource instanceof File) {
      File file = (File) resource;
      switch (file.getType()) {
        case AUDIO:
          imageView.setImageResource(R.drawable.file_audio);
          break;
        case VIDEO:
          imageView.setImageResource(R.drawable.file_movie);
          break;
        case IMAGE:
          imageView.setBackgroundResource(R.drawable.file_image);
          break;
        default:
          imageView.setImageResource(0);
      }
    } else {
      imageView.setImageResource(0);
    }
    TextView nameView = (TextView) rowView.findViewById(R.id.bulbName);
    nameView.setTextColor(context.getResources().getColor(R.color.bulbNameAvailable));
    nameView.setTypeface(FontFactory.getInstance().getOpensans(context));

    nameView.setText(resource.getName());

    TextView textView2 = (TextView) rowView.findViewById(R.id.row_details_line);
    if (textView2 != null) {
      textView2.setText(resource.getId());
    }

    return rowView;
  }
Пример #9
0
  protected Resource findResourceAvailable(String resourceType) {
    Resource rAvailable = null;
    context = getContext();
    for (Object o : context.getObjects(Resource.class)) {
      Resource resource = (Resource) o;
      if (resource.getResourceType() == resourceType) {
        System.out.println(
            "resource type? "
                + resourceType
                + " is required here, looking if "
                + resource.getId()
                + " is available? "
                + resource.isAvailable());
        if (resource.isAvailable() == true) {
          rAvailable = resource;
          break;
        } else {

        }
      }
    }
    return rAvailable;
  }
  @Test
  public void createAuthenticatableResource_validAsAuthorized() {
    final String domainName = generateDomain();
    final String resourceClassName = generateResourceClass(true, false);
    final char[] password = generateUniquePassword();
    final char[] passwordBase = generateUniquePassword();
    final char[] shortPwd = (passwordBase + "123").substring(0, 3).toCharArray();
    final char[] whitespacedPwd = (" " + passwordBase + "\t").toCharArray();

    // (ironically,) set up an authenticatable resource with resource class create permission
    final Resource authenticatedResource = generateResourceAndAuthenticate();
    final String permissionName = generateResourceClassPermission(resourceClassName);
    final ResourcePermission grantedResourcePermission =
        ResourcePermissions.getInstance(permissionName);
    grantResourceCreatePermission(
        authenticatedResource, resourceClassName, domainName, permissionName);

    Set<Resource> resourcesByPermission =
        accessControlContext.getResourcesByResourcePermissions(
            authenticatedResource, resourceClassName, grantedResourcePermission);
    assertThat(resourcesByPermission.isEmpty(), is(true));

    // create resource and verify
    final Resource resource =
        accessControlContext.createResource(
            resourceClassName, domainName, PasswordCredentials.newInstance(password));

    assertThat(resource, is(not(nullValue())));
    resourcesByPermission =
        accessControlContext.getResourcesByResourcePermissions(
            authenticatedResource, resourceClassName, grantedResourcePermission);
    assertThat(resourcesByPermission.size(), is(1));
    assertThat(accessControlContext.getDomainNameByResource(resource), is(domainName));
    final ResourceClassInfo resourceClassInfo =
        accessControlContext.getResourceClassInfoByResource(resource);
    assertThat(resourceClassInfo.getResourceClassName(), is(resourceClassName));

    // create another resource with a short password
    final Resource resource_shortPwd =
        accessControlContext.createResource(
            resourceClassName, domainName, PasswordCredentials.newInstance(shortPwd));

    assertThat(resource_shortPwd, is(not(nullValue())));
    resourcesByPermission =
        accessControlContext.getResourcesByResourcePermissions(
            authenticatedResource, resourceClassName, grantedResourcePermission);
    assertThat(resourcesByPermission.size(), is(2));
    assertThat(resource_shortPwd.getId(), is(not(resource.getId())));
    assertThat(accessControlContext.getDomainNameByResource(resource_shortPwd), is(domainName));
    final ResourceClassInfo resourceClassInfo2 =
        accessControlContext.getResourceClassInfoByResource(resource_shortPwd);
    assertThat(resourceClassInfo2.getResourceClassName(), is(resourceClassName));

    // create another resource with a whitespaced password
    final Resource resource_whitespacedPwd =
        accessControlContext.createResource(
            resourceClassName, domainName, PasswordCredentials.newInstance(whitespacedPwd));

    assertThat(resource_whitespacedPwd, is(not(nullValue())));
    resourcesByPermission =
        accessControlContext.getResourcesByResourcePermissions(
            authenticatedResource, resourceClassName, grantedResourcePermission);
    assertThat(resourcesByPermission.size(), is(3));
    assertThat(resource_whitespacedPwd.getId(), is(not(resource.getId())));
    assertThat(resource_whitespacedPwd.getId(), is(not(resource_shortPwd.getId())));
    assertThat(
        accessControlContext.getDomainNameByResource(resource_whitespacedPwd), is(domainName));
    final ResourceClassInfo resourceClassInfo3 =
        accessControlContext.getResourceClassInfoByResource(resource_whitespacedPwd);
    assertThat(resourceClassInfo3.getResourceClassName(), is(resourceClassName));

    // verify we can authenticate
    accessControlContext.authenticate(resource, PasswordCredentials.newInstance(password));
    accessControlContext.authenticate(resource_shortPwd, PasswordCredentials.newInstance(shortPwd));
    accessControlContext.authenticate(
        resource_whitespacedPwd, PasswordCredentials.newInstance(whitespacedPwd));
  }
  @Test
  public void createAuthenticatableResource_caseSensitiveConsistent_AsAuthorized() {
    authenticateSystemResource();
    final String domainBase = generateUniqueDomainName();
    final String resourceClassBase = generateUniqueResourceClassName();
    final String domain_lower = domainBase + "_ddd";
    final String domain_UPPER = domainBase + "_DDD";
    final String resourceClass_lower = resourceClassBase + "_ccc";
    final String resourceClass_UPPER = resourceClassBase + "_CCC";
    final String permissionName = generateUniquePermissionName();
    final char[] passwordBase = generateUniquePassword();
    final char[] password_lower = (passwordBase + "_pwd").toCharArray();
    final char[] password_UPPER = (passwordBase + "_PWD").toCharArray();
    accessControlContext.createDomain(domain_lower);
    accessControlContext.createResourceClass(resourceClass_lower, true, false);
    accessControlContext.createResourcePermission(resourceClass_lower, permissionName);

    if (isDatabaseCaseSensitive()) {
      accessControlContext.createDomain(domain_UPPER);
      accessControlContext.createResourceClass(resourceClass_UPPER, true, false);
      accessControlContext.createResourcePermission(resourceClass_UPPER, permissionName);

      // set up an authenticatable resource with resource class create permission
      // and an extra permission in each domain/class combo, so that we can look up
      // the resources later via that permission
      final Resource authenticatedResource = generateResourceAndAuthenticate();
      grantResourceCreatePermission(
          authenticatedResource, resourceClass_lower, domain_lower, permissionName);
      grantResourceCreatePermission(
          authenticatedResource, resourceClass_lower, domain_UPPER, permissionName);
      grantResourceCreatePermission(
          authenticatedResource, resourceClass_UPPER, domain_lower, permissionName);
      grantResourceCreatePermission(
          authenticatedResource, resourceClass_UPPER, domain_UPPER, permissionName);
      final ResourcePermission grantedResourcePermission_lower =
          ResourcePermissions.getInstance(permissionName);
      final ResourcePermission grantedResourcePermission_UPPER =
          ResourcePermissions.getInstance(permissionName);

      Set<Resource> resourcesByPermission;
      resourcesByPermission =
          accessControlContext.getResourcesByResourcePermissions(
              authenticatedResource, resourceClass_lower, grantedResourcePermission_lower);
      assertThat(resourcesByPermission.isEmpty(), is(true));
      resourcesByPermission =
          accessControlContext.getResourcesByResourcePermissions(
              authenticatedResource, resourceClass_UPPER, grantedResourcePermission_UPPER);
      assertThat(resourcesByPermission.isEmpty(), is(true));

      // create resources with case-sensitive domain/class names and verify resources get created in
      // different domain/classes
      final Resource resource_lowlow =
          accessControlContext.createResource(
              resourceClass_lower, domain_lower, PasswordCredentials.newInstance(password_lower));
      assertThat(resource_lowlow, is(not(nullValue())));
      resourcesByPermission =
          accessControlContext.getResourcesByResourcePermissions(
              authenticatedResource, resourceClass_lower, grantedResourcePermission_lower);
      assertThat(resourcesByPermission.size(), is(1));

      final Resource resource_lowUP =
          accessControlContext.createResource(
              resourceClass_lower, domain_UPPER, PasswordCredentials.newInstance(password_UPPER));
      assertThat(resource_lowUP, is(not(nullValue())));
      assertThat(resource_lowUP.getId(), is(not(resource_lowlow.getId())));
      resourcesByPermission =
          accessControlContext.getResourcesByResourcePermissions(
              authenticatedResource, resourceClass_lower, grantedResourcePermission_lower);
      assertThat(resourcesByPermission.size(), is(2));

      final Resource resource_UPlow =
          accessControlContext.createResource(
              resourceClass_UPPER, domain_lower, PasswordCredentials.newInstance(password_lower));
      assertThat(resource_UPlow, is(not(nullValue())));
      resourcesByPermission =
          accessControlContext.getResourcesByResourcePermissions(
              authenticatedResource, resourceClass_UPPER, grantedResourcePermission_UPPER);
      assertThat(resourcesByPermission.size(), is(1));

      final Resource resource_UPUP =
          accessControlContext.createResource(
              resourceClass_UPPER, domain_UPPER, PasswordCredentials.newInstance(password_UPPER));
      assertThat(resource_UPUP, is(not(nullValue())));
      assertThat(resource_UPUP.getId(), is(not(resource_UPlow.getId())));
      resourcesByPermission =
          accessControlContext.getResourcesByResourcePermissions(
              authenticatedResource, resourceClass_UPPER, grantedResourcePermission_UPPER);
      assertThat(resourcesByPermission.size(), is(2));

      // verify passwords are case-sensitive
      accessControlContext.authenticate(
          resource_lowlow, PasswordCredentials.newInstance(password_lower));
      accessControlContext.authenticate(
          resource_UPUP, PasswordCredentials.newInstance(password_UPPER));
      try {
        accessControlContext.authenticate(
            resource_lowlow, PasswordCredentials.newInstance(password_UPPER));
        fail(
            "authentication of system resource with case-insensitive password should not have succeeded");
      } catch (IncorrectCredentialsException e) {
        assertThat(e.getMessage().toLowerCase(), containsString("invalid password"));
      }
      try {
        accessControlContext.authenticate(
            resource_UPUP, PasswordCredentials.newInstance(password_lower));
        fail(
            "authentication of system resource with case-insensitive password should not have succeeded");
      } catch (IncorrectCredentialsException e) {
        assertThat(e.getMessage().toLowerCase(), containsString("invalid password"));
      }
    } else {
      // set up an authenticatable resource with resource class create permission
      // and an extra permission in each domain/class combo, so that we can look up
      // the resources later via that permission
      final Resource authenticatedResource = generateResourceAndAuthenticate();
      grantResourceCreatePermission(
          authenticatedResource, resourceClass_lower, domain_lower, permissionName);
      final ResourcePermission grantedResourcePermission =
          ResourcePermissions.getInstance(permissionName);

      Set<Resource> resourcesByPermission;
      resourcesByPermission =
          accessControlContext.getResourcesByResourcePermissions(
              authenticatedResource, resourceClass_lower, grantedResourcePermission);
      assertThat(resourcesByPermission.isEmpty(), is(true));
      resourcesByPermission =
          accessControlContext.getResourcesByResourcePermissions(
              authenticatedResource, resourceClass_UPPER, grantedResourcePermission);
      assertThat(resourcesByPermission.isEmpty(), is(true));

      // create resources with case-sensitive domain/class names and verify resources get created in
      // different domain/classes
      final Resource resource_lowlow =
          accessControlContext.createResource(
              resourceClass_lower, domain_lower, PasswordCredentials.newInstance(password_lower));
      assertThat(resource_lowlow, is(not(nullValue())));
      resourcesByPermission =
          accessControlContext.getResourcesByResourcePermissions(
              authenticatedResource, resourceClass_lower, grantedResourcePermission);
      assertThat(resourcesByPermission.size(), is(1));

      final Resource resource_lowUP =
          accessControlContext.createResource(
              resourceClass_lower, domain_UPPER, PasswordCredentials.newInstance(password_UPPER));
      assertThat(resource_lowUP, is(not(nullValue())));
      assertThat(resource_lowUP.getId(), is(not(resource_lowlow.getId())));
      resourcesByPermission =
          accessControlContext.getResourcesByResourcePermissions(
              authenticatedResource, resourceClass_lower, grantedResourcePermission);
      assertThat(resourcesByPermission.size(), is(2));

      final Resource resource_UPlow =
          accessControlContext.createResource(
              resourceClass_UPPER, domain_lower, PasswordCredentials.newInstance(password_lower));
      assertThat(resource_UPlow, is(not(nullValue())));
      assertThat(resource_UPlow.getId(), is(not(resource_lowlow.getId())));
      assertThat(resource_UPlow.getId(), is(not(resource_lowUP.getId())));
      resourcesByPermission =
          accessControlContext.getResourcesByResourcePermissions(
              authenticatedResource, resourceClass_UPPER, grantedResourcePermission);
      assertThat(resourcesByPermission.size(), is(3));

      final Resource resource_UPUP =
          accessControlContext.createResource(
              resourceClass_UPPER, domain_UPPER, PasswordCredentials.newInstance(password_UPPER));
      assertThat(resource_UPUP, is(not(nullValue())));
      assertThat(resource_UPUP.getId(), is(not(resource_lowlow.getId())));
      assertThat(resource_UPUP.getId(), is(not(resource_lowUP.getId())));
      assertThat(resource_UPUP.getId(), is(not(resource_UPlow.getId())));
      resourcesByPermission =
          accessControlContext.getResourcesByResourcePermissions(
              authenticatedResource, resourceClass_UPPER, grantedResourcePermission);
      assertThat(resourcesByPermission.size(), is(4));

      // verify passwords are case-sensitive
      accessControlContext.authenticate(
          resource_lowlow, PasswordCredentials.newInstance(password_lower));
      accessControlContext.authenticate(
          resource_UPUP, PasswordCredentials.newInstance(password_UPPER));
      try {
        accessControlContext.authenticate(
            resource_lowlow, PasswordCredentials.newInstance(password_UPPER));
        fail(
            "authentication of system resource with case-insensitive password should not have succeeded");
      } catch (IncorrectCredentialsException e) {
        assertThat(e.getMessage().toLowerCase(), containsString("invalid password"));
      }
      try {
        accessControlContext.authenticate(
            resource_UPUP, PasswordCredentials.newInstance(password_lower));
        fail(
            "authentication of system resource with case-insensitive password should not have succeeded");
      } catch (IncorrectCredentialsException e) {
        assertThat(e.getMessage().toLowerCase(), containsString("invalid password"));
      }
    }
  }
  @Test
  public void createAuthenticatableResource_whitespaceConsistent_AsAuthorized() {
    final String domainName = generateDomain();
    final String resourceClassName = generateResourceClass(true, false);
    final char[] password = generateUniquePassword();

    // (ironically,) set up an authenticatable resource with resource class create permission
    final Resource authenticatedResource = generateResourceAndAuthenticate();
    final String permissionName = generateResourceClassPermission(resourceClassName);
    final ResourcePermission grantedResourcePermission =
        ResourcePermissions.getInstance(permissionName);
    grantResourceCreatePermission(
        authenticatedResource, resourceClassName, domainName, permissionName);

    Set<Resource> resourcesByPermission =
        accessControlContext.getResourcesByResourcePermissions(
            authenticatedResource, resourceClassName, grantedResourcePermission);
    assertThat(resourcesByPermission.isEmpty(), is(true));

    // create resource with white-spaced names (and pwd) and verify
    final String domainName_whitespaced = " " + domainName + "\t";
    final String resourceClassName_whitespaced = " " + resourceClassName + "\t";
    final char[] password_whitespaced = (" " + password + "\t").toCharArray();
    final Resource whitespacedResource =
        accessControlContext.createResource(
            resourceClassName_whitespaced,
            domainName_whitespaced,
            PasswordCredentials.newInstance(password));

    assertThat(whitespacedResource, is(not(nullValue())));
    resourcesByPermission =
        accessControlContext.getResourcesByResourcePermissions(
            authenticatedResource, resourceClassName, grantedResourcePermission);
    assertThat(resourcesByPermission.size(), is(1));
    assertThat(accessControlContext.getDomainNameByResource(whitespacedResource), is(domainName));

    // create another resource WITHOUT white-spaced names and pwd
    final Resource resource =
        accessControlContext.createResource(
            resourceClassName, domainName, PasswordCredentials.newInstance(password));

    assertThat(resource, is(not(nullValue())));
    resourcesByPermission =
        accessControlContext.getResourcesByResourcePermissions(
            authenticatedResource, resourceClassName, grantedResourcePermission);
    assertThat(resourcesByPermission.size(), is(2));
    assertThat(resource.getId(), is(not(whitespacedResource.getId())));
    assertThat(accessControlContext.getDomainNameByResource(resource), is(domainName));

    // verify passwords are whitespace-sensitive
    accessControlContext.authenticate(
        whitespacedResource, PasswordCredentials.newInstance(password));
    accessControlContext.authenticate(resource, PasswordCredentials.newInstance(password));
    try {
      accessControlContext.authenticate(
          whitespacedResource, PasswordCredentials.newInstance(password_whitespaced));
      fail(
          "authentication of resource with extra leading/trailing password should not have succeeded");
    } catch (IncorrectCredentialsException e) {
      assertThat(e.getMessage().toLowerCase(), containsString("invalid password"));
    }
    try {
      accessControlContext.authenticate(
          resource, PasswordCredentials.newInstance(password_whitespaced));
      fail(
          "authentication of resource with extra leading/trailing password should not have succeeded");
    } catch (IncorrectCredentialsException e) {
      assertThat(e.getMessage().toLowerCase(), containsString("invalid password"));
    }

    // verify we can authenticate
    accessControlContext.authenticate(resource, PasswordCredentials.newInstance(password));
    accessControlContext.authenticate(
        whitespacedResource, PasswordCredentials.newInstance(password));
  }