Exemplo n.º 1
0
  public void testFilterExactAttribute() {

    try {
      GenericApplicationContext gContext =
          BaseDataConnectorTest.createSpringContext(RESOLVER_CONFIG);
      GroupDataConnector gdc = (GroupDataConnector) gContext.getBean("testFilterExactAttribute");

      Filter filter = gdc.getFilter();

      Set<Group> groups = filter.getResults(grouperSession);

      assertEquals(1, groups.size());

      assertTrue(groups.contains(groupA));
      assertFalse(groups.contains(groupB));
      assertFalse(groups.contains(groupC));

      assertTrue(filter.matches(groupA));
      assertFalse(filter.matches(groupB));
      assertFalse(filter.matches(groupC));
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 2
0
  /**
   * Assert that the attributes returned from the data connector match the provided attributes.
   *
   * @param dataConnectorName the data connector name
   * @param principalName the principalName
   * @param correctMap the correct attributes
   */
  private void runAttributeDefinitionTest(
      String dataConnectorName,
      String principalName,
      AttributeMap correctMap,
      String attributeDefinitionName) {
    try {
      GenericApplicationContext gContext =
          BaseDataConnectorTest.createSpringContext(RESOLVER_CONFIG);
      ShibbolethResolutionContext ctx = getShibContext(principalName);

      // resolve data connector dependency
      GroupDataConnector gdc = (GroupDataConnector) gContext.getBean(dataConnectorName);
      gdc.resolve(ctx);
      ctx.getResolvedPlugins().put(gdc.getId(), gdc);

      // resolve attribute definition
      AttributeDefinition ad = (AttributeDefinition) gContext.getBean(attributeDefinitionName);
      BaseAttribute attr = ad.resolve(ctx);

      // assert equality
      AttributeMap currentMap = new AttributeMap();
      currentMap.setAttribute(attr);
      LOG.debug("correctMap\n{}", correctMap);
      LOG.debug("currentMap\n{}", currentMap);
      assertEquals(correctMap, currentMap);
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 3
0
 public void testGroupNotFound() {
   try {
     GenericApplicationContext gContext =
         BaseDataConnectorTest.createSpringContext(RESOLVER_CONFIG);
     GroupDataConnector gdc = (GroupDataConnector) gContext.getBean("testAttributesOnly");
     Map<String, BaseAttribute> map = gdc.resolve(getShibContext("notfound"));
     assertTrue(map.isEmpty());
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 4
0
 /**
  * Assert that the attributes returned from the data connector match the provided attributes.
  *
  * @param dataConnectorName the data connector name
  * @param group the group
  * @param correctMap the correct attributes
  */
 private void runResolveTest(String dataConnectorName, Group group, AttributeMap correctMap) {
   try {
     GenericApplicationContext gContext =
         BaseDataConnectorTest.createSpringContext(RESOLVER_CONFIG);
     GroupDataConnector gdc = (GroupDataConnector) gContext.getBean(dataConnectorName);
     AttributeMap currentMap = new AttributeMap(gdc.resolve(getShibContext(group.getName())));
     LOG.debug("correctMap\n{}", correctMap);
     LOG.debug("currentMap\n{}", currentMap);
     assertEquals(correctMap, currentMap);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 5
0
  public void testMatchFilterMinus() {
    try {
      GenericApplicationContext gContext =
          BaseDataConnectorTest.createSpringContext(RESOLVER_CONFIG);
      GroupDataConnector gdc = (GroupDataConnector) gContext.getBean("testFilterMinus");

      assertTrue(
          "map should not be empty", !gdc.resolve(getShibContext(groupA.getName())).isEmpty());
      assertTrue("map should be empty", gdc.resolve(getShibContext(groupB.getName())).isEmpty());
      assertTrue("map should be empty", gdc.resolve(getShibContext(groupC.getName())).isEmpty());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }